Changesets can be listed by changeset number.
The Git repository is here.
- Revision:
- 149
- Log:
Empty forums were having their "empty" page returned with a status
code of 404, producing problems in O2. It might be an attempt to
stop cache-related problems but there are more elegant ways to do
that built into HTTP! Will have to keep an eye on this for a while
but, as is so often said - "seems to work fine" now.
- Author:
- adh
- Date:
- Wed Nov 22 22:29:17 +0000 2006
- Size:
- 3320 Bytes
1 | class ForumController < ApplicationController |
2 | helper :forum |
3 | #caches_page :index, :forum |
4 | |
5 | # Use HubSsoLib for permissions management, as a layer on top of |
6 | # the provision within RForum. |
7 | |
8 | @@hubssolib_permissions = HubSsoLib::Permissions.new({ |
9 | :new => [ :admin, :webmaster ], |
10 | :edit => [ :admin, :webmaster ], |
11 | :move => [ :admin, :webmaster ] |
12 | }) |
13 | |
14 | def ForumController.hubssolib_permissions |
15 | @@hubssolib_permissions |
16 | end |
17 | |
18 | # Display the list of topics in a forum. |
19 | def forum |
20 | begin |
21 | @forum = Forum.find(@params['id']) |
22 | return if redirect_if_site_doesnt_match |
23 | rescue ActiveRecord::RecordNotFound |
24 | render_text "Forum not found", 404 |
25 | return |
26 | end |
27 | |
28 | @title = @forum.name |
29 | |
30 | @page = @params['page'].to_i |
31 | @page = 1 if @page == 0 |
32 | @topics_per_page = RForum::CONFIG[:topics_per_page] |
33 | range = ((@page - 1) * @topics_per_page)..(@page * @topics_per_page) |
34 | tag = @params['tag'] |
35 | @topics = @forum.get_topics_for_list(range, tag, @user.can_view_deleted_posts?) |
36 | if @topics.size < @topics_per_page |
37 | @last_page = true |
38 | end |
39 | |
40 | if @topics.empty? |
41 | render 'forum/forum', 200 |
42 | end |
43 | |
44 | if not @user.guest? |
45 | topic_read_times = @user.topic_read_times |
46 | |
47 | @topics.each do |topic| |
48 | topic['last_read_time'] = topic_read_times[topic.id] |
49 | end |
50 | end |
51 | end |
52 | |
53 | # List all forums. |
54 | def list |
55 | @title = l(:forum_list_title) |
56 | |
57 | @forums.each{|f| f['last_post'] = f.get_last_post} |
58 | end |
59 | |
60 | def index |
61 | redirect_to :controller => 'forum', :action => 'list' |
62 | end |
63 | |
64 | def search |
65 | @title = l(:search_title) |
66 | |
67 | if @params['forums'] |
68 | @selected_forums = @params['forums'].collect {|id| id.to_i} |
69 | else |
70 | @selected_forums = (@forums.collect {|f| f.id}) |
71 | end |
72 | |
73 | if @params['query'] |
74 | @query = @params['query'] |
75 | @page_params = {'query' => @query} |
76 | @page = @params['page'].to_i |
77 | @page = 1 if @page == 0 |
78 | @posts_per_page = RForum::CONFIG[:search_results_per_page] |
79 | |
80 | @results = Post.search(@query, @selected_forums, @posts_per_page, (@page - 1) * @posts_per_page) |
81 | |
82 | if @results.size < @posts_per_page |
83 | @last_page = true |
84 | end |
85 | end |
86 | |
87 | end |
88 | |
89 | def new |
90 | raise RForum::SecurityError unless @user.admin? |
91 | @title = l(:create_forum_title) |
92 | @forum = Forum.new(@params['forum']) |
93 | |
94 | if @params['save'] |
95 | @forum.save |
96 | redirect_to :action => 'list' |
97 | else |
98 | render_action 'edit' |
99 | end |
100 | end |
101 | |
102 | def edit |
103 | raise RForum::SecurityError unless @user.admin? |
104 | @title = l(:create_forum_title) |
105 | |
106 | @forum = Forum.find(@params['id']) |
107 | |
108 | if @params['save'] |
109 | Forum.update(@params['id'], @params['forum']) |
110 | redirect_to :action => 'list' |
111 | elsif @params['delete'] |
112 | # TODO: javascript confirmation is not sufficient because this operation |
113 | # is pretty dangerous |
114 | Forum.find(@params['id']).destroy |
115 | redirect_to :action => 'list' |
116 | end |
117 | end |
118 | |
119 | def move |
120 | raise RForum::SecurityError unless @user.admin? |
121 | |
122 | @forum = Forum.find(@params['id']) |
123 | |
124 | if @params['direction'] == 'up' |
125 | @forum.move_higher |
126 | elsif @params['direction'] == 'down' |
127 | @forum.move_lower |
128 | end |
129 | |
130 | redirect_to :action => 'list' |
131 | end |
132 | end |