Changesets can be listed by changeset number.
The Git repository is here.
- Revision:
- 178
- Log:
Hub integration of Beast forum. Completed styling for RISC OS Open site.
Removed reliance on JavaScript. Added Textile hints to various views.
Added bespoke utility code used to port over RForum data for posterity;
note the rather large bug that it ignores the deleted flag on RForum
data.Some amount of testing carried out on Firefox, Opera and Netsurf. Looks
OK so far, but there are definitely some aesthetic kinks to work out
still and doubtless some operational bugs will surface once it goes
live and is subjected to more intensive real world use.
- Author:
- rool
- Date:
- Mon Mar 12 00:19:40 +0000 2007
- Size:
- 3666 Bytes
1 | class TopicsController < ApplicationController |
2 | before_filter :find_forum_and_topic, :except => :index |
3 | |
4 | @@hubssolib_permissions = HubSsoLib::Permissions.new({ |
5 | :new => [ :admin, :webmaster, :privileged, :normal ], |
6 | :create => [ :admin, :webmaster, :privileged, :normal ], |
7 | :edit => [ :admin, :webmaster ], |
8 | :update => [ :admin, :webmaster ], |
9 | :destroy => [ :admin, :webmaster ], |
10 | }) |
11 | |
12 | def TopicsController.hubssolib_permissions |
13 | @@hubssolib_permissions |
14 | end |
15 | |
16 | def index |
17 | respond_to do |format| |
18 | format.html { redirect_to forum_path(params[:forum_id]) } |
19 | format.xml do |
20 | @topics = Topic.find_all_by_forum_id(params[:forum_id], :order => 'sticky desc, replied_at desc', :limit => 25) |
21 | render :xml => @topics.to_xml |
22 | end |
23 | end |
24 | end |
25 | |
26 | def new |
27 | @topic = Topic.new |
28 | end |
29 | |
30 | def show |
31 | respond_to do |format| |
32 | format.html do |
33 | # see notes in application.rb on how this works |
34 | update_last_seen_at |
35 | # keep track of when we last viewed this topic for activity indicators |
36 | (session[:topics] ||= {})[@topic.id] = Time.now.utc if logged_in? |
37 | # authors of topics don't get counted towards total hits |
38 | @topic.hit! unless logged_in? and @topic.user == current_user |
39 | @post_pages, @posts = paginate(:posts, :per_page => 25, :order => 'posts.created_at', :include => :user, :conditions => ['posts.topic_id = ?', params[:id]]) |
40 | @voices = @posts.map(&:user) ; @voices.uniq! |
41 | @post = Post.new |
42 | end |
43 | format.xml do |
44 | render :xml => @topic.to_xml |
45 | end |
46 | format.rss do |
47 | @posts = @topic.posts.find(:all, :order => 'created_at desc', :limit => 25) |
48 | render :action => 'show.rxml', :layout => false |
49 | end |
50 | end |
51 | end |
52 | |
53 | def create |
54 | # this is icky - move the topic/first post workings into the topic model? |
55 | Topic.transaction do |
56 | @topic = @forum.topics.build(params[:topic]) |
57 | assign_protected |
58 | @topic.save! |
59 | @post = @topic.posts.build(params[:topic]) |
60 | @post.user = current_user |
61 | @post.save! |
62 | end |
63 | respond_to do |format| |
64 | format.html { redirect_to topic_path(@forum, @topic) } |
65 | format.xml { head :created, :location => formatted_topic_url(:forum_id => @forum, :id => @topic, :format => :xml) } |
66 | end |
67 | end |
68 | |
69 | def update |
70 | @topic.attributes = params[:topic] |
71 | assign_protected |
72 | @topic.save! |
73 | respond_to do |format| |
74 | format.html { redirect_to topic_path(@forum, @topic) } |
75 | format.xml { head 200 } |
76 | end |
77 | end |
78 | |
79 | def destroy |
80 | @topic.destroy |
81 | flash[:notice] = "Topic '#{CGI::escapeHTML @topic.title}' was deleted." |
82 | respond_to do |format| |
83 | format.html { redirect_to forum_path(@forum) } |
84 | format.xml { head 200 } |
85 | end |
86 | end |
87 | |
88 | protected |
89 | def assign_protected |
90 | @topic.user = current_user if @topic.new_record? |
91 | # admins and moderators can sticky and lock topics |
92 | return unless admin? or current_user.moderator_of?(@topic.forum) |
93 | @topic.sticky, @topic.locked = params[:topic][:sticky], params[:topic][:locked] |
94 | # only admins can move |
95 | return unless admin? |
96 | @topic.forum_id = params[:topic][:forum_id] if params[:topic][:forum_id] |
97 | end |
98 | |
99 | def find_forum_and_topic |
100 | @forum = Forum.find(params[:forum_id]) |
101 | @topic = @forum.topics.find(params[:id]) if params[:id] |
102 | end |
103 | |
104 | def authorized? |
105 | %w(new create).include?(action_name) || @topic.editable_by?(current_user) |
106 | end |
107 | end |