Committer: gprochaev
LJSUP-6868. SupermaintainerU trunk/bin/upgrading/en.dat U trunk/bin/upgrading/proplists.dat U trunk/cgi-bin/LJ/Poll.pm U trunk/cgi-bin/LJ/Setting/WebmasterTools.pm U trunk/cgi-bin/LJ/User.pm U trunk/cgi-bin/ljlib.pl A trunk/htdocs/community/election.bml A trunk/htdocs/community/election.bml.text.local U trunk/htdocs/manage/settings/index.bml U trunk/htdocs/poll/index.bml
Modified: trunk/bin/upgrading/en.dat =================================================================== --- trunk/bin/upgrading/en.dat 2010-12-24 07:06:40 UTC (rev 18002) +++ trunk/bin/upgrading/en.dat 2010-12-24 11:23:32 UTC (rev 18003) @@ -3380,6 +3380,12 @@ poll.dberror.questions=Database error inserting questions: [[errmsg]] +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.error.alreadyvoted|staleness=1 poll.error.alreadyvoted=Sorry, you have already voted in this poll under the account [[user]]. @@ -3409,6 +3415,8 @@ poll.error.noquestions=You must have at least one question in a poll. +poll.error.not_enougth_rights=You are not have enougth rights for view this poll. + poll.error.notext=Need text inside an lj-pq tag to say what the question is about. poll.error.notvalidated|staleness=1 @@ -3479,6 +3487,8 @@ poll.viewanswers=View Answers +poll.vote=Vote! + poll.warning.cutoff|staleness=1 poll.warning.cutoff=Because your "[[oldval]]" answer exceeded the maximum length of 255 bytes, it has been cut off and now reads as "[[newval]]". Modified: trunk/bin/upgrading/proplists.dat =================================================================== --- trunk/bin/upgrading/proplists.dat 2010-12-24 07:06:40 UTC (rev 18002) +++ trunk/bin/upgrading/proplists.dat 2010-12-24 11:23:32 UTC (rev 18003) @@ -1444,6 +1444,9 @@ pollproplist2.createdate: 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. + logproplist.copyright: datatype: char des: Copyrighted status: 'C' - copyrighted, 'P' - public, full cite allowed. @@ -1598,8 +1601,15 @@ cldversion: 8 prettyname: System limit of friending notification delay +userproplist.election_poll_id: + datatype: num + des: Supermaintainer election poll id + cldversion: 8 + prettyname: Supermaintainer election poll id + logproplist.external_url: datatype: char des: URL of this entry on an external site prettyname: External URL sortorder: 107 + Modified: trunk/cgi-bin/LJ/Poll.pm =================================================================== --- trunk/cgi-bin/LJ/Poll.pm 2010-12-24 07:06:40 UTC (rev 18002) +++ trunk/cgi-bin/LJ/Poll.pm 2010-12-24 11:23:32 UTC (rev 18003) @@ -899,14 +899,21 @@ my ($self, %opts) = @_; my $remote = LJ::get_remote(); - my $ditemid = $self->ditemid; - my $pollid = $self->pollid; + my $ditemid = $self->ditemid; + my $pollid = $self->pollid; + my $journalid = $self->journalid; + my $mode = delete $opts{mode}; my $qid = delete $opts{qid}; my $page = delete $opts{page}; my $pagesize = delete $opts{pagesize}; + 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); + # Default pagesize. $pagesize = 2000 unless $pagesize; @@ -925,6 +932,10 @@ $mode = $time ? 'results' : $can_vote ? 'enter' : 'results'; } + ## Supermaintainer election has only one mode - voting + $mode = "enter" + if ($is_super && !$self->is_closed); + my $sth; my $ret = ''; @@ -975,20 +986,26 @@ $ret .= LJ::html_hidden('pollid', $pollid); } + if ($is_super) { + $ret .= LJ::Lang::ml('poll.election.description', { enddate => LJ::TimeUtil->fancy_time_format(LJ::TimeUtil->mysqldate_to_time($self->prop('createdate')) + 1814400, 'day') }); + } + $ret .= "<b><a href='$LJ::SITEROOT/poll/?id=$pollid'>" . LJ::Lang::ml('poll.pollnum', { 'num' => $pollid }) . "</a></b> " - unless $opts{widget}; + unless $opts{widget} || $is_super; $ret .= $opts{scroll_links} if $opts{widget}; if ($self->name) { my $name = $self->name; LJ::Poll->clean_poll(\$name); - if ($opts{widget}) { - $name = LJ::trim_at_word($name, 70); - $ret .= "<h3>$name</h3>"; - } else { - $ret .= "<i>$name</i>"; + unless ($is_super) { + if ($opts{widget}) { + $name = LJ::trim_at_word($name, 70); + $ret .= "<h3>$name</h3>"; + } else { + $ret .= "<i>$name</i>"; + } } } - $ret .= "<br />\n" if !$opts{widget}; + $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); @@ -999,7 +1016,7 @@ } $ret .= LJ::Lang::ml('poll.security2', { 'whovote' => LJ::Lang::ml('poll.security.'.$self->whovote), 'whoview' => LJ::Lang::ml('poll.security.'.$whoview) }) - unless $opts{widget}; + unless $opts{widget} || $is_super; my %aggr_results; my $aggr_users; @@ -1029,10 +1046,14 @@ my $text = $q->text; $text = LJ::trim_at_word($text, 150) if $opts{widget}; LJ::Poll->clean_poll(\$text); - if ($opts{widget}) { - $results_table .= "<p class='b-post-question'>$opts{poll_pic}$text$posted</p><div id='LJ_Poll_${pollid}_$qid' class='b-potd-poll'>"; + unless ($is_super) { + if ($opts{widget}) { + $results_table .= "<p class='b-post-question'>$opts{poll_pic}$text$posted</p><div id='LJ_Poll_${pollid}_$qid' class='b-potd-poll'>"; + } else { + $results_table .= "<p>$text</p><div id='LJ_Poll_${pollid}_$qid' style='margin: 10px 0pt 10px 40px;'>"; + } } else { - $results_table .= "<p>$text</p><div id='LJ_Poll_${pollid}_$qid' style='margin: 10px 0pt 10px 40px;'>"; + $results_table .= "<p>".LJ::Lang::ml('poll.election.subject')."</p><div id='LJ_Poll_${pollid}_$qid' style='margin: 10px 0pt 10px 40px;'>"; } $posted = ''; @@ -1258,7 +1279,8 @@ $results_table .= LJ::html_check({ 'type' => $q->type, 'name' => "pollq-$qid", 'value' => $itid, 'id' => "pollq-$pollid-$qid-$itid", 'selected' => ($preval{$qid} =~ /\b$itid\b/) }); - $results_table .= " <label for='pollq-$pollid-$qid-$itid'>$item</label><br class=\"i-potd-br\" />"; + my $received = ($is_super && $itvotes{$itid}) ? LJ::Lang::ml ("poll.election.received.votes", { cnt => $itvotes{$itid} }) : ''; + $results_table .= " <label for='pollq-$pollid-$qid-$itid'>$item $received</label><br class=\"i-potd-br\" />"; next; } @@ -1315,7 +1337,7 @@ if ($do_form) { $ret .= LJ::html_submit( 'poll-submit', - LJ::Lang::ml('poll.submit'), + $is_super ? LJ::Lang::ml('poll.vote') : LJ::Lang::ml('poll.submit'), {class => 'LJ_PollSubmit'}) . "</form>\n";; } Modified: trunk/cgi-bin/LJ/Setting/WebmasterTools.pm =================================================================== --- trunk/cgi-bin/LJ/Setting/WebmasterTools.pm 2010-12-24 07:06:40 UTC (rev 18002) +++ trunk/cgi-bin/LJ/Setting/WebmasterTools.pm 2010-12-24 11:23:32 UTC (rev 18003) @@ -6,8 +6,9 @@ sub should_render { my ($class, $u) = @_; + my $remote = LJ::get_remote(); return 0 if $class eq __PACKAGE__; # this is an abstract class - return $u && $u->is_personal; + return ($u && $u->is_personal) || ($remote && $remote->can_super_manage($u)) ? 1 : 0; } sub code { Modified: trunk/cgi-bin/LJ/User.pm =================================================================== --- trunk/cgi-bin/LJ/User.pm 2010-12-24 07:06:40 UTC (rev 18002) +++ trunk/cgi-bin/LJ/User.pm 2010-12-24 11:23:32 UTC (rev 18003) @@ -200,6 +200,7 @@ my $remote = LJ::get_remote(); LJ::set_rel($u, $remote, "A"); # maintainer + LJ::set_rel($u, $remote, "S"); # supermaintainer LJ::set_rel($u, $remote, "M") if $opts{moderated} =~ /^[AF]$/; # moderator if moderated LJ::join_community($remote, $u, 1, 1); # member @@ -5166,6 +5167,33 @@ return $u->show_graphic_previews eq "on" ? 1 : 0; } +# name: can_super_manage +# des: Given a target user and determines that the user is an supermaintainer of community +# returns: bool: true if supermaitainer, otherwise fail +# args: u +# des-u: user object or userid of community +sub can_super_manage { + my $remote = shift; + my $u = LJ::want_user(shift); + + return undef unless $remote && $u; + + # is same user? + return 1 if LJ::u_equals($u, $remote); + + # do not allow suspended users manage other accounts + return 0 if $remote->is_suspended; + + # people/syn/rename accounts can only be managed by the one account + return undef if $u->{journaltype} =~ /^[PYR]$/; + + # check for supermaintainer access + return undef unless LJ::check_rel($u, $remote, 'S'); + + # passed checks, return true + return 1; +} + # name: can_manage # des: Given a target user and determines that the user is an admin for the taget user # returns: bool: true if authorized, otherwise fail Modified: trunk/cgi-bin/ljlib.pl =================================================================== --- trunk/cgi-bin/ljlib.pl 2010-12-24 07:06:40 UTC (rev 18002) +++ trunk/cgi-bin/ljlib.pl 2010-12-24 11:23:32 UTC (rev 18003) @@ -1352,8 +1352,12 @@ # </LJFUNC> sub get_authas_user { my $user = shift; + my $opts = shift; + return undef unless $user; + $opts = { type => $opts } unless ref $opts; + # get a remote my $remote = LJ::get_remote(); return undef unless $remote; @@ -1367,7 +1371,11 @@ return undef unless $u->{clusterid}; # does $u have admin access? - return undef unless $remote->can_manage($u); + if ($opts->{'type'} eq 'S') { + return undef unless $remote->can_super_manage($u); + } else { + return undef unless $remote->can_manage($u); + } # passed all checks, return $u return $u; Added: trunk/htdocs/community/election.bml =================================================================== --- trunk/htdocs/community/election.bml (rev 0) +++ trunk/htdocs/community/election.bml 2010-12-24 11:23:32 UTC (rev 18003) @@ -0,0 +1,65 @@ +<?page +body<= +<?_code + use strict; + use vars qw(%GET %POST $title); + + # TODO set crumb + #LJ::set_active_crumb('commaccount'); + + $title = $ML{'.title'}; + my $body; + + my $remote = LJ::get_remote(); + unless ($remote) { + $body = "<?needlogin?>"; + return $body; + } + + $body .= "<form method='GET'>\n"; + $body .= LJ::make_authas_select($remote, { 'authas' => $GET{'authas'}, 'type' => 'C' }); + $body .= "</form>\n\n"; + + my $authas = $GET{'authas'} || $remote->{'user'}; + my $u = LJ::get_authas_user($authas); + return LJ::bad_input($ML{'error.invalidauth'}) + unless $u; + + unless ($remote->can_manage ($u)) { + return "You can't vote for supermaintainer"; + } + + # Must be working with a community + unless ($u->{journaltype} eq 'C') { + $body .= "<br />$ML{'.choose'}"; + return $body; + } + + my $warning; + + $body .= "<?errorbar <strong>$ML{'.error.ineligible'}</strong> errorbar?>" + unless $u->{statusvis} eq 'V' || $u->is_readonly; + + # Upgrade successful + $body .= "<?warningbar $warning warningbar?><br />" if $warning; + + my $poll_id = $u->prop ('election_poll_id'); + return $body . '<br/>Net polla' unless $poll_id; + + $body .= "<hr width='30%'>"; + + my $poll = LJ::Poll->new($poll_id); + $body .= $poll->render; + + + return $body; +_code?> +<=body +title=><?_code return $title; _code?> +head<= +<?_code + LJ::need_res('stc/pay.css'); + return $head; +_code?> +<=head +page?> Added: trunk/htdocs/community/election.bml.text.local =================================================================== --- trunk/htdocs/community/election.bml.text.local (rev 0) +++ trunk/htdocs/community/election.bml.text.local 2010-12-24 11:23:32 UTC (rev 18003) @@ -0,0 +1,5 @@ +.title=Community Supermaintainer Election +.choose=Please choose a community + + + Modified: trunk/htdocs/manage/settings/index.bml =================================================================== --- trunk/htdocs/manage/settings/index.bml 2010-12-24 07:06:40 UTC (rev 18002) +++ trunk/htdocs/manage/settings/index.bml 2010-12-24 11:23:32 UTC (rev 18003) @@ -136,7 +136,7 @@ extensions => { name => LJ::Lang::ml('.cat.integration'), visible => 1, - disabled => (!$u || $u->is_community && (!LJ::SUP->is_sup_enabled($u) || !LJ::is_enabled('lj_live_roll')) ) ? 1 : 0, + disabled => (!$u || !($remote && $remote->can_super_manage($u)) && (!LJ::SUP->is_sup_enabled($u) || !LJ::is_enabled('lj_live_roll')) ) ? 1 : 0, form => 1, desc => LJ::Lang::ml('.cat.integration.desc'), need_ssl => 0, Modified: trunk/htdocs/poll/index.bml =================================================================== --- trunk/htdocs/poll/index.bml 2010-12-24 07:06:40 UTC (rev 18002) +++ trunk/htdocs/poll/index.bml 2010-12-24 11:23:32 UTC (rev 18003) @@ -28,6 +28,7 @@ } my $poll = LJ::Poll->new($pollid); + my $is_super = $poll->prop ('supermaintainer'); unless ($poll && $poll->valid) { $title = $ML{'Error'}; @@ -42,6 +43,9 @@ my $mode = ""; $mode = $FORM{'mode'} if ($FORM{'mode'} =~ /(enter|results|ans)/); + ## Supermaintainer election has only one mode - voting + $mode = "enter" if $is_super; + # Handle opening and closing of polls # We do this first because a closed poll will alter how a poll is displayed if ($poll->is_owner($remote)) { @@ -117,6 +121,10 @@ $body .= join('', map { "<p>$_</p>" } @warnings); return; } + if ($is_super) { + my $journal = LJ::want_user($poll->journalid); + return BML::redirect($LJ::SITEROOR."/community/election.bml?authas=".$journal->user); + } return BML::redirect($entry->url); }