[livejournal] r18554: LJSUP-8149: trusted users for personal j...
Committer: vsukhanov
LJSUP-8149: trusted users for personal journalsU trunk/cgi-bin/LJ/Console/Command/BanSet.pm U trunk/cgi-bin/LJ/Talk.pm U trunk/cgi-bin/LJ/User.pm U trunk/cgi-bin/ljrelation.pl U trunk/htdocs/delcomment.bml
Modified: trunk/cgi-bin/LJ/Console/Command/BanSet.pm
===================================================================
--- trunk/cgi-bin/LJ/Console/Command/BanSet.pm 2011-03-15 10:45:32 UTC (rev 18553)
+++ trunk/cgi-bin/LJ/Console/Command/BanSet.pm 2011-03-15 10:49:44 UTC (rev 18554)
@@ -34,8 +34,14 @@
return $self->error("Unknown account: $comm")
unless $journal;
- return $self->error("You are not a maintainer of this account")
- unless $remote && $remote->can_manage($journal);
+ ## Access controll
+ if ($journal->is_person){
+ return $self->error("You are not a watcher of this account")
+ unless $remote and $remote->can_sweep($journal);
+ } else {
+ return $self->error("You are not a maintainer of this account")
+ unless $remote && $remote->can_manage($journal);
+ }
}
my $banuser = LJ::load_user($user);
Modified: trunk/cgi-bin/LJ/Talk.pm
===================================================================
--- trunk/cgi-bin/LJ/Talk.pm 2011-03-15 10:45:32 UTC (rev 18553)
+++ trunk/cgi-bin/LJ/Talk.pm 2011-03-15 10:49:44 UTC (rev 18554)
@@ -344,7 +344,8 @@
return 1 if $remote->{'user'} eq $userpost ||
$remote->{'user'} eq (ref $u ? $u->{'user'} : $u) ||
$remote->{'user'} eq (ref $up ? $up->{'user'} : $up) ||
- $remote->can_manage($u);
+ $remote->can_manage($u) ||
+ $remote->can_sweep($u);
return 0;
}
@@ -382,6 +383,7 @@
sub can_mark_spam {
return 0 unless $_[0];
return 1 if $_[0]->can_moderate($_[1]);
+ return 1 if $_[0]->can_sweep($_[1]);
return LJ::Talk::can_screen(@_);
}
@@ -856,10 +858,15 @@
return undef unless $nodeid =~ /^\d+$/;
my $uid = $u->id;
- # call normally if no gearman/not wanted
+ ## call normally if no gearman/not wanted
+
+ ## Do no try to connect to Gearman if there is no need.
+ return get_talk_data_do($uid, $nodetype, $nodeid, $opts)
+ unless LJ::conf_test($LJ::LOADCOMMENTS_USING_GEARMAN, $u->id);
+
my $gc = LJ::gearman_client();
return get_talk_data_do($uid, $nodetype, $nodeid, $opts)
- unless $gc && LJ::conf_test($LJ::LOADCOMMENTS_USING_GEARMAN, $u->id);
+ unless $gc;
# invoke gearman
my $result;
@@ -885,6 +892,9 @@
# retrieves data from the talk2 table (but preferably memcache)
# returns a hashref (key -> { 'talkid', 'posterid', 'datepost', 'datepost_unix',
# 'parenttalkid', 'state' } , or undef on failure
+# opts -> {
+# init_comobject => [1|0], # by default 0, init or not comment objects
+# }
sub get_talk_data_do
{
my ($uid, $nodetype, $nodeid, $opts) = @_;
@@ -895,7 +905,7 @@
my $init_comobj = 1;
$init_comobj = $opts->{init_comobj} if exists $opts->{init_comobj};
-
+
my $ret = {};
# check for data in memcache
@@ -924,8 +934,7 @@
return unless @LJ::MEMCACHE_SERVERS;
return unless $u->writer;
- my $gc = LJ::gearman_client();
- if ($gc && LJ::conf_test($LJ::FIXUP_USING_GEARMAN, $u)) {
+ if (LJ::conf_test($LJ::FIXUP_USING_GEARMAN, $u) and my $gc = LJ::gearman_client()) {
$gc->dispatch_background("fixup_logitem_replycount",
Storable::nfreeze([ $u->id, $nodeid ]), {
uniq => "-",
Modified: trunk/cgi-bin/LJ/User.pm
===================================================================
--- trunk/cgi-bin/LJ/User.pm 2011-03-15 10:45:32 UTC (rev 18553)
+++ trunk/cgi-bin/LJ/User.pm 2011-03-15 10:49:44 UTC (rev 18554)
@@ -5364,6 +5364,27 @@
return 1;
}
+sub can_sweep {
+ 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 to be watchers of other accounts.
+ return 0 if $remote->is_suspended;
+
+ # only personal journals can have watchers
+ return undef unless $u->journaltype eq 'P';
+
+ # check for admin access
+ return undef unless LJ::check_rel($u, $remote, 'W');
+
+ return 1;
+}
+
sub hide_adult_content {
my $u = shift;
Modified: trunk/cgi-bin/ljrelation.pl
===================================================================
--- trunk/cgi-bin/ljrelation.pl 2011-03-15 10:45:32 UTC (rev 18553)
+++ trunk/cgi-bin/ljrelation.pl 2011-03-15 10:49:44 UTC (rev 18554)
@@ -11,6 +11,7 @@
# S - supermaintainer
# I - inviter
# D - spammer
+# W - journal sweeper
#########################
# <LJFUNC>
Modified: trunk/htdocs/delcomment.bml
===================================================================
--- trunk/htdocs/delcomment.bml 2011-03-15 10:45:32 UTC (rev 18553)
+++ trunk/htdocs/delcomment.bml 2011-03-15 10:49:44 UTC (rev 18554)
@@ -141,6 +141,7 @@
my $can_manage = $remote->can_manage($journal);
my $can_mark_spam = LJ::is_enabled('spam_button') &&
LJ::Talk::can_mark_spam($remote, $journal, $poster, $comment);
+ my $can_sweep = ($remote && $poster && $remote->can_sweep($poster));
my %can = (
'manage_journal' => $can_manage,
@@ -151,7 +152,7 @@
# they can ban the comment author if they are the journal owner
# and there is an author; also, they will not be able to ban
# themselves
- 'ban' => $can_manage && $poster && ( $remote != $poster ),
+ 'ban' => ($can_manage || $can_sweep) && $poster && ( $remote != $poster ),
# they can mark as spam unless the comment is their own;
# they don't need to be the community maintainer to do that
