Changeset 14

Show
Ignore:
Timestamp:
02/20/07 23:43:38 (3 years ago)
Author:
eevee
Message:

Split forum flags into flags and accessibility; accessibility now controls, well, how accessible the forum is by default. 'Locked' means no new threads; 'archive' means no new threads or posts; 'hidden' means no new stuff and it's invisible. Permissions of 'override_forum_*' will (eventually) allow a user to bypass these restrictions per-forum.
This is only partially implemented; I will finish it up tomorrow or so.
Also started migrating from database slurping to iterators, one at a time. The changes are more related than they seem; I'm implementing some of the forum flags as extra search() calls, and if I slurp the results of the first search() immediately then I can't do another. Easiest way around this is to just make it an iterator and alter the templates slightly.
I also plan to do some general forum template refactoring, but that will come after this stuff actually works correctly.

Location:
veekun
Files:
7 modified

Legend:

Unmodified
Added
Removed
  • veekun/lib/Vee/Controller/Forum.pm

    r6 r14  
    4848    $s->{extra_css } = 'forum'; 
    4949 
    50     $s->{announcements} = [ $c->model('DBIC::Threads')->search_announcements ]; 
    51     $s->{forums       } = [ $c->model('DBIC::Forums')->search(undef, { prefetch => { lastpost => 'user' } }) ]; 
     50    $s->{announcements} = $c->model('DBIC::Threads')->search_announcements; 
     51    $s->{forums}        = $c->model('DBIC::Forums')->search(undef, { prefetch => { lastpost => 'user' } }); 
     52 
     53    $s->{can_see}       = sub { Vee::Authorization::has_permission($c, 'override_forum_hidden', shift) }; 
    5254 
    5355    $s->{template} = 'forum/index.tt'; 
     
    7678    $s->{crumbs}      = [ '<a href="/forum">Forum Index</a>', '<a href="/forum/'.$forum->id.'">'.$forum->name.'</a>' ]; 
    7779 
    78     $s->{announcements} = [ $c->model('DBIC::Threads')->search_announcements ]; 
     80    $s->{announcements} = $c->model('DBIC::Threads')->search_announcements; 
    7981    $s->{forum}         = $forum; 
    80     $s->{threads}       = [ $forum->search_related('threads', \ 'NOT FIND_IN_SET("deleted", me.flags)', { 
     82    $s->{threads}       = $forum->search_related('threads', undef, { 
    8183        order_by => 'FIND_IN_SET("sticky", me.flags) > 0 DESC, lastpost.time DESC', 
    8284        prefetch => { firstpost => 'user', lastpost => 'user' }, 
    8385        offset => $skip, 
    8486        rows => $perpage, 
    85     } ) ]; 
     87    } ); 
     88    # ugly but for now I don't know the best way to clean it up 
     89    $s->{threads} = $s->{threads}->search(\ 'NOT FIND_IN_SET("deleted", me.flags)') unless Vee::Authorization::has_permission($c, 'override_thread_deleted', $forum->id); 
    8690 
    8791    $s->{template} = 'forum/view.tt'; 
     
    106110        or $c->vee_abort('There is no thread with id ', $id, '.'); 
    107111    $thread->hitct( $thread->hitct + 1 ); $thread->update; 
     112 
     113    if ($thread->flags =~ /deleted/ and not Vee::Authorization::has_permission($c, 'override_thread_deleted', $thread->forum->id)) { 
     114        $c->vee_abort('This thread has been deleted.'); 
     115    } 
    108116 
    109117    my $filter = $c->req->params->{filter}; 
  • veekun/lib/Vee/Schema/Forums.pm

    r1 r14  
    1010__PACKAGE__->load_components("PK::Auto", "Core"); 
    1111__PACKAGE__->table("forums"); 
    12 __PACKAGE__->add_columns("id", "name", "lastpostid", "threadct", "postct", "flags", "blurb"); 
     12__PACKAGE__->add_columns("id", "name", "lastpostid", "threadct", "postct", "flags", "accessibility", "blurb"); 
    1313__PACKAGE__->set_primary_key("id"); 
    1414__PACKAGE__->add_unique_constraint(["id"], undef); 
  • veekun/lib/Vee/Utils/Forum.pm

    r1 r14  
    3333} 
    3434 
    35 =head2 can_post 
     35=head2 can_thread 
    3636 
    3737Returns true if the current user can create threads in the given forum, false 
  • veekun/script/base.sql

    r9 r14  
    5959  threadct int(10) unsigned NOT NULL default '0', 
    6060  postct int(10) unsigned NOT NULL default '0', 
    61   flags set('locked','readonly','header','hidden') NOT NULL default '', 
     61  flags set('header') default NULL, 
     62  accessibility enum('normal','locked','archive','hidden') NOT NULL default 'normal', 
    6263  blurb varchar(255) NOT NULL default '', 
    6364  PRIMARY KEY  (id) 
  • veekun/templates/forum/common.tt

    r13 r14  
    6060 
    6161[% BLOCK show_announcements %][%# announcements %] 
    62 [% RETURN UNLESS announcements AND announcements.size %] 
     62[% RETURN UNLESS announcements %] 
    6363<h2>Announcements</h2> 
    6464[% INCLUDE threads_start -%] 
    65 [% FOREACH t IN announcements %] 
     65[% WHILE (t = announcements.next) %] 
    6666[%     INCLUDE threads_each thread=t show_forum=1 %] 
    6767[% END %] 
     
    179179[%#     last_thread = sql.thread_info(last_post.threadid) -%] 
    180180<tr><td class="forum-icon"> 
    181 <!-- TODO: something should go here. --> 
     181[% UNLESS forum.accessibility == 'normal' %]<img src="/images/icons/[% forum.accessibility %].png" alt="[% forum.accessibility %]" title="[% forum.accessibility %]"/>[% END %] 
    182182</td><td class="forum-name"> 
    183183<a href="/forum/[% forum.id %]" class="forum-link"> 
    184  <div class="forum-title"> 
    185 [%     FOREACH flag IN ForumFlagArray %] 
    186 [%         NEXT UNLESS forum.flags.match(flag.name) %] 
    187   <img src="/images/icons/[% flag.name %].png" alt="[% flag.name %]" title="[% flag.name %]: [% flag.blurb %]" class="forum-icon"/> 
    188 [%     END %] 
    189 [%     forum.name %] 
    190  </div> 
     184 <div class="forum-title">[% forum.name %]</div> 
    191185[%     IF forum.blurb %] 
    192186 <div class="forum-info">[% forum.blurb %]</div> 
  • veekun/templates/forum/index.tt

    r1 r14  
    1010[% forum_flags %] 
    1111[% INCLUDE forums_start %] 
    12 [% FOREACH f IN forums %] 
    13 [%     NEXT UNLESS f %] 
     12[% WHILE (f = forums.next) %] 
     13[%     NEXT IF f.accessibility == 'hidden' AND NOT can_see(f.id) %] 
    1414[%     IF f.flags.match('header') %] 
    15 [%         INCLUDE forums_header title=f.name blurb=f.blurb %] 
     15[%         prev_header = f %] 
    1616[%     ELSE %] 
     17[%         INCLUDE forums_header title=prev_header.name blurb=prev_header.blurb IF prev_header %] 
    1718[%         INCLUDE forums_each forum=f %] 
    1819[%     END %] 
  • veekun/templates/forum/view.tt

    r5 r14  
    1313[% forum_flags %] 
    1414[% INCLUDE threads_start %] 
    15 [% FOREACH t IN threads %] 
     15[% WHILE (t = threads.next) %] 
    1616[%     INCLUDE threads_each thread=t %] 
    1717[% END %]