[dw-free] remove LJ::can_view
[commit: http://hg.dwscoalition.org/dw-free/rev/043f9a944c46]
http://bugs.dwscoalition.org/show_bug.cgi?id=2121
Remove LJ::can_view in favor of LJ::Entry->visible_to, former was only used
in three places anyway.
Patch by
mark.
Files modified:
http://bugs.dwscoalition.org/show_bug.cgi?id=2121
Remove LJ::can_view in favor of LJ::Entry->visible_to, former was only used
in three places anyway.
Patch by
![[staff profile]](https://www.dreamwidth.org/img/silk/identity/user_staff.png)
Files modified:
- cgi-bin/LJ/Talk.pm
- cgi-bin/LJ/User.pm
- htdocs/edittags.bml
-------------------------------------------------------------------------------- diff -r be43f2100215 -r 043f9a944c46 cgi-bin/LJ/Talk.pm --- a/cgi-bin/LJ/Talk.pm Thu Nov 26 05:06:52 2009 +0000 +++ b/cgi-bin/LJ/Talk.pm Thu Nov 26 05:17:10 2009 +0000 @@ -253,27 +253,29 @@ sub check_viewable return 0; }; - unless (LJ::can_view($remote, $item)) { - my $journal = LJ::load_userid( $item->{ownerid} ); - my $journalname = $journal->username; + my $ent = LJ::Entry->new_from_item_hash( $item ) + or die "Unable to construct entry object.\n"; + return 1 if $ent->visible_to( $remote ); - if (defined $remote) { - if ( $journal->is_community && ! $journal->is_closed_membership && $remote && $item->{security} ne "private" ) { - return $err->( BML::ml( 'talk.error.notauthorised.comm.open', { aopts => "href='$LJ::SITEROOT/community/join?comm=$journalname'" } ) ); - } elsif ( $journal->is_community && $journal->is_closed_membership ) { - return $err->( BML::ml( 'talk.error.notauthorised.comm.closed' ) ); - } else { - return $err->( BML::ml( 'talk.error.notauthorised' ) ); - } + my $journal = LJ::load_userid( $item->{ownerid} ); + my $journalname = $journal->username; + + if (defined $remote) { + if ( $journal->is_community && ! $journal->is_closed_membership && $remote && $item->{security} ne "private" ) { + return $err->( BML::ml( 'talk.error.notauthorised.comm.open', { aopts => "href='$LJ::SITEROOT/community/join?comm=$journalname'" } ) ); + } elsif ( $journal->is_community && $journal->is_closed_membership ) { + return $err->( BML::ml( 'talk.error.notauthorised.comm.closed' ) ); } else { - my $r = BML::get_request(); - my $host = $r->headers_in->{Host}; - my $args = scalar $r->args; - my $querysep = $args ? "?" : ""; - my $redir = LJ::eurl("http://" . $host . $r->uri . $querysep . $args); + return $err->( BML::ml( 'talk.error.notauthorised' ) ); + } + } else { + my $r = BML::get_request(); + my $host = $r->headers_in->{Host}; + my $args = scalar $r->args; + my $querysep = $args ? "?" : ""; + my $redir = LJ::eurl("http://" . $host . $r->uri . $querysep . $args); - return $err->(BML::redirect("$LJ::SITEROOT/?returnto=$redir&errmsg=notloggedin")); - } + return $err->(BML::redirect("$LJ::SITEROOT/?returnto=$redir&errmsg=notloggedin")); } return 1; @@ -3087,9 +3089,11 @@ sub init { # check that user can even view this post, which is required # to reply to it #### Check security before viewing this post - unless (LJ::can_view($up, $item)) { - $bmlerr->("$SC.error.mustlogin") unless (defined $up); - $bmlerr->("$SC.error.noauth"); + my $ent = LJ::Entry->new_from_item_hash( $item ) + or die "Unable to create entry object.\n"; + unless ( $ent->visible_to( $up ) ) { + $bmlerr->( "$SC.error.mustlogin" ) unless defined $up; + $bmlerr->( "$SC.error.noauth" ); return undef; } diff -r be43f2100215 -r 043f9a944c46 cgi-bin/LJ/User.pm --- a/cgi-bin/LJ/User.pm Thu Nov 26 05:06:52 2009 +0000 +++ b/cgi-bin/LJ/User.pm Thu Nov 26 05:17:10 2009 +0000 @@ -60,7 +60,7 @@ use LJ::S2Theme; ### 13. Community-Related Functions and Authas ### 14. Adult Content Functions ### 15. Email-Related Functions -### 16. Entry-Related Functions +### 16. (( there is no section 16 )) ### 17. Interest-Related Functions ### 18. Jabber-Related Functions ### 19. OpenID and Identity Functions @@ -7680,72 +7680,6 @@ sub set_email { ######################################################################## -### 16. Entry-Related Functions - -# <LJFUNC> -# name: LJ::can_view -# des: Checks to see if the remote user can view a given journal entry. -# <b>Note:</b> This is meant for use on single entries at a time, -# not for calling many times on every entry in a journal. -# returns: boolean; 1 if remote user can see item -# args: remote, item -# des-item: Hashref from the 'log' table. -# </LJFUNC> -sub can_view -{ - -# TODO: fold this into LJ::Entry->visible_to :( - - &nodb; - my ( $remote, $item ) = @_; - - # public is okay - return 1 if $item->{'security'} eq "public"; - - # must be logged in otherwise - return 0 unless $remote; - - my $userid = int($item->{'ownerid'} || $item->{'journalid'}); - my $remoteid = int( $remote->userid ); - - # owners can always see their own. - return 1 if $userid == $remoteid; - - # should be 'usemask' or 'private' security from here out, otherwise - # assume it's something new and return 0 - return 0 unless $item->{security} eq "usemask" || $item->{security} eq "private"; - - return 0 unless $remote->is_individual; - - # this far down we have to load the user - my $u = LJ::want_user( $userid ) or return 0; - - if ( $item->{security} eq "private" ) { - # other people can't read private on personal journals - return 0 if $u->is_individual; - - # but community administrators can read private entries on communities - return 1 if $u->is_community && $remote->can_manage( $u ); - - # private entry on a community; we're not allowed to see this - return 0; - } - - if ( $item->{security} eq "usemask" ) { - # 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 - } - - return 0; -} - - -######################################################################## ### 17. Interest-Related Functions sub interest_string_to_list { diff -r be43f2100215 -r 043f9a944c46 htdocs/edittags.bml --- a/htdocs/edittags.bml Thu Nov 26 05:06:52 2009 +0000 +++ b/htdocs/edittags.bml Thu Nov 26 05:17:10 2009 +0000 @@ -33,8 +33,11 @@ body<= my $logrow = LJ::get_log2_row($u, $jitemid); return $err->($ML{'.invalid.entry'}) unless $logrow; return $err->($ML{'.invalid.entry'}) unless $logrow->{anum} == $anum; - return $err->($ML{'.invalid.notauthorized'}) - unless LJ::can_view($remote, $logrow); + + my $ent = LJ::Entry->new_from_item_hash( $logrow ) + or die "Unable to create entry object.\n"; + return $err->( $ML{'.invalid.notauthorized'} ) + unless $ent->visible_to( $remote ); # poster must be visible too if ($logrow->{posterid} != $u->{userid}) { --------------------------------------------------------------------------------