Changesets can be listed by changeset number.
The Git repository is here.
- Revision:
- 471
- Log:
Add 'quick and dirty' blacklist mechanism
- Author:
- rool
- Date:
- Sat Jan 26 09:02:22 +0000 2019
- Size:
- 3996 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 | per_page = [params[:posts_per_page].to_i, 25].max |
40 | @post_pages, @posts = paginate(:posts, :per_page => per_page, :order => 'posts.created_at', :include => :user, :conditions => ['posts.topic_id = ?', params[:id]]) |
41 | @voices = @posts.map(&:user) ; @voices.uniq! |
42 | @post = Post.new |
43 | end |
44 | format.xml do |
45 | render :xml => @topic.to_xml |
46 | end |
47 | format.rss do |
48 | @posts = @topic.posts.find(:all, :order => 'created_at desc', :limit => 50) |
49 | render :action => 'show.rxml', :layout => false |
50 | end |
51 | end |
52 | end |
53 | |
54 | def create |
55 | # this is icky - move the topic/first post workings into the topic model? |
56 | Topic.transaction do |
57 | @topic = @forum.topics.build(params[:topic]) |
58 | assign_protected |
59 | @topic.save! |
60 | @post = @topic.posts.build(params[:topic]) |
61 | @post.user = current_user |
62 | @post.save! |
63 | end |
64 | respond_to do |format| |
65 | format.html { redirect_to topic_path(@forum, @topic) } |
66 | format.xml { head :created, :location => formatted_topic_url(:forum_id => @forum, :id => @topic, :format => :xml) } |
67 | end |
68 | rescue ActiveRecord::RecordInvalid |
69 | flash[:error] = "Your topic's first post was empty, or contained prohibited words" |
70 | respond_to do |format| |
71 | format.html { redirect_to forum_path(@forum) } |
72 | format.xml { render :xml => @post.errors.to_xml, :status => 400 } |
73 | end |
74 | end |
75 | |
76 | def update |
77 | @topic.attributes = params[:topic] |
78 | assign_protected |
79 | @topic.save! |
80 | respond_to do |format| |
81 | format.html { redirect_to topic_path(@forum, @topic) } |
82 | format.xml { head 200 } |
83 | end |
84 | end |
85 | |
86 | def destroy |
87 | @topic.destroy |
88 | flash[:notice] = "Topic '#{CGI::escapeHTML @topic.title}' was deleted." |
89 | respond_to do |format| |
90 | format.html { redirect_to forum_path(@forum) } |
91 | format.xml { head 200 } |
92 | end |
93 | end |
94 | |
95 | protected |
96 | def assign_protected |
97 | @topic.user = current_user if @topic.new_record? |
98 | # admins and moderators can sticky and lock topics |
99 | return unless admin? or current_user.moderator_of?(@topic.forum) |
100 | @topic.sticky, @topic.locked = params[:topic][:sticky], params[:topic][:locked] |
101 | # only admins can move |
102 | return unless admin? |
103 | @topic.forum_id = params[:topic][:forum_id] if params[:topic][:forum_id] |
104 | end |
105 | |
106 | def find_forum_and_topic |
107 | @forum = Forum.find(params[:forum_id]) |
108 | @topic = @forum.topics.find(params[:id]) if params[:id] |
109 | end |
110 | |
111 | def authorized? |
112 | %w(new create).include?(action_name) || @topic.editable_by?(current_user) |
113 | end |
114 | end |