implements #2658: private forum topics
This commit is contained in:
@@ -55,6 +55,11 @@ div#c-forum-topics {
|
|||||||
span.locked-topic {
|
span.locked-topic {
|
||||||
color: #666;
|
color: #666;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
span.level-topic {
|
||||||
|
color: #f66;
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
|
|
||||||
tr.forum-topic-row td:last-child {
|
tr.forum-topic-row td:last-child {
|
||||||
white-space: nowrap;
|
white-space: nowrap;
|
||||||
|
|||||||
@@ -3,6 +3,8 @@ class ForumTopicsController < ApplicationController
|
|||||||
before_filter :member_only, :except => [:index, :show]
|
before_filter :member_only, :except => [:index, :show]
|
||||||
before_filter :moderator_only, :only => [:new_merge, :create_merge]
|
before_filter :moderator_only, :only => [:new_merge, :create_merge]
|
||||||
before_filter :normalize_search, :only => :index
|
before_filter :normalize_search, :only => :index
|
||||||
|
before_filter :load_topic, :only => [:edit, :show, :update, :destroy, :undelete, :new_merge, :create_merge, :subscribe, :unsubscribe]
|
||||||
|
before_filter :check_min_level, :only => [:show, :edit, :update, :new_merge, :create_merge, :destroy, :undelete, :subscribe, :unsubscribe]
|
||||||
|
|
||||||
def new
|
def new
|
||||||
@forum_topic = ForumTopic.new
|
@forum_topic = ForumTopic.new
|
||||||
@@ -11,7 +13,6 @@ class ForumTopicsController < ApplicationController
|
|||||||
end
|
end
|
||||||
|
|
||||||
def edit
|
def edit
|
||||||
@forum_topic = ForumTopic.find(params[:id])
|
|
||||||
check_privilege(@forum_topic)
|
check_privilege(@forum_topic)
|
||||||
respond_with(@forum_topic)
|
respond_with(@forum_topic)
|
||||||
end
|
end
|
||||||
@@ -27,7 +28,6 @@ class ForumTopicsController < ApplicationController
|
|||||||
end
|
end
|
||||||
|
|
||||||
def show
|
def show
|
||||||
@forum_topic = ForumTopic.find(params[:id])
|
|
||||||
unless CurrentUser.user.is_anonymous?
|
unless CurrentUser.user.is_anonymous?
|
||||||
@forum_topic.mark_as_read!(CurrentUser.user)
|
@forum_topic.mark_as_read!(CurrentUser.user)
|
||||||
end
|
end
|
||||||
@@ -42,14 +42,12 @@ class ForumTopicsController < ApplicationController
|
|||||||
end
|
end
|
||||||
|
|
||||||
def update
|
def update
|
||||||
@forum_topic = ForumTopic.find(params[:id])
|
|
||||||
check_privilege(@forum_topic)
|
check_privilege(@forum_topic)
|
||||||
@forum_topic.update_attributes(params[:forum_topic], :as => CurrentUser.role)
|
@forum_topic.update_attributes(params[:forum_topic], :as => CurrentUser.role)
|
||||||
respond_with(@forum_topic)
|
respond_with(@forum_topic)
|
||||||
end
|
end
|
||||||
|
|
||||||
def destroy
|
def destroy
|
||||||
@forum_topic = ForumTopic.find(params[:id])
|
|
||||||
check_privilege(@forum_topic)
|
check_privilege(@forum_topic)
|
||||||
@forum_topic.delete!
|
@forum_topic.delete!
|
||||||
flash[:notice] = "Topic deleted"
|
flash[:notice] = "Topic deleted"
|
||||||
@@ -57,7 +55,6 @@ class ForumTopicsController < ApplicationController
|
|||||||
end
|
end
|
||||||
|
|
||||||
def undelete
|
def undelete
|
||||||
@forum_topic = ForumTopic.find(params[:id])
|
|
||||||
check_privilege(@forum_topic)
|
check_privilege(@forum_topic)
|
||||||
@forum_topic.undelete!
|
@forum_topic.undelete!
|
||||||
flash[:notice] = "Topic undeleted"
|
flash[:notice] = "Topic undeleted"
|
||||||
@@ -71,18 +68,15 @@ class ForumTopicsController < ApplicationController
|
|||||||
end
|
end
|
||||||
|
|
||||||
def new_merge
|
def new_merge
|
||||||
@forum_topic = ForumTopic.find(params[:id])
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def create_merge
|
def create_merge
|
||||||
@forum_topic = ForumTopic.find(params[:id])
|
|
||||||
@merged_topic = ForumTopic.find(params[:merged_id])
|
@merged_topic = ForumTopic.find(params[:merged_id])
|
||||||
@forum_topic.merge(@merged_topic)
|
@forum_topic.merge(@merged_topic)
|
||||||
redirect_to forum_topic_path(@merged_topic)
|
redirect_to forum_topic_path(@merged_topic)
|
||||||
end
|
end
|
||||||
|
|
||||||
def subscribe
|
def subscribe
|
||||||
@forum_topic = ForumTopic.find(params[:id])
|
|
||||||
subscription = ForumSubscription.where(:forum_topic_id => @forum_topic.id, :user_id => CurrentUser.user.id).first
|
subscription = ForumSubscription.where(:forum_topic_id => @forum_topic.id, :user_id => CurrentUser.user.id).first
|
||||||
unless subscription
|
unless subscription
|
||||||
ForumSubscription.create(:forum_topic_id => @forum_topic.id, :user_id => CurrentUser.user.id, :last_read_at => @forum_topic.updated_at)
|
ForumSubscription.create(:forum_topic_id => @forum_topic.id, :user_id => CurrentUser.user.id, :last_read_at => @forum_topic.updated_at)
|
||||||
@@ -91,7 +85,6 @@ class ForumTopicsController < ApplicationController
|
|||||||
end
|
end
|
||||||
|
|
||||||
def unsubscribe
|
def unsubscribe
|
||||||
@forum_topic = ForumTopic.find(params[:id])
|
|
||||||
subscription = ForumSubscription.where(:forum_topic_id => @forum_topic.id, :user_id => CurrentUser.user.id).first
|
subscription = ForumSubscription.where(:forum_topic_id => @forum_topic.id, :user_id => CurrentUser.user.id).first
|
||||||
if subscription
|
if subscription
|
||||||
subscription.destroy
|
subscription.destroy
|
||||||
@@ -121,4 +114,29 @@ private
|
|||||||
raise User::PrivilegeError
|
raise User::PrivilegeError
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def load_topic
|
||||||
|
@forum_topic = ForumTopic.find(params[:id])
|
||||||
|
end
|
||||||
|
|
||||||
|
def check_min_level
|
||||||
|
if CurrentUser.user.level < @forum_topic.min_level
|
||||||
|
respond_with(@forum_topic) do |fmt|
|
||||||
|
fmt.html do
|
||||||
|
flash[:notice] = "Access denied"
|
||||||
|
redirect_to forum_topics_path
|
||||||
|
end
|
||||||
|
|
||||||
|
fmt.json do
|
||||||
|
render :nothing => true, :status => 403
|
||||||
|
end
|
||||||
|
|
||||||
|
fmt.xml do
|
||||||
|
render :nothing => true, :status => 403
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ class ForumTopic < ActiveRecord::Base
|
|||||||
}
|
}
|
||||||
|
|
||||||
attr_accessible :title, :original_post_attributes, :category_id, :as => [:member, :builder, :gold, :platinum, :janitor, :moderator, :admin, :default]
|
attr_accessible :title, :original_post_attributes, :category_id, :as => [:member, :builder, :gold, :platinum, :janitor, :moderator, :admin, :default]
|
||||||
attr_accessible :is_sticky, :is_locked, :is_deleted, :as => [:admin, :moderator]
|
attr_accessible :is_sticky, :is_locked, :is_deleted, :min_level, :as => [:admin, :moderator]
|
||||||
belongs_to :creator, :class_name => "User"
|
belongs_to :creator, :class_name => "User"
|
||||||
belongs_to :updater, :class_name => "User"
|
belongs_to :updater, :class_name => "User"
|
||||||
has_many :posts, lambda {order("forum_posts.id asc")}, :class_name => "ForumPost", :foreign_key => "topic_id", :dependent => :destroy
|
has_many :posts, lambda {order("forum_posts.id asc")}, :class_name => "ForumPost", :foreign_key => "topic_id", :dependent => :destroy
|
||||||
|
|||||||
@@ -306,6 +306,37 @@ class User < ActiveRecord::Base
|
|||||||
"Admin" => Levels::ADMIN
|
"Admin" => Levels::ADMIN
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def level_string(value)
|
||||||
|
case value
|
||||||
|
when Levels::BLOCKED
|
||||||
|
"Banned"
|
||||||
|
|
||||||
|
when Levels::MEMBER
|
||||||
|
"Member"
|
||||||
|
|
||||||
|
when Levels::BUILDER
|
||||||
|
"Builder"
|
||||||
|
|
||||||
|
when Levels::GOLD
|
||||||
|
"Gold"
|
||||||
|
|
||||||
|
when Levels::PLATINUM
|
||||||
|
"Platinum"
|
||||||
|
|
||||||
|
when Levels::JANITOR
|
||||||
|
"Janitor"
|
||||||
|
|
||||||
|
when Levels::MODERATOR
|
||||||
|
"Moderator"
|
||||||
|
|
||||||
|
when Levels::ADMIN
|
||||||
|
"Admin"
|
||||||
|
|
||||||
|
else
|
||||||
|
""
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def promote_to!(new_level, options = {})
|
def promote_to!(new_level, options = {})
|
||||||
@@ -356,34 +387,7 @@ class User < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
|
|
||||||
def level_string(value = nil)
|
def level_string(value = nil)
|
||||||
case (value || level)
|
User.level_string(value || level)
|
||||||
when Levels::BLOCKED
|
|
||||||
"Banned"
|
|
||||||
|
|
||||||
when Levels::MEMBER
|
|
||||||
"Member"
|
|
||||||
|
|
||||||
when Levels::BUILDER
|
|
||||||
"Builder"
|
|
||||||
|
|
||||||
when Levels::GOLD
|
|
||||||
"Gold"
|
|
||||||
|
|
||||||
when Levels::PLATINUM
|
|
||||||
"Platinum"
|
|
||||||
|
|
||||||
when Levels::JANITOR
|
|
||||||
"Janitor"
|
|
||||||
|
|
||||||
when Levels::MODERATOR
|
|
||||||
"Moderator"
|
|
||||||
|
|
||||||
when Levels::ADMIN
|
|
||||||
"Admin"
|
|
||||||
|
|
||||||
else
|
|
||||||
""
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def is_anonymous?
|
def is_anonymous?
|
||||||
|
|||||||
@@ -22,6 +22,10 @@
|
|||||||
<%= f.input :is_locked %>
|
<%= f.input :is_locked %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
|
<% if CurrentUser.is_builder? %>
|
||||||
|
<%= f.input :min_level, :as => :select, :collection => User.level_hash.to_a %>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
<%= f.button :submit, "Submit", :data => { :disable_with => "Submitting..." } %>
|
<%= f.button :submit, "Submit", :data => { :disable_with => "Submitting..." } %>
|
||||||
<%= dtext_preview_button "forum_post", "body", :input_id => "forum_post_body_for_#{forum_topic.original_post.id}", :preview_id => "dtext-preview-for-#{forum_topic.original_post.id}" %>
|
<%= dtext_preview_button "forum_post", "body", :input_id => "forum_post_body_for_#{forum_topic.original_post.id}", :preview_id => "dtext-preview-for-#{forum_topic.original_post.id}" %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|||||||
@@ -9,30 +9,36 @@
|
|||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
<% forum_topics.each do |topic| %>
|
<% forum_topics.each do |topic| %>
|
||||||
<tr class="forum-topic-row forum-topic-category-<%= topic.category_id %>">
|
<% if CurrentUser.user.level >= topic.min_level %>
|
||||||
<td>
|
<tr class="forum-topic-row forum-topic-category-<%= topic.category_id %>">
|
||||||
<% if topic.is_sticky? %>
|
<td>
|
||||||
<span class="sticky">Sticky:</span>
|
<% if topic.is_sticky? %>
|
||||||
<% end %>
|
<span class="sticky">Sticky:</span>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
<% unless topic.read_by?(CurrentUser.user) %>
|
<% unless topic.read_by?(CurrentUser.user) %>
|
||||||
<span class="new">NEW</span>
|
<span class="new">NEW</span>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<%= link_to topic.title, forum_topic_path(topic) %>
|
<%= link_to topic.title, forum_topic_path(topic) %>
|
||||||
|
|
||||||
<% if topic.response_count > Danbooru.config.posts_per_page %>
|
<% if topic.response_count > Danbooru.config.posts_per_page %>
|
||||||
<%= link_to "page #{topic.last_page}", forum_topic_path(topic, :page => topic.last_page), :class => "last-page" %>
|
<%= link_to "page #{topic.last_page}", forum_topic_path(topic, :page => topic.last_page), :class => "last-page" %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<% if topic.is_locked? %>
|
<% if topic.is_locked? %>
|
||||||
<span class="locked-topic">(locked)</span>
|
<span class="locked-topic">(locked)</span>
|
||||||
<% end %>
|
<% end %>
|
||||||
</td>
|
|
||||||
<td><%= link_to_user topic.creator %></td>
|
<% if topic.min_level > 0 %>
|
||||||
<td><%= link_to_user topic.updater %></td>
|
<span class="level-topic">(<%= User.level_string(topic.min_level).downcase %> only)</span>
|
||||||
<td><%= compact_time topic.updated_at %></td>
|
<% end %>
|
||||||
</tr>
|
</td>
|
||||||
|
<td><%= link_to_user topic.creator %></td>
|
||||||
|
<td><%= link_to_user topic.updater %></td>
|
||||||
|
<td><%= compact_time topic.updated_at %></td>
|
||||||
|
</tr>
|
||||||
|
<% end %>
|
||||||
<% end %>
|
<% end %>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
@@ -2,8 +2,13 @@
|
|||||||
<div id="a-show">
|
<div id="a-show">
|
||||||
<h1>
|
<h1>
|
||||||
Topic: <%= @forum_topic.title %>
|
Topic: <%= @forum_topic.title %>
|
||||||
|
|
||||||
|
<% if @forum_topic.min_level >= User::Levels::BUILDER %>
|
||||||
|
<span class="level-topic">(<%= User.level_string(@forum_topic.min_level).downcase %> only)</span>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
<% if @forum_topic.is_deleted? %>
|
<% if @forum_topic.is_deleted? %>
|
||||||
(deleted)
|
<span class="locked-topic">(deleted)</span>
|
||||||
<% end %>
|
<% end %>
|
||||||
</h1>
|
</h1>
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
class AddMinLevelToForumTopics < ActiveRecord::Migration
|
||||||
|
def change
|
||||||
|
add_column :forum_topics, :min_level, :integer, :default => 0, :null => false
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -2210,7 +2210,8 @@ CREATE TABLE forum_topics (
|
|||||||
text_index tsvector NOT NULL,
|
text_index tsvector NOT NULL,
|
||||||
created_at timestamp without time zone,
|
created_at timestamp without time zone,
|
||||||
updated_at timestamp without time zone,
|
updated_at timestamp without time zone,
|
||||||
category_id integer DEFAULT 0 NOT NULL
|
category_id integer DEFAULT 0 NOT NULL,
|
||||||
|
min_level integer DEFAULT 0 NOT NULL
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
@@ -7456,3 +7457,5 @@ INSERT INTO schema_migrations (version) VALUES ('20160919234407');
|
|||||||
|
|
||||||
INSERT INTO schema_migrations (version) VALUES ('20161018221128');
|
INSERT INTO schema_migrations (version) VALUES ('20161018221128');
|
||||||
|
|
||||||
|
INSERT INTO schema_migrations (version) VALUES ('20161024220345');
|
||||||
|
|
||||||
|
|||||||
@@ -16,6 +16,17 @@ class ForumTopicsControllerTest < ActionController::TestCase
|
|||||||
CurrentUser.ip_addr = nil
|
CurrentUser.ip_addr = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "for a level restricted topic" do
|
||||||
|
setup do
|
||||||
|
@forum_topic.update_attribute(:min_level, 50)
|
||||||
|
end
|
||||||
|
|
||||||
|
should "not allow users to see the topic" do
|
||||||
|
get :show, {:id => @forum_topic.id}
|
||||||
|
assert_redirected_to forum_topics_path
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
context "show action" do
|
context "show action" do
|
||||||
should "render" do
|
should "render" do
|
||||||
get :show, {:id => @forum_topic.id}
|
get :show, {:id => @forum_topic.id}
|
||||||
|
|||||||
Reference in New Issue
Block a user