[dw-free] update community membership backend
[commit: http://hg.dwscoalition.org/dw-free/rev/913ec83595d8]
http://bugs.dwscoalition.org/show_bug.cgi?id=161
Allow viewing members-only posts in communities. Lightly tested.
Patch by
mark.
http://bugs.dwscoalition.org/show_bug.cgi?id=161
Allow viewing members-only posts in communities. Lightly tested.
Patch by
![[staff profile]](https://www.dreamwidth.org/img/silk/identity/user_staff.png)
-------------------------------------------------------------------------------- diff -r cda50f44faf8 -r 913ec83595d8 cgi-bin/DW/Logic/LogItems.pm --- a/cgi-bin/DW/Logic/LogItems.pm Tue Feb 24 08:41:09 2009 +0000 +++ b/cgi-bin/DW/Logic/LogItems.pm Tue Feb 24 09:09:34 2009 +0000 @@ -429,8 +429,14 @@ sub recent_items my $itemload = $itemshow + $skip; my $mask = 0; - if ($remote && ($remote->{'journaltype'} eq "P" || $remote->{'journaltype'} eq "I") && $remoteid != $userid) { - $mask = $u->trustmask( $remote ); + if ( $remote && ( $remote->is_person || $remote->is_identity ) && $remoteid != $userid ) { + # if this is a community we're viewing, fake the mask to select on, as communities + # no longer have masks to users + if ( $u->is_community ) { + $mask = $remote->member_of( $u ) ? 1 : 0; + } else { + $mask = $u->trustmask( $remote ); + } } # decide what level of security the remote user can see diff -r cda50f44faf8 -r 913ec83595d8 cgi-bin/LJ/Entry.pm --- a/cgi-bin/LJ/Entry.pm Tue Feb 24 08:41:09 2009 +0000 +++ b/cgi-bin/LJ/Entry.pm Tue Feb 24 09:09:34 2009 +0000 @@ -874,6 +874,10 @@ sub visible_to # if it's usemask, we have to refuse non-personal journals, # so we have to load the user return 0 unless $remote->{'journaltype'} eq 'P' || $remote->{'journaltype'} eq 'I'; + + # check if it's a community and they're a member + return 1 if $self->journal->is_community && + $remote->member_of( $self->journal ); my $gmask = $self->journal->trustmask( $remote ); my $allowed = (int($gmask) & int($self->{'allowmask'})); @@ -1736,7 +1740,12 @@ sub get_log2_recent_user my $mask = $mask_for_remote{$item->{journalid}}; unless (defined $mask) { my $ju = LJ::load_userid( $item->{journalid} ); - $mask = $ju->trustmask( $remote ); + if ( $ju->is_community ) { + # communities don't have masks towards users, so fake it + $mask = $remote->member_of( $ju ) ? 1 : 0; + } else { + $mask = $ju->trustmask( $remote ); + } $mask_for_remote{$item->{journalid}} = $mask; } $permit = $item->{'allowmask'}+0 & $mask+0; diff -r cda50f44faf8 -r 913ec83595d8 cgi-bin/LJ/User.pm --- a/cgi-bin/LJ/User.pm Tue Feb 24 08:41:09 2009 +0000 +++ b/cgi-bin/LJ/User.pm Tue Feb 24 09:09:34 2009 +0000 @@ -4869,6 +4869,9 @@ sub get_postto_list { # </LJFUNC> sub can_view { + +# TODO: fold this into LJ::Entry->visible_to :( + &nodb; my $remote = shift; my $item = shift; @@ -4896,8 +4899,14 @@ sub can_view # so we have to load the user return 0 unless $remote->{'journaltype'} eq 'P' || $remote->{'journaltype'} eq 'I'; - # TAG:FR:ljlib:can_view (turn off bit 0 for just watching? hmm.) + # this far down we have to load the user my $u = LJ::want_user( $userid ) or return 0; + + # check if it's a community and they're a member + return 1 if $u->is_community && + $remote->member_of( $u ); + + # now load allowmask my $allowed = ( $u->trustmask( $remoteid ) & int($item->{'allowmask'}) ); return $allowed ? 1 : 0; # no need to return matching mask } --------------------------------------------------------------------------------