Igor Gariev (gariev) wrote in changelog,
Igor Gariev
gariev
changelog

[livejournal] r15630: LJSUP-4767: Tagging system in communitie...

Committer: gariev
LJSUP-4767: Tagging system in communities: add new settings

U   trunk/cgi-bin/LJ/Console/Command/TagPermissions.pm
U   trunk/cgi-bin/LJ/S2.pm
U   trunk/cgi-bin/taglib.pl
U   trunk/cgi-bin/talklib.pl
U   trunk/htdocs/edittags.bml
U   trunk/htdocs/manage/tags.bml
Modified: trunk/cgi-bin/LJ/Console/Command/TagPermissions.pm
===================================================================
--- trunk/cgi-bin/LJ/Console/Command/TagPermissions.pm	2009-08-24 09:30:54 UTC (rev 15629)
+++ trunk/cgi-bin/LJ/Console/Command/TagPermissions.pm	2009-08-24 11:06:26 UTC (rev 15630)
@@ -10,7 +10,7 @@
 
 sub args_desc { [
                  'community' => "Optional; community to change permission levels for.",
-                 'add level' => "Accounts at this level can add existing tags to entries. One of 'public', 'friends', 'private', or a custom friend group name.",
+                 'add level' => "Accounts at this level can add existing tags to entries. One of 'public', 'friends', 'private', 'author_moder' or a custom friend group name.",
                  'control level' => "Accounts at this level can do everything: add, remove, and create new ones. Value is one of 'public', 'friends', 'private', or a custom friend group name.",
                  ] }
 
@@ -61,6 +61,10 @@
     $control = $validate_level->($control);
     return $self->error("Levels must be one of: 'private', 'public', 'friends', 'author_moder', or the name of a friends group.")
         unless $add && $control;
+    return $self->error("Only <add level> can be 'author_moder'") 
+        if $control eq 'author_moder';
+    return $self->error("'author_moder' level can be applied to communities only")
+        if $add eq 'author_moder' && !$foru->is_community;
 
     $foru->set_prop('opt_tagpermissions', "$add,$control");
 

Modified: trunk/cgi-bin/LJ/S2.pm
===================================================================
--- trunk/cgi-bin/LJ/S2.pm	2009-08-24 09:30:54 UTC (rev 15629)
+++ trunk/cgi-bin/LJ/S2.pm	2009-08-24 11:06:26 UTC (rev 15630)
@@ -3595,6 +3595,7 @@
     my $remote = LJ::get_remote();
     my $null_link = { '_type' => 'Link', '_isnull' => 1 };
     my $journalu = LJ::load_user($journal);
+    my $entry = LJ::Entry->new($journalu, ditemid => $this->{itemid});
 
     if ($key eq "edit_entry") {
         return $null_link unless $remote && ($remote->{'user'} eq $journal ||
@@ -3605,7 +3606,7 @@
                             LJ::S2::Image("$LJ::IMGPREFIX/btn_edit.gif", 22, 20));
     }
     if ($key eq "edit_tags") {
-        return $null_link unless $remote && LJ::Tags::can_add_tags(LJ::load_user($journal), $remote);
+        return $null_link unless $remote && LJ::Tags::can_add_entry_tags($remote, $entry);
         return LJ::S2::Link("$LJ::SITEROOT/edittags.bml?journal=$journal&itemid=$this->{'itemid'}",
                             $ctx->[S2::PROPS]->{"text_edit_tags"},
                             LJ::S2::Image("$LJ::IMGPREFIX/btn_edittags.gif", 22, 20));
@@ -3637,7 +3638,6 @@
     if ($key eq "flag") {
         return $null_link unless LJ::is_enabled("content_flag");
 
-        my $entry = LJ::Entry->new($journalu, ditemid => $this->{itemid});
         return $null_link unless $remote && $remote->can_see_content_flag_button( content => $entry );
         return LJ::S2::Link(LJ::ContentFlag->adult_flag_url($entry),
                             $ctx->[S2::PROPS]->{"text_flag"},

Modified: trunk/cgi-bin/taglib.pl
===================================================================
--- trunk/cgi-bin/taglib.pl	2009-08-24 09:30:54 UTC (rev 15629)
+++ trunk/cgi-bin/taglib.pl	2009-08-24 11:06:26 UTC (rev 15630)
@@ -472,6 +472,36 @@
 }
 
 # <LJFUNC>
+# name: LJ::Tags::can_add_entry_tags
+# class: tags
+# des: Determines if user is allowed to add tags to (edit tags of) an individual entry.
+# args: remote, entry
+# des-remote: User id or object of account performing the action
+# des-entry: LJ::Entry object
+# returns: 1 if allowed, 0 if not, undef on error
+# </LJFUNC>
+sub can_add_entry_tags {
+    return undef if $LJ::DISABLED{tags};
+
+    my $remote = LJ::want_user(shift);
+    my $entry = shift;
+    return unless $remote && $entry;
+    
+    ## generic case: if $remote can add tags to the entire journal of the entry
+    my $journal = $entry->journal;
+    return 1 if LJ::Tags::can_add_tags($journal, $remote);
+    
+    ## special case: $remote is author of the $entry in a community,
+    ## and community settings allows 'author or maintainters' to change tags 
+    my $perms = LJ::Tags::get_permission_levels($journal);
+    return 1 if $perms->{add} eq 'author_moder' && $remote==$entry->poster;
+    
+    ## not allowed.
+    return;
+}
+
+
+# <LJFUNC>
 # name: LJ::Tags::can_control_tags
 # class: tags
 # des: Determines if one account is allowed to control (add, edit, delete) the tags of another.
@@ -509,8 +539,6 @@
         return 0;
     } elsif ($perm eq 'friends') {
         return LJ::is_friend($u, $remote);
-    } elsif ($perm eq 'author_moder') {
-        return LJ::is_friend($u, $remote) || LJ::can_manage($remote, $u);
     } elsif ($perm eq 'private') {
         return LJ::can_manage($remote, $u);
     } elsif ($perm =~ /^group:(\d+)$/) {
@@ -702,7 +730,8 @@
 
     # get access levels
     my $can_control = LJ::Tags::can_control_tags($u, $remote);
-    my $can_add = $can_control || LJ::Tags::can_add_tags($u, $remote);
+    my $entry = LJ::Entry->new($u, jitemid=>$jitemid);
+    my $can_add = $can_control || LJ::Tags::can_add_entry_tags($remote, $entry);
 
     # bail out early if we can't do any actions
     return undef unless $can_add || $opts->{force};

Modified: trunk/cgi-bin/talklib.pl
===================================================================
--- trunk/cgi-bin/talklib.pl	2009-08-24 09:30:54 UTC (rev 15629)
+++ trunk/cgi-bin/talklib.pl	2009-08-24 11:06:26 UTC (rev 15630)
@@ -146,7 +146,7 @@
 
     # edit tags
     unless ($LJ::DISABLED{tags}) {
-        if (defined $remote && LJ::Tags::can_add_tags($u, $remote)) {
+        if (defined $remote && LJ::Tags::can_add_entry_tags($remote, $entry)) {
             push @linkele, $mlink->("$LJ::SITEROOT/edittags.bml?${jargent}itemid=$itemid", "edittags");
         }
     }

Modified: trunk/htdocs/edittags.bml
===================================================================
--- trunk/htdocs/edittags.bml	2009-08-24 09:30:54 UTC (rev 15629)
+++ trunk/htdocs/edittags.bml	2009-08-24 11:06:26 UTC (rev 15630)
@@ -31,6 +31,7 @@
     my $jitemid = int($ditemid / 256);
     return $err->($ML{'.invalid.entry'}) unless $jitemid;
 
+    my $entry = LJ::Entry->new($u, ditemid=>$ditemid);
     my $logrow = LJ::get_log2_row($u, $jitemid);
     return $err->($ML{'.invalid.entry'}) unless $logrow;
     return $err->($ML{'.invalid.entry'}) unless $logrow->{anum} == $anum;
@@ -97,7 +98,8 @@
     $ret .= '<form method="POST" action="/edittags.bml" id="edit_tagform">';
     $ret .= LJ::form_auth();
     $ret .= "<td class='sep'>";
-    if ( LJ::Tags::can_add_tags($u, $remote) ) {
+    my $can_remote_add_entry_tags = LJ::Tags::can_add_entry_tags($remote, $entry);
+    if ($can_remote_add_entry_tags) {
         $ret .= LJ::html_text(
             {
                 name  => 'edittags',
@@ -130,7 +132,7 @@
     }
 
     $ret .= "<br /><br />";
-    $ret .= "$ML{'.permissions.add.yes'}<br />" if LJ::Tags::can_add_tags($u, $remote);
+    $ret .= "$ML{'.permissions.add.yes'}<br />" if $can_remote_add_entry_tags;
     $ret .= "$ML{'.permissions.control.yes'}<br />" if LJ::Tags::can_control_tags($u, $remote);
     $ret .= BML::ml('.view', { aopts => 'href="' . LJ::journal_base($u) . "/$ditemid.html" . '"' });
     $ret .= "</td></tr>";

Modified: trunk/htdocs/manage/tags.bml
===================================================================
--- trunk/htdocs/manage/tags.bml	2009-08-24 09:30:54 UTC (rev 15629)
+++ trunk/htdocs/manage/tags.bml	2009-08-24 11:06:26 UTC (rev 15630)
@@ -64,7 +64,7 @@
 
             return LJ::bad_input($ML{'.error.invalidsettings'})
                unless $add =~ /^(?:private|public|friends|group:\d+|author_moder)$/ &&
-               $control =~ /^(?:private|public|friends|group:\d+|author_moder)$/;
+               $control =~ /^(?:private|public|friends|group:\d+)$/;
 
             $u->set_prop("opt_tagpermissions", "$add,$control");
         }
@@ -279,13 +279,13 @@
     } else {
         push @groups, ("friends", $ML{'.setting.members'});
         push @groups, ("private", $ML{'.setting.maintainers'});
-        push @groups, ("author_moder", $ML{'.setting.author'});
     }
 
     my $grouplist = LJ::get_friend_group($u);
-    push @groups,  map  { "group:" . $_, $grouplist->{$_}->{groupname} }
-    sort { $grouplist->{$a}->{groupname} cmp $grouplist->{$b}->{groupname} }
-    keys %$grouplist;
+    push @groups,  
+        map  { "group:" . $_, $grouplist->{$_}->{groupname} }
+        sort { $grouplist->{$a}->{groupname} cmp $grouplist->{$b}->{groupname} }
+        keys %$grouplist;
 
     my $security = LJ::Tags::get_permission_levels($u);
 
@@ -293,6 +293,14 @@
         . LJ::html_select({ name => 'control_level', selected => $security->{control} }, @groups)
         . " $ML{'.setting.desc.control'} </div>";
 
+
+    ## security level "author_moder" (entry's tags can be changed by entry's author or
+    ## by moderator or a community can be applied to communities only
+    if ($u->is_community) {
+        # insert after (public, friends, private)
+        splice @groups, 3*2, 0, ("author_moder", $ML{'.setting.author'});
+    }
+    
     $ret .= "<div class='tagsec'>"
             . LJ::html_select({ name => 'add_level', selected => $security->{add} }, @groups)
             . " $ML{'.setting.desc.add'} </div>";

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