X-Git-Url: https://ruin.nu/git/?a=blobdiff_plain;f=lib%2FNDWeb%2FController%2FForum.pm;h=2de3ea82e105d286704caa3bbdc4be8ee64b1b83;hb=3586132bdff6f0f1effdc21c1837597f9d533842;hp=f4fa3c0abd74dd36411e6db572161b3eaf50476c;hpb=b00d7995de3f6eb15560b5ae9dac75f12e248b13;p=ndwebbie.git diff --git a/lib/NDWeb/Controller/Forum.pm b/lib/NDWeb/Controller/Forum.pm index f4fa3c0..2de3ea8 100644 --- a/lib/NDWeb/Controller/Forum.pm +++ b/lib/NDWeb/Controller/Forum.pm @@ -159,6 +159,9 @@ sub board : Local { $c->forward('findBoard'); $board = $c->stash->{board}; + if ( !defined $board->{fbid}){ + $c->detach('/default'); + } my $threads = $dbh->prepare(q{SELECT ft.ftid,u.username,ft.subject ,count(NULLIF(COALESCE(fp.time > ftv.time,TRUE),FALSE)) AS unread,count(fp.fpid) AS posts @@ -180,34 +183,15 @@ sub board : Local { while (my $thread = $threads->fetchrow_hashref){ push @threads,$thread; } - $c->stash(threads => \@threads); - if ($board->{moderate}){ - my $categories = $dbh->prepare(q{SELECT fcid,category FROM forum_categories ORDER BY fcid}); - my $boards = $dbh->prepare(q{SELECT fb.fbid,fb.board, bool_or(fa.post) AS post - FROM forum_boards fb NATURAL JOIN forum_access fa - WHERE fb.fcid = $1 AND - gid IN (SELECT groups($2)) - GROUP BY fb.fbid,fb.board - ORDER BY fb.fbid - }); - $categories->execute; - my @categories; - while (my $category = $categories->fetchrow_hashref){ - $boards->execute($category->{fcid},$c->stash->{UID}); - - my @boards; - while (my $b = $boards->fetchrow_hashref){ - next if (not $b->{post} or $b->{fbid} == $board->{fbid}); - push @boards,$b; - } - $category->{boards} = \@boards; - push @categories,$category if @boards; - } - $c->stash(categories => \@categories); + if ( !(defined $board->{post}) && @threads == 0){ + $c->acl_access_denied('test',$c->action,'No access to board') } -} + $c->stash(threads => \@threads); + $c->forward('listModeratorBoards', [$board->{fbid}]) if $board->{moderate}; + +} sub thread : Local { my ( $self, $c, $thread ) = @_; @@ -215,16 +199,20 @@ sub thread : Local { $c->forward('findThread'); unless ($c->stash->{thread}){ - $c->stash(template => 'access_denied.tt2'); + $c->stash(template => 'default.tt2'); + $c->res->status(404); return; } my $query = $dbh->prepare(q{SELECT uid,username FROM users u JOIN forum_priv_access fta USING (uid) WHERE fta.ftid = $1}); $query->execute($thread); $c->stash(access => $query->fetchall_arrayref({}) ); - $c->forward('findUsers') if $c->stash->{thread}->{moderate}; $c->forward('findPosts'); $c->forward('markThreadAsRead') if $c->user_exists; + if ($c->stash->{thread}->{moderate}) { + $c->forward('findUsers'); + $c->forward('listModeratorBoards', [$c->stash->{thread}->{fbid}]); + } } sub findPosts :Private { @@ -535,6 +523,35 @@ sub insertPost : Private { $insert->execute($thread,html_escape($c->req->param('message')),$c->stash->{UID}); } +sub listModeratorBoards : Private { + my ( $self, $c, $fbid ) = @_; + my $dbh = $c->model; + + my $categories = $dbh->prepare(q{SELECT fcid,category FROM forum_categories ORDER BY fcid}); + my $boards = $dbh->prepare(q{SELECT fb.fbid,fb.board, bool_or(fa.post) AS post + FROM forum_boards fb NATURAL JOIN forum_access fa + WHERE fb.fcid = $1 + AND gid IN (SELECT groups($2)) + AND moderate + GROUP BY fb.fbid,fb.board + ORDER BY fb.fbid + }); + $categories->execute; + my @categories; + while (my $category = $categories->fetchrow_hashref){ + $boards->execute($category->{fcid},$c->stash->{UID}); + + my @boards; + while (my $b = $boards->fetchrow_hashref){ + next if ($b->{fbid} == $fbid); + push @boards,$b; + } + $category->{boards} = \@boards; + push @categories,$category if @boards; + } + $c->stash(categories => \@categories); +} + =head1 AUTHOR Michael Andreen (harv@ruin.nu)