Типа я (zilogic) wrote in changelog,
Типа я
zilogic
changelog

[livejournal] r19471: LJSUP-9292: Create console command set f...

Committer: amyshkin
LJSUP-9292: Create console command set for $username s2privs $arg
U   trunk/bin/upgrading/proplists.dat
U   trunk/cgi-bin/LJ/Console/Command/Set.pm
U   trunk/cgi-bin/ljhooks.pl
Modified: trunk/bin/upgrading/proplists.dat
===================================================================
--- trunk/bin/upgrading/proplists.dat	2011-07-14 02:46:46 UTC (rev 19470)
+++ trunk/bin/upgrading/proplists.dat	2011-07-14 02:57:01 UTC (rev 19471)
@@ -1671,7 +1671,7 @@
   multihomed: 0
   cldversion: 8
 
-userproplist.get_alien_posts:
+userproplist.take_entries:
   datatype: bool
   prettyname: Can get other journals post
   des: Can get other journals post
@@ -1679,10 +1679,18 @@
   multihomed: 0
   cldversion: 8
 
-userproplist.give_posts_to_alien:
+userproplist.provide_entries:
   datatype: bool
   prettyname: Can give post to others
   des: Can give post to others
   indexed: 0
   multihomed: 0
   cldversion: 8
+
+userproplist.javascript:
+  datatype: bool
+  prettyname: JS is enabled in S2
+  des: JS is enabled in S2
+  indexed: 0
+  multihomed: 0
+  cldversion: 8

Modified: trunk/cgi-bin/LJ/Console/Command/Set.pm
===================================================================
--- trunk/cgi-bin/LJ/Console/Command/Set.pm	2011-07-14 02:46:46 UTC (rev 19470)
+++ trunk/cgi-bin/LJ/Console/Command/Set.pm	2011-07-14 02:57:01 UTC (rev 19471)
@@ -26,6 +26,8 @@
 
     my $remote = LJ::get_remote();
     my $journal = $remote;   # may be overridden later
+    my $errmsg;
+    my $rv;
 
     if (scalar(@args) == 4) {
         # sanity check
@@ -38,6 +40,26 @@
 
         return $self->error("Invalid account: $name")
             unless $journal;
+
+        my $prop = $args[0];
+
+        if ( $prop eq 's2privs' ) {
+            return $self->error("You are not permitted to change this journal's settings.")
+                unless (LJ::check_priv($remote, 'siteadmin', 's2privs') && LJ::check_priv($remote, 'siteadmin', 'users')) || $LJ::IS_DEV_SERVER;
+
+            return $self->error("No setter for property '$prop'")
+                unless ref $LJ::SETTER{$prop} eq 'CODE';
+
+            my $arg = $args[1];
+            $arg =~ s/\s//g;
+
+            if( $arg eq 'none' or $arg eq "''" or $arg eq '""' ) {
+                return $self->set_privs( $journal, $remote, 's2privs', 'none', \$errmsg );
+            }
+
+            return $self->set_privs( $journal, $remote, 's2privs', $arg, \$errmsg );
+        }
+
         return $self->error("You are not permitted to change this journal's settings.")
             unless ($remote && $remote->can_manage($journal)) || LJ::check_priv($remote, "siteadmin", "propedit");
     }
@@ -46,12 +68,23 @@
     return $self->error("Unknown property '$key'")
         unless ref $LJ::SETTER{$key} eq "CODE";
 
-    my $errmsg;
-    my $rv = $LJ::SETTER{$key}->($journal, $key, $value, \$errmsg);
+    $rv = $LJ::SETTER{$key}->($journal, $key, $value, \$errmsg);
     return $self->error("Error setting property: $errmsg")
         unless $rv;
 
     return $self->print("User property '$key' set to '$value' for " . $journal->user);
 }
 
+sub set_privs {
+    my ( $self, $journal, $remote, $prop, $value, $errmsg ) = @_;
+    my $rv = $LJ::SETTER{$prop}->($journal, $prop, 'none', $errmsg);
+
+    return $self->error("Error setting property: $$errmsg")
+        unless $rv;
+
+    LJ::statushistory_add($journal, $remote, 's2privs', "s2privs set to 'none'");
+
+    return $self->print("s2privs for " . $journal->{user} . " set to 'none'");
+}
+
 1;

Modified: trunk/cgi-bin/ljhooks.pl
===================================================================
--- trunk/cgi-bin/ljhooks.pl	2011-07-14 02:46:46 UTC (rev 19470)
+++ trunk/cgi-bin/ljhooks.pl	2011-07-14 02:57:01 UTC (rev 19471)
@@ -293,7 +293,7 @@
     }
 });
 
-register_setter('get_alien_posts', sub {
+register_setter('take_entries', sub {
     my ($u, $key, $value, $err) = @_;
 
     unless ($value =~ /^(0|1)$/) {
@@ -304,7 +304,7 @@
     my $remote = LJ::get_remote();
 
     if (LJ::check_priv($remote, 'siteadmin', 'propedit') || $LJ::IS_DEV_SERVER) {
-        $u->set_prop('get_alien_posts', $value);
+        $u->set_prop('take_entries', $value);
         return 1;
     }
     else {
@@ -313,7 +313,7 @@
     }
 });
 
-register_setter('give_posts_to_alien', sub {
+register_setter('provide_entries', sub {
     my ($u, $key, $value, $err) = @_;
 
     unless ($value =~ /^(0|1)$/) {
@@ -324,7 +324,7 @@
     my $remote = LJ::get_remote();
 
     if (LJ::check_priv($remote, 'siteadmin', 'propedit') || $LJ::IS_DEV_SERVER) {
-        $u->set_prop('give_posts_to_alien', $value);
+        $u->set_prop('provide_entries', $value);
         return 1;
     }
     else {
@@ -369,4 +369,38 @@
     return 1;
 });
 
+#TODO: enable 'enabled_s2_js' when it will be implemented
+register_setter("s2privs", sub {
+    my ($u, $key, $value, $err) = @_;
+
+    my %good_params = map { $_ => 1} qw/javascript take_entries provide_entries/;
+
+    if ( $value eq 'none' ) {
+        $u->set_prop( $_, 0 ) for keys %good_params;
+        return 1;
+    }
+
+    my %args = map { $_ => 1 } split( /\+/, $value );
+    my @to_set;
+
+    delete $args{$_}
+        ? do {
+            push( @to_set, $_ );
+            delete $good_params{$_};
+          }
+        : undef
+            for keys %good_params;
+
+    return 0 if int(keys %args);
+    return 0 unless @to_set;
+
+    # First of all clear unused s2privs props
+    $u->set_prop( $_, 0 ) for keys %good_params;
+
+    # and now set required props
+    $u->set_prop( $_, 0 ) for @to_set;
+
+    return 1;
+});
+
 1;

Tags: dat, livejournal, pl, pm, zilogic
Subscribe
  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

  • 0 comments