Use $u->has_banned( $remote ), instead of LJ::is_banned( $remote, $u ),
or $u->is_banned( $remote ). Note the confusing inconsistent argument order.
Also, code modernization.
Patch by kareila.
diffs (238 lines):
diff -r 4ea4957bcb9f -r 44a1463f4850 cgi-bin/LJ/Poll.pm
--- a/cgi-bin/LJ/Poll.pm Mon Jun 28 16:50:56 2010 +0800
+++ b/cgi-bin/LJ/Poll.pm Mon Jun 28 18:00:21 2010 +0800
@@ -1136,13 +1136,12 @@ sub can_vote {
# owner can do anything
return 1 if $remote && $remote->userid == $self->posterid;
- my $is_friend = $remote && $self->journal->trusts_or_has_member( $remote );
+ my $trusted = $remote && $self->journal->trusts_or_has_member( $remote );
- return 0 if $self->whovote eq "trusted" && !$is_friend;
+ return 0 if $self->whovote eq "trusted" && !$trusted;
- if (LJ::is_banned($remote, $self->journalid) || LJ::is_banned($remote,
$self->posterid)) {
- return 0;
- }
+ return 0 if $self->journal->has_banned( $remote )
+ or $self->poster->has_banned( $remote );
if ($self->is_createdate_restricted) {
my $propval = $self->prop("createdate");
diff -r 4ea4957bcb9f -r 44a1463f4850 cgi-bin/LJ/Tags.pm
--- a/cgi-bin/LJ/Tags.pm Mon Jun 28 16:50:56 2010 +0800
+++ b/cgi-bin/LJ/Tags.pm Mon Jun 28 18:00:21 2010 +0800
@@ -473,7 +473,7 @@ sub can_add_tags {
my $remote = LJ::want_user(shift);
return undef unless $u && $remote;
return undef unless $remote->is_person;
- return undef if LJ::is_banned($remote, $u);
+ return undef if $u->has_banned( $remote );
# get permission hashref and check it; note that we fall back to the
control
# permission, which will allow people to add even if they can't add by
default
@@ -491,9 +491,10 @@ sub can_add_entry_tags {
return undef unless $remote && $entry;
return undef unless $remote->is_personal;
- return undef if $remote->is_banned( $entry->journal );
my $journal = $entry->journal;
+ return undef if $journal->has_banned( $remote );
+
my $perms = LJ::Tags::get_permission_levels( $journal );
# specific case: are we the author of this entry, or otherwise an admin of
the journal?
@@ -528,7 +529,7 @@ sub can_control_tags {
my $remote = LJ::want_user(shift);
return undef unless $u && $remote;
return undef unless $remote->is_person;
- return undef if LJ::is_banned($remote, $u);
+ return undef if $u->has_banned( $remote );
# get permission hashref and check it
my $perms = LJ::Tags::get_permission_levels($u);
diff -r 4ea4957bcb9f -r 44a1463f4850 cgi-bin/LJ/Talk.pm
--- a/cgi-bin/LJ/Talk.pm Mon Jun 28 16:50:56 2010 +0800
+++ b/cgi-bin/LJ/Talk.pm Mon Jun 28 18:00:21 2010 +0800
@@ -1331,7 +1331,7 @@ sub talkform {
$ret .= "<tr valign='middle' id='ljuser_row'>";
- if ( LJ::is_banned( $remote, $journalu ) ) {
+ if ( $journalu->has_banned( $remote ) ) {
$ret .= $bantext->( 'user' );
} else {
$ret .= "<td align='center'><img
src='$LJ::IMGPREFIX/silk/identity/user.png' onclick='handleRadios(1);'
/></td>";
@@ -1427,7 +1427,7 @@ sub talkform {
$journalu->trusts( $remote ) )
) {
$ret .= "<tr valign='middle' id='oidli' name='oidli'>";
- if ( LJ::is_banned( $remote, $journalu ) ) {
+ if ( $journalu->has_banned( $remote ) ) {
$ret .= $bantext->( 'openid' );
} else {
$ret .= "<td align='center'><img
src='$LJ::IMGPREFIX/silk/identity/openid.png' onclick='handleRadios(4);'
/></td>";
@@ -1529,7 +1529,7 @@ sub talkform {
# Don't worry about a real href since js hides the row anyway
my $other_user = "<script language='JavaScript'>if
(document.getElementById) {document.write(\" <a href='#'
onClick='otherLJUser();return false;'>[other]</a>\");}</script>";
- if ( LJ::is_banned( $remote, $journalu ) ) {
+ if ( $journalu->has_banned( $remote ) ) {
$ret .= $bantext->( 'user', $other_user );
} else {
$ret .= "<td align='center'><img
src='$LJ::IMGPREFIX/silk/identity/user.png' onclick='handleRadios(1);'
/></td>";
@@ -3009,9 +3009,7 @@ sub init {
$up = LJ::load_user($form->{'userpost'});
if ($up) {
### see if the user is banned from posting here
- if (LJ::is_banned($up, $journalu)) {
- $mlerr->("$SC.error.banned");
- }
+ $mlerr->("$SC.error.banned") if $journalu->has_banned( $up );
# TEMP until we have better openid support
if ($up->is_identity && $journalu->{'opt_whocanreply'} eq
"reg") {
@@ -3076,7 +3074,7 @@ sub init {
$up = $remote;
### see if the user is banned from posting here
- $mlerr->("$SC.error.banned") if (LJ::is_banned($up, $journalu));
+ $mlerr->("$SC.error.banned") if $journalu->has_banned( $up );
if ($form->{'oiddo_login'}) {
$up->make_login_session($form->{'exptype'},
$form->{'ipfixed'});
diff -r 4ea4957bcb9f -r 44a1463f4850 cgi-bin/LJ/User.pm
--- a/cgi-bin/LJ/User.pm Mon Jun 28 16:50:56 2010 +0800
+++ b/cgi-bin/LJ/User.pm Mon Jun 28 18:00:21 2010 +0800
@@ -3227,10 +3227,15 @@ sub ban_user_multi {
# return if $target is banned from $u's journal
-*has_banned = \&is_banned;
-sub is_banned {
- my ($u, $target) = @_;
- return LJ::is_banned($target->userid, $u->userid);
+sub has_banned {
+ my ( $u, $target ) = @_;
+
+ my $uid = LJ::want_userid( $u );
+ my $jid = LJ::want_userid( $target );
+ return 1 unless $uid && $jid;
+ return 0 if $uid == $jid; # can't ban yourself
+
+ return LJ::check_rel( $uid, $jid, 'B' );
}
diff -r 4ea4957bcb9f -r 44a1463f4850 cgi-bin/communitylib.pl
--- a/cgi-bin/communitylib.pl Mon Jun 28 16:50:56 2010 +0800
+++ b/cgi-bin/communitylib.pl Mon Jun 28 18:00:21 2010 +0800
@@ -76,7 +76,7 @@ sub send_comm_invite {
return undef unless $u && $cu && $mu;
# step 1: if the user has banned the community, don't accept the invite
- return LJ::error('comm_user_has_banned') if LJ::is_banned($cu, $u);
+ return LJ::error('comm_user_has_banned') if $u->has_banned( $cu );
# step 2: lazily clean out old community invites.
return LJ::error('db') unless $u->writer;
diff -r 4ea4957bcb9f -r 44a1463f4850 cgi-bin/ljprotocol.pl
--- a/cgi-bin/ljprotocol.pl Mon Jun 28 16:50:56 2010 +0800
+++ b/cgi-bin/ljprotocol.pl Mon Jun 28 18:00:21 2010 +0800
@@ -1213,8 +1213,7 @@ sub postevent
# make sure this user isn't banned from posting here (if
# this is a community journal)
- return fail($err,151) if
- LJ::is_banned($posterid, $ownerid);
+ return fail($err,151) if $uowner->has_banned( $u );
# don't allow backdated posts in communities
return fail($err,152) if
diff -r 4ea4957bcb9f -r 44a1463f4850 cgi-bin/ljrelation.pl
--- a/cgi-bin/ljrelation.pl Mon Jun 28 16:50:56 2010 +0800
+++ b/cgi-bin/ljrelation.pl Mon Jun 28 18:00:21 2010 +0800
@@ -13,28 +13,6 @@
package LJ;
use strict;
-
-# <LJFUNC>
-# name: LJ::is_banned
-# des: Checks to see if a user is banned from a journal.
-# returns: boolean; 1 if "user" is banned from "journal"
-# args: user, journal
-# des-user: User hashref or userid.
-# des-journal: Journal hashref or userid.
-# </LJFUNC>
-sub is_banned {
- # get user and journal ids
- my $uid = LJ::want_userid(shift);
- my $jid = LJ::want_userid(shift);
- return 1 unless $uid && $jid;
-
- # for speed: common case is non-community posting and replies
- # in own journal. avoid db hit.
- return 0 if ($uid == $jid);
-
- # edge from journal -> user
- return LJ::check_rel($jid, $uid, 'B');
-}
# <LJFUNC>
# name: LJ::get_reluser_id
diff -r 4ea4957bcb9f -r 44a1463f4850 htdocs/community/join.bml
--- a/htdocs/community/join.bml Mon Jun 28 16:50:56 2010 +0800
+++ b/htdocs/community/join.bml Mon Jun 28 18:00:21 2010 +0800
@@ -53,7 +53,7 @@ body<=
# ensure this user isn't banned
return "<?h1 $ML{'Sorry'} h1?><?p $ML{'.label.banned'} p?>"
- if LJ::is_banned($remote, $cu);
+ if $cu->has_banned( $remote );
# and make sure they're not already a member
return "<?h1 $ML{'Error'} h1?><?p $ML{'.error.already.member'} p?>"
diff -r 4ea4957bcb9f -r 44a1463f4850 htdocs/tools/endpoints/changerelation.bml
--- a/htdocs/tools/endpoints/changerelation.bml Mon Jun 28 16:50:56 2010 +0800
+++ b/htdocs/tools/endpoints/changerelation.bml Mon Jun 28 18:00:21 2010 +0800
@@ -105,11 +105,11 @@ _c?>
$success = $remote->ban_user($ban_user);
LJ::Hooks::run_hooks('ban_set', $remote, $ban_user);
- #$ret{is_banned} = $remote->is_banned($ban_user) ? 1 : 0;
+ #$ret{is_banned} = $remote->has_banned($ban_user) ? 1 : 0;
} elsif ( $action eq 'setUnban' ) {
my $unban_user = LJ::load_user($target);
$success = $remote->unban_user_multi($unban_user->{userid});
- #$ret{is_banned} = $remote->is_banned($unban_user) ? 1 : 0;
+ #$ret{is_banned} = $remote->has_banned($unban_user) ? 1 : 0;
} else {
return $err->("Invalid action $action");
}
diff -r 4ea4957bcb9f -r 44a1463f4850 htdocs/tools/endpoints/ctxpopup.bml
--- a/htdocs/tools/endpoints/ctxpopup.bml Mon Jun 28 16:50:56 2010 +0800
+++ b/htdocs/tools/endpoints/ctxpopup.bml Mon Jun 28 18:00:21 2010 +0800
@@ -138,8 +138,7 @@ _c?>
my %extrainfo = LJ::Hooks::run_hook("ctxpopup_extra_info", $u);
%ret = (%ret, %extrainfo);
- $ret{is_banned} = LJ::is_banned($u,$remote) ? 1 : 0
- if $remote && $u;
+ $ret{is_banned} = $remote->has_banned( $u ) ? 1 : 0 if $remote;
$ret{success} = 1;
return LJ::js_dumper(\%ret);
diff -r 4ea4957bcb9f -r 44a1463f4850 htdocs/tools/popsubscriptions.bml
--- a/htdocs/tools/popsubscriptions.bml Mon Jun 28 16:50:56 2010 +0800
+++ b/htdocs/tools/popsubscriptions.bml Mon Jun 28 18:00:21 2010 +0800
@@ -127,7 +127,7 @@ body<=
my $popuser = $popusers->{$uid};
# don't show inactive accounts, or banned accounts
- next if $uid == $remote_id || $popuser->is_inactive ||
$remote->is_banned( $popuser, $remote);
+ next if $uid == $remote_id || $popuser->is_inactive ||
$remote->has_banned( $popuser );
# sort userids into arrays
if ( $numberpersonal < $maximum && $popuser->is_personal ) {
_______________________________________________
dw-changelog mailing list
[email protected]
http://lists.dwscoalition.org/mailman/listinfo/dw-changelog