wisest owl (wisest_owl) wrote in changelog,
wisest owl
wisest_owl
changelog

[livejournal] r18026: LJSUP-6868. Supermaintainer

Committer: gprochaev
LJSUP-6868. Supermaintainer

A   trunk/bin/misc/set_comm_supermaintainer.pl
U   trunk/bin/upgrading/en.dat
U   trunk/bin/upgrading/proplists.dat
U   trunk/cgi-bin/LJ/Poll.pm
U   trunk/cgi-bin/LJ/User.pm
U   trunk/htdocs/accountstatus.bml
U   trunk/htdocs/community/election.bml
U   trunk/htdocs/community/members.bml
U   trunk/htdocs/community/members.bml.text
U   trunk/htdocs/poll/index.bml
Added: trunk/bin/misc/set_comm_supermaintainer.pl
===================================================================
--- trunk/bin/misc/set_comm_supermaintainer.pl	                        (rev 0)
+++ trunk/bin/misc/set_comm_supermaintainer.pl	2011-01-14 08:21:59 UTC (rev 18026)
@@ -0,0 +1,296 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+no warnings 'once';
+use lib "$ENV{LJHOME}/cgi-bin";
+require "ljlib.pl";
+require "ljdb.pl";
+require "ljlang.pl";
+require 'ljprotocol.pl';
+use Getopt::Long;
+use LJ::DBUtil;
+
+my $to_journal = LJ::load_user("lj_elections")
+    or die "No user 'lj_elections' on this server";
+my $poster = LJ::load_user("system") 
+    or die "No user 'system' on this server";
+
+my $help = <<"HELP";
+    This script set the supermaintainer role for all or selected communities. 
+    If no supermaintainer can be set, then poll is created for the community.
+
+    Usage:
+        $0 comm1 comm2 comm3
+
+    Options: 
+        --verbose       Show progress
+        --help          Show this text and exit
+HELP
+
+my ($need_help, $verbose);
+GetOptions(
+    "help"          => \$need_help, 
+    "verbose"       => \$verbose,
+) or die $help;
+if ($need_help) {
+    print $help;
+    exit(1);
+}
+
+my $dbr = LJ::get_dbh("slow") or die "Can't get slow DB connection";
+$dbr->{RaiseError} = 1;
+$dbr->{ShowErrorStatement} = 1;
+
+my $where = @ARGV ? " AND user IN('".join("','",@ARGV)."') " : '';
+$verbose = 1 if @ARGV;
+my $communities = $dbr->selectall_arrayref ("SELECT userid, user FROM user WHERE journaltype = 'C'$where", { Slice => {} });
+
+sub _log {
+    print @_ if $verbose;
+}
+
+my $i = 0;
+foreach my $c (@$communities) {
+    _log '-' x 30, "\n";
+
+    _log "Start work with community '" . $c->{'user'} . "'\n";
+    my $comm = LJ::load_userid ($c->{userid});
+    next unless $comm;
+
+    _log "Search and set supermaintainer for community: " . $c->{'user'}."\n";
+
+    ## skip if community has supermaintainer already
+    my $s_maints = LJ::load_rel_user($c->{userid}, 'S');
+    my $s_maint_u = @$s_maints ? LJ::load_userid($s_maints) : undef;
+    if ($s_maint_u) {
+        _log "Community has supermaintainer already: " . $s_maint_u->user . "\n";
+        next;
+    }
+
+    if ($comm->prop ('election_poll_id')) {
+        my $jitemid = $comm->prop ('election_poll_id');
+        ## Poll was created
+        if ($jitemid) {
+            my $poll = LJ::Poll->new ($jitemid);
+            if ($poll->is_closed) {
+                _log "Poll is closed and supermaintainer did not set.\n";
+            } else {
+                _log "Poll is open.\n";
+                next;
+            }
+        }
+    }
+
+    my $maintainers = LJ::load_rel_user($c->{userid}, 'A');
+    ## Check for all maintainers are alive
+    my $users = LJ::load_userids(@$maintainers);
+    my @alive_mainteiners;
+    foreach my $u (values %$users) {
+        if ($u && $u->is_visible && $u->can_manage($comm) && $u->check_activity(90)) {
+            push @alive_mainteiners, $u;
+        }
+    }
+    unless (@alive_mainteiners) {
+        _log "Community does not have active maintainers\n";
+        next;
+    }
+
+    if (scalar @alive_mainteiners == 1) {
+        ## Check for alone maintainer is normal user and if ok set to supermaintainer
+        my $user = $alive_mainteiners[0];
+        _log "Set user ".$user->user." as supermaintainer for ".$comm->user."\n";
+        LJ::set_rel($c->{userid}, $user->{userid}, 'S');
+    } else {
+        ## Search for maintainer via userlog
+        _log "Search in userlog for creator or first alive maintainer\n";
+        my $u = _check_maintainers ($comm);
+        if ($u) {
+            _log "Set user ".$u->user." as supermaintainer for ".$comm->user."\n";
+            LJ::set_rel($c->{userid}, $u->{userid}, 'S');
+        } else {
+            _log "Create poll for supermaintainer election\n";
+            my $poll_id = _create_poll ($c->{userid});
+            $comm->set_prop ('election_poll_id' => $poll_id)
+                or die "Can't set prop 'election_poll_id'";
+        }
+    } 
+
+    $i++;
+    if ($i > 1000) {
+        print "Sleeping...\n";
+        sleep 1;
+        $i = 0;
+    }
+}
+
+sub _check_maintainers {
+    my $comm = shift;
+
+    my $dbcr = LJ::get_cluster_reader($comm)
+        or die "Unable to get user cluster reader.";
+    $dbcr->{RaiseError} = 1;
+
+    my $sth = $dbcr->prepare("SELECT action, actiontarget, remoteid FROM userlog WHERE userid = ? AND action = ? ORDER BY logtime ASC");
+    $sth->execute($comm->{userid}, 'account_create');
+
+    my $row = $sth->fetchrow_hashref;
+    if ($row) {
+        my $u_id = $row->{'remoteid'};
+        my $u = LJ::load_userid ($u_id);
+        return $u if $u && $u->is_visible && $u->can_manage($comm) && $u->check_activity(90);
+    }
+
+    $sth->execute($comm->{userid}, 'maintainer_add');
+    while (my $row = $sth->fetchrow_hashref) {
+        my $u_id = $row->{'actiontarget'};
+        my $u = LJ::load_userid ($u_id);
+        return $u if $u && $u->is_visible && $u->can_manage($comm) && $u->check_activity(90);
+    }
+
+    ## Can't find active maintainer
+    return undef;
+}
+
+sub _edit_post {
+    my %opts = @_;
+
+    my $u = $opts{to};
+    my $comm = $opts{comm};
+    my $entry = $opts{entry};
+    my $poll = $opts{poll};
+
+    my $security = delete $opts{security} || 'private';
+    my $proto_sec = $security;
+    if ($security eq "friends") {
+        $proto_sec = "usemask";
+    }
+
+    my $subject = delete $opts{subject} || LJ::Lang::ml('poll.election.post_subject');
+    my $body    = delete $opts{body}    || LJ::Lang::ml('poll.election.post_body', { comm => $comm->user });
+
+    my %req = (
+               mode     => 'editevent',
+               ver      => $LJ::PROTOCOL_VER,
+               user     => $u->{user},
+               password => '',
+               event    => $body . "<br/>" . "<lj-poll-".$poll->pollid.">",
+               subject  => $subject,
+               tz       => 'guess',
+               security => $proto_sec,
+               itemid   => $entry->jitemid,
+               );
+
+    $req{allowmask} = 1 if $security eq 'friends';
+
+    my %res;
+    my $flags = { noauth => 1, nomod => 1 };
+
+    LJ::do_request(\%req, \%res, $flags);
+
+    die "Error posting: $res{errmsg}" unless $res{'success'} eq "OK";
+    my $jitemid = $res{itemid} or die "No itemid";
+
+    return LJ::Entry->new($u, jitemid => $jitemid);
+}
+
+sub _create_post {
+    my %opts = @_;
+
+    my $u = $opts{to};
+    my $comm = $opts{comm};
+
+    my $security = delete $opts{security} || 'private';
+    my $proto_sec = $security;
+    if ($security eq "friends") {
+        $proto_sec = "usemask";
+    }
+
+    my $subject = delete $opts{subject} || LJ::Lang::ml('poll.election.post_subject');
+    my $body    = delete $opts{body}    || LJ::Lang::ml('poll.election.post_body', { comm => $comm->user });
+
+    my %req = (
+               mode => 'postevent',
+               ver => $LJ::PROTOCOL_VER,
+               user => $u->{user},
+               password => '',
+               event => $body,
+               subject => $subject,
+               tz => 'guess',
+               security => $proto_sec,
+               );
+
+    $req{allowmask} = 1 if $security eq 'friends';
+
+    my %res;
+    my $flags = { noauth => 1, nomod => 1 };
+
+    LJ::do_request(\%req, \%res, $flags);
+
+    die "Error posting: $res{errmsg}" unless $res{'success'} eq "OK";
+    my $jitemid = $res{itemid} or die "No itemid";
+
+    return LJ::Entry->new($u, jitemid => $jitemid);
+}
+
+sub _create_poll {
+    my $comm_id = shift;
+
+    my $comm = LJ::load_userid($comm_id);
+    my $entry = _create_post (to => $to_journal, comm => $comm);
+
+    die "Entry for Poll does not created\n" unless $entry;
+
+    my @items = ();
+    my $maintainers = LJ::load_rel_user($comm_id, 'A');
+    foreach my $u_id (@$maintainers) {
+        my $u = LJ::load_userid($u_id);
+        push @items, {
+            item    => "<lj user='".$u->user."'>",
+        };
+    }
+
+    my @q = (
+        {
+            qtext   => LJ::Lang::ml('poll.election.subject'),
+            type    => 'radio',
+            items   => \@items,
+        }
+    );
+
+    my $poll = LJ::Poll->create (entry => $entry, whovote => 'all', whoview => 'all', questions => \@q)
+        or die "Poll was not created";
+
+    $poll->set_prop ('createdate' => $entry->eventtime_mysql)
+        or die "Can't set prop 'createdate'";
+
+    $poll->set_prop ('supermaintainer' => $comm->userid)
+        or die "Can't set prop 'supermaintainer'";
+
+    _edit_post (to => $to_journal, comm => $comm, entry => $entry, poll => $poll) 
+        or die "Can't edit post";
+
+    ## All are ok. Emailing to all maintainers about election.
+    my $subject = LJ::Lang::ml('Supermaintainer election');
+    foreach my $maint_id (@$maintainers) {
+        my $u = LJ::load_userid ($maint_id);
+        LJ::send_mail({ 'to'        => $u->email_raw,
+                        'from'      => $LJ::ACCOUNTS_EMAIL,
+                        'fromname'  => $LJ::SITENAMESHORT,
+                        'wrap'      => 1,
+                        'charset'   => $u->mailencoding || 'utf-8',
+                        'subject'   => $subject,
+                        'body'      => (LJ::Lang::ml('poll.election.start.email', {
+                                                username        => LJ::ljuser($u),
+                                                communityname   => LJ::ljuser($comm),
+                                                faqlink         => '#',
+                                                shortsite       => $LJ::SITENAMESHORT,
+                                            })
+                                        ),
+                    });
+    }
+
+    return $poll->pollid;
+}
+
+


Property changes on: trunk/bin/misc/set_comm_supermaintainer.pl
___________________________________________________________________
Added: svn:executable
   + *

Modified: trunk/bin/upgrading/en.dat
===================================================================
--- trunk/bin/upgrading/en.dat	2011-01-13 10:45:48 UTC (rev 18025)
+++ trunk/bin/upgrading/en.dat	2011-01-14 08:21:59 UTC (rev 18026)
@@ -3380,12 +3380,48 @@
 
 poll.dberror.questions=Database error inserting questions: [[errmsg]]
 
+poll.election.closed=No Active election for this community now.
+
 poll.election.description=Election will be opened <b>untill all maintainers will make their choices</b><br/> but no longer than [[enddate]].<br/> If winner will not be found (in case of number of candidates will get similar<br /> number of votes) election may be extended up to another 3 weeks.
 
 poll.election.received.votes=([[cnt]] vote received)
 
-poll.election.subject=Choose your candidate:
+poll.election.start.email<<
+Dear [[username]],
 
+You are receiving this email because you are a maintainer of the community [[communityname]]. LiveJournal has recently implemented a new role of community management, known as the 'Owner' of the community. The Owner of a community will be the only person who will be able to perform tasks such as deleting maintainers or deleting the community itself. You can read more about the Owner role here:  [[faqlink]]
+
+Since [[communityname]] is an existing community with multiple maintainers, it is now up to you and the other maintainers of the community to select which of you will be granted the Owner status. A poll has been created for your community at this page [link to poll page]. You simply need to visit this page and cast your vote for which current maintainer you believe should be made Owner of the community. More information on how the election process works can be found at the page above.
+
+Regards,
+[[shortsite]] Team
+.
+
+poll.election.end.email<<
+Dear [[username]],
+
+You are receiving this email because you are a maintainer of the community [[communityname]]. 
+
+According to result of the Supermaintainer Election [[winner]] appointet to this role.
+
+You can read more about this role here:  [[faqlink]]
+
+Regards,
+[[shortsite]] Team
+.
+
+poll.election.subject=<b>Choose your candidate:</b>
+
+poll.election.post_subject=Election Post
+
+poll.election.post_body=Election Post for community [[comm]]
+
+poll.election.selected=<br/><br/>Your candidate: [[choice]].<br/>You can change your choice while election is open.
+
+poll.supermaintainer.not_selected=Not selected
+
+poll.supermaintainer.is=<br/><br/>Current supermaintainer:&nbsp;[[user]]
+
 poll.error.alreadyvoted|staleness=1
 poll.error.alreadyvoted=Sorry, you have already voted in this poll under the account [[user]].
 

Modified: trunk/bin/upgrading/proplists.dat
===================================================================
--- trunk/bin/upgrading/proplists.dat	2011-01-13 10:45:48 UTC (rev 18025)
+++ trunk/bin/upgrading/proplists.dat	2011-01-14 08:21:59 UTC (rev 18026)
@@ -1445,7 +1445,7 @@
   des: The voter must have created their account by the date specified (Pacific time) in order to vote.  Must be in format YYYY-MM-DD, otherwise there will be no restriction.
 
 pollproplist2.supermaintainer:
-  des: Is set to 1, only maintainers can see, vote and view results for this poll.
+  des: If set to !0, only maintainers can see, vote and view results for this poll. Has value as UserID - SuperMaintainer.
 
 logproplist.copyright:
   datatype: char

Modified: trunk/cgi-bin/LJ/Poll.pm
===================================================================
--- trunk/cgi-bin/LJ/Poll.pm	2011-01-13 10:45:48 UTC (rev 18025)
+++ trunk/cgi-bin/LJ/Poll.pm	2011-01-14 08:21:59 UTC (rev 18026)
@@ -739,7 +739,112 @@
 sub is_closed {
     my $self = shift;
     $self->_load;
-    return $self->{status} eq 'X' ? 1 : 0;
+
+    return 1 if $self->{status} eq 'X';
+
+    ## Is this poll is an election poll?
+    my $is_super = $self->prop('supermaintainer');
+    return 0 unless $is_super;
+
+    my $comm = LJ::load_userid($is_super);
+    return 0 unless $comm;
+
+    ## Check for all maintainers have already voted
+    my $dbr = LJ::get_db_reader();
+    my $sth;
+    my @questions = $self->questions;
+
+    ## SuperMaintainer election poll have only one question
+    my $qid = $questions[0]->pollqid;
+    my @items = $questions[0]->items;
+
+    ## Drop unvisible, non-maintainers and not active users
+    @items = grep {
+        my $user = $_->{item};
+        $user =~ s/<lj user='(.*?)'>/$1/;
+        my $u = LJ::load_user($user);
+        ($u && $u->is_visible && $u->can_manage($comm) && $u->check_activity(90)) ? 1 : 0;
+    } @items;
+
+    ## Fetch poll results
+    if ($self->is_clustered) {
+        $sth = $self->journal->prepare("SELECT value, userid FROM pollresult2 WHERE pollid=? AND pollqid=? AND journalid=?");
+        $sth->execute($self->pollid, $qid, $self->journalid);
+    } else {
+        $sth = $dbr->prepare("SELECT value, userid FROM pollresult WHERE pollid=? AND pollqid=?");
+        $sth->execute($self->pollid, $qid);
+    }
+
+    ## We are not calculate results from unvisible, non-maintainers and not active users
+    my %results = ();
+    my $cnt = 0;
+    while (my @res = $sth->fetchrow_array) {
+        my $uid = $res[1];
+        my $u = LJ::load_userid($uid);
+        next unless ($u && $u->is_visible && $u->can_manage($comm) && $u->check_activity(90));
+        $results{$res[0]}++;
+        $cnt++;
+    }
+
+    ## Not all maintainers have voted
+    return 0
+        if @items != $cnt;
+
+    my @cnts = sort { $b <=> $a } values %results;
+    my $max_votes_for = 0;
+    ## Max votes
+    my $max_votes = $cnts[0];
+    ## Check for duplicate of votes count
+    foreach my $it (keys %results) {
+        if (
+            $max_votes == $results{$it}     ## Found max votes count
+            && $max_votes_for               ## User have selected already
+            && $max_votes_for != $it        ## Ooops, it's another user
+        ) {
+            ## We have two equal votes count for diff users
+            $max_votes_for = undef;
+            last;
+        }
+        $max_votes_for = $it;
+    }
+
+    ## We found election winner. Set this user as supermaintainer and close election.
+    if ($max_votes_for && $items[$max_votes_for - 1]) {
+        my $winner = $items[$max_votes_for - 1]->{item};
+        $winner =~ s/<lj user='(.*?)'>/$1/;
+        $winner = LJ::load_user($winner);
+        if ($winner && $winner->can_manage($is_super) && $winner->is_visible) {
+            LJ::set_rel($is_super, $winner->{userid}, 'S');
+            $self->close_poll;
+
+            ## Poll is closed. Emailing to all maintainers about it.
+            my $subject = LJ::Lang::ml('Supermaintainer election is closed');
+            my $maintainers = LJ::load_rel_user($comm->userid, 'A');
+            foreach my $maint_id (@$maintainers) {
+                my $u = LJ::load_userid ($maint_id);
+                LJ::send_mail({ 'to'        => $u->email_raw,
+                                'from'      => $LJ::ACCOUNTS_EMAIL,
+                                'fromname'  => $LJ::SITENAMESHORT,
+                                'wrap'      => 1,
+                                'charset'   => $u->mailencoding || 'utf-8',
+                                'subject'   => $subject,
+                                'body'      => (LJ::Lang::ml('poll.election.end.email', {
+                                                        username        => LJ::ljuser($u),
+                                                        communityname   => LJ::ljuser($comm),
+                                                        winner          => LJ::ljuser($winner),
+                                                        faqlink         => '#',
+                                                        shortsite       => $LJ::SITENAMESHORT,
+                                                    })
+                                                ),
+                            });
+            }
+
+            return 1;
+        }
+    }
+
+    ## Can't set a supermaintainer
+    return 0;
 }
 
 # return true if remote is also the owner
@@ -912,7 +1017,7 @@
     my $is_super = $self->prop ('supermaintainer');
     ## Only maintainers can view, vote and see results for election polls.
     return "<b>[" . LJ::Lang::ml('poll.error.not_enougth_rights') . "]</b>"
-        if $is_super && !$remote->can_manage($journalid);
+        if $is_super && $remote && !$remote->can_manage($is_super);
 
     # Default pagesize.
     $pagesize = 2000 unless $pagesize;
@@ -986,7 +1091,7 @@
         $ret .= LJ::html_hidden('pollid', $pollid);
     }
 
-    if ($is_super) {
+    if ($is_super && !$self->is_closed) {
         $ret .= LJ::Lang::ml('poll.election.description', { enddate => LJ::TimeUtil->fancy_time_format(LJ::TimeUtil->mysqldate_to_time($self->prop('createdate')) + 1814400, 'day') });
     }
 
@@ -1008,7 +1113,7 @@
     $ret .= "<br />\n" unless $opts{widget} || $is_super;
     $ret .= "<span style='font-family: monospace; font-weight: bold; font-size: 1.2em;'>" .
             LJ::Lang::ml('poll.isclosed') . "</span><br />\n"
-        if ($self->is_closed);
+        if ($self->is_closed && !$is_super);
 
     my $whoview = $self->whoview;
     if ($whoview eq "none") {
@@ -1040,6 +1145,31 @@
         #$posted .= " ($ago; " . LJ::TimeUtil->mysqldate_to_time($self->entry->logtime_mysql, 0) . ")";
         #$posted .= " (" . localtime . " - '" . $self->entry->logtime_mysql . "')";
     }
+
+    if ($is_super && !$self->is_closed) {
+        my $sth;
+        ## Election poll has a only one question
+        my $q = $qs[0];
+        if ($self->is_clustered) {
+            $sth = $self->journal->prepare("SELECT value FROM pollresult2 WHERE pollid=? AND pollqid=? AND journalid=? AND userid=?");
+            $sth->execute($self->pollid, $q->pollqid, $self->journalid, $remote->userid);
+        } else {
+            $sth = $dbr->prepare("SELECT value FROM pollresult WHERE pollid=? AND pollqid=? AND userid=?");
+            $sth->execute($self->pollid, $q->pollqid, $remote->userid);
+        }
+
+        if (my @row = $sth->fetchrow_array) {
+            my @items = $self->question($q->pollqid)->items;
+            my $user = $row[0] ? $items[$row[0] - 1] : undef;
+            if ($user) {
+                $user = $user->{item};
+                LJ::Poll->clean_poll(\$user);
+                $ret .= LJ::Lang::ml('poll.election.selected', { choice => $user });
+            }
+        }
+
+    }
+
     ## go through all questions, adding to buffer to return
     foreach my $q (@qs) {
         my $qid = $q->pollqid;
@@ -1316,7 +1446,7 @@
     }
 
     ## calc amount of participants.
-    if ($mode eq "results" and not $opts{widget}){
+    if ($mode eq "results" and not $opts{widget} and !$is_super){
         my $sth = "";
         my $participants;
         if ($have_aggr_results) {
@@ -1331,9 +1461,22 @@
         ($participants) = $sth->fetchrow_array if $sth;
         $ret .= LJ::Lang::ml('poll.participants', { 'total' => $participants });
     }
-    
-    $ret .= $results_table;
 
+    if ($is_super && $self->is_closed) {
+        $ret .= LJ::Lang::ml('poll.election.closed');
+        my $comm = LJ::load_userid($self->prop('supermaintainer'));
+        my $res = LJ::load_rel_user($comm->{userid}, 'S');
+        my $user = '';
+        if (@$res) {
+            $user = LJ::ljuser(LJ::load_userid($res->[0]));
+        } else {
+            $user = LJ::Lang::ml('poll.supermaintainer.not_selected');
+        }
+        $ret .= LJ::Lang::ml('poll.supermaintainer.is', { user => $user });
+    } else {
+        $ret .= $results_table;
+    }
+
     if ($do_form) {
         $ret .= LJ::html_submit(
                                 'poll-submit',

Modified: trunk/cgi-bin/LJ/User.pm
===================================================================
--- trunk/cgi-bin/LJ/User.pm	2011-01-13 10:45:48 UTC (rev 18025)
+++ trunk/cgi-bin/LJ/User.pm	2011-01-14 08:21:59 UTC (rev 18026)
@@ -5922,7 +5922,29 @@
     return 1;
 }
 
+## Check for activity user at last N days
+## args: days - how many days to check
+## return:
+##      1 - user logs in the last 'days' days
+##      0 - user NOT logs in the last 'days' days
+sub check_activity {
+    my $u    = shift;
+    my $days = shift;
 
+    return 0 unless $days;
+
+    my $sth = $u->prepare ("SELECT logintime FROM loginlog WHERE userid=? ORDER BY logintime DESC");
+    $sth->execute ($u->userid);
+
+    if (my @row = $sth->fetchrow_array) {
+        my $logintime = $row[0];
+        return 1 if time - $logintime < $days * 86400;
+    }
+
+    return 0;
+}
+
+
 package LJ;
 
 use Carp;

Modified: trunk/htdocs/accountstatus.bml
===================================================================
--- trunk/htdocs/accountstatus.bml	2011-01-13 10:45:48 UTC (rev 18025)
+++ trunk/htdocs/accountstatus.bml	2011-01-14 08:21:59 UTC (rev 18026)
@@ -130,7 +130,8 @@
 
     # authas switcher form
     $ret .= "<form method='get' action='accountstatus.bml'>\n";
-    $ret .= LJ::make_authas_select($remote, { 'authas' => $GET{'authas'}, 'showall' => 1}) . "\n";
+    ## type = 'S' : Only Supermaintainers can delete communities
+    $ret .= LJ::make_authas_select($remote, { 'authas' => $GET{'authas'}, 'showall' => 1, type => 'S' }) . "\n";
     $ret .= "</form>\n\n";
 
     my $getextra = "?authas=$authas" unless $authas eq $remote->{'user'};

Modified: trunk/htdocs/community/election.bml
===================================================================
--- trunk/htdocs/community/election.bml	2011-01-13 10:45:48 UTC (rev 18025)
+++ trunk/htdocs/community/election.bml	2011-01-14 08:21:59 UTC (rev 18026)
@@ -51,7 +51,6 @@
     my $poll = LJ::Poll->new($poll_id);
     $body .= $poll->render;
 
-
     return $body;
 _code?>
 <=body

Modified: trunk/htdocs/community/members.bml
===================================================================
--- trunk/htdocs/community/members.bml	2011-01-13 10:45:48 UTC (rev 18025)
+++ trunk/htdocs/community/members.bml	2011-01-14 08:21:59 UTC (rev 18026)
@@ -70,6 +70,15 @@
     my %attrshort_r = ( map { $attrshort{$_} => $_ } keys %attrshort ); # reversed
 
     # saving a form submission
+    if ($POST{'select_as_sm'}) {
+        my $new_sm = $POST{'uid_to_sm'};
+        my $new_sm_u = LJ::load_userid($new_sm);
+        ## Is user exist, active and maintainer?
+        if ($new_sm_u && $new_sm_u->is_visible && $new_sm_u->can_manage($c)) {
+            LJ::clear_rel($c->{userid}, $remote->{userid}, 'S');
+            LJ::set_rel($c->{userid}, $new_sm_u->{userid}, 'S');
+        }
+    }
     if ($POST{'action:update'}) {
         # validate form auth
         return $print_with_ad->("<?h1 $ML{'Error'} h1?><?p $ML{'error.invalidform'} p?>")
@@ -589,6 +598,31 @@
     $ret .= "<form method='post' action='members.bml?authas=$cname'>";
     $ret .= LJ::form_auth();
 
+    ## SuperMaintainer
+    if ($remote->can_super_manage($c)) {
+        $ret .= BML::ml('.you.supermaintainer', { comm => LJ::ljuser($c->user) });
+        my $ids = LJ::load_rel_user($c->userid, 'A');
+        
+        my @users = map { 
+                            my $u = LJ::load_userid($_);
+                            {
+                                text => $u->user,
+                                value => $_,
+                            }
+                        } @$ids;
+
+        $ret .= LJ::html_select({
+                    name => "uid_to_sm", style => "",
+                    selected => 0,
+                    },
+                    { text => '',
+                    value => '',},
+                    @users
+                );
+
+        $ret .= LJ::html_submit('select_as_sm', BML::ml('.set.user_to_supermaintainer')) . "<br/>";
+    }
+
     # jump to user
     if ($items{'pages'} > 1) {
         $ret .= "<div style='margin-left: 30px;'>$ML{'.jump'}: ";
@@ -608,6 +642,17 @@
     # rows for existing users
     my $rc = 0;
     my @wstrs;
+    my %disabled = ();
+    my $elect_poll_id = $c->prop('election_poll_id');
+    my $elect_poll = undef;
+    if ($elect_poll_id) {
+        $elect_poll = LJ::Poll->new($elect_poll_id);
+    }
+    if (not can_super_manage $remote ($c) 
+        or ($elect_poll && !$elect_poll->is_closed)
+    ){
+        %disabled = ( disabled => 'disabled' );
+    }
     foreach(@users) {
         my $rstyle = ($rc++ & 1) ? "altrow2" : "altrow1";
         $ret .= "<tr class='$rstyle'><td>" . LJ::ljuser($_->{'name'}) . "</td>";
@@ -615,7 +660,7 @@
         foreach my $key (@attribs) {
             $ret .= "<td style='text-align: center;'>";
             $ret .= LJ::html_check({ 'name' => "edit_$_->{'userid'}_$key",
-                                     'selected' => $_->{$key} });
+                                     'selected' => $_->{$key}, $key =~ /moderate|admin/ ? %disabled : () });
             $wstr .= $attrshort_r{$key} if $_->{$key};
             $ret .= "</td>";
         }

Modified: trunk/htdocs/community/members.bml.text
===================================================================
--- trunk/htdocs/community/members.bml.text	2011-01-13 10:45:48 UTC (rev 18025)
+++ trunk/htdocs/community/members.bml.text	2011-01-14 08:21:59 UTC (rev 18026)
@@ -65,6 +65,8 @@
 
 .settings2=Settings
 
+.set.user_to_supermaintainer=Proceed...
+
 .success.added=added: [[list]]
 
 .success.deleted=removed: [[list]]
@@ -93,3 +95,5 @@
 
 .update=Update settings
 
+.you.supermaintainer=<br/><br/>Currently, you are <b>"SuperMaintainer"</b> for this community [[comm]].<br/><br/>You can abdicate and appoint another maintainer for this role:
+

Modified: trunk/htdocs/poll/index.bml
===================================================================
--- trunk/htdocs/poll/index.bml	2011-01-13 10:45:48 UTC (rev 18025)
+++ trunk/htdocs/poll/index.bml	2011-01-14 08:21:59 UTC (rev 18026)
@@ -73,7 +73,7 @@
         return;
     }
 
-    unless ($entry->visible_to($remote)) {
+    unless ($is_super || (!$is_super && !$entry->visible_to($remote))) {
         $body = $ML{'.error.cantview'};
         return;
     }
@@ -122,7 +122,7 @@
             return;
         }
         if ($is_super) {
-            my $journal = LJ::want_user($poll->journalid);
+            my $journal = LJ::want_user($is_super);
             return BML::redirect($LJ::SITEROOR."/community/election.bml?authas=".$journal->user);
         }
         return BML::redirect($entry->url);

Tags: bml, dat, livejournal, pl, pm, text, wisest-owl
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