restrict deleting forum posts to janitors

This commit is contained in:
albert
2013-02-18 15:59:35 -05:00
parent b109d44daf
commit b8c0cbeed1
2 changed files with 32 additions and 30 deletions

View File

@@ -43,7 +43,7 @@ class ForumPostsController < ApplicationController
def destroy def destroy
@forum_post = ForumPost.find(params[:id]) @forum_post = ForumPost.find(params[:id])
check_privilege(@forum_post) raise User::PrivilegeError unless CurrentUser.is_janitor?
@forum_post.update_attribute(:is_deleted, true) @forum_post.update_attribute(:is_deleted, true)
respond_with(@forum_post) respond_with(@forum_post)
end end

View File

@@ -1,30 +1,32 @@
<article data-forum-post-id="<%= forum_post.id %>"> <% if CurrentUser.is_janitor? || !forum_post.is_deleted? %>
<div class="author"> <article data-forum-post-id="<%= forum_post.id %>">
<h4> <div class="author">
<%= link_to forum_post.creator.name, user_path(forum_post.creator_id) %> <h4>
<% if forum_post.is_deleted? %> <%= link_to forum_post.creator.name, user_path(forum_post.creator_id) %>
(deleted) <% if forum_post.is_deleted? %>
<% end %> (deleted)
</h4>
<p>
<%= time_ago_in_words_tagged(forum_post.created_at) %>
</p>
</div>
<div class="content">
<div>
<%= format_text(forum_post.body) %>
</div>
<menu>
<li><%= link_to "Quote", new_forum_post_path(:post_id => forum_post.id), :method => :get, :remote => true %></li>
<% if CurrentUser.user.is_janitor? || CurrentUser.user.id == forum_post.creator_id %>
<% if forum_post.is_deleted %>
<li><%= link_to "Undelete", undelete_forum_post_path(forum_post.id), :method => :post, :remote => true %></li>
<% else %>
<li><%= link_to "Delete", forum_post_path(forum_post.id), :confirm => "Do you really want to delete this post?", :method => :delete, :remote => true %></li>
<% end %> <% end %>
<li><%= link_to "Edit", edit_forum_post_path(forum_post.id) %></li> </h4>
<% end %> <p>
</menu> <%= time_ago_in_words_tagged(forum_post.created_at) %>
</div> </p>
<div class="clearfix"></div> </div>
</article> <div class="content">
<div>
<%= format_text(forum_post.body) %>
</div>
<menu>
<li><%= link_to "Quote", new_forum_post_path(:post_id => forum_post.id), :method => :get, :remote => true %></li>
<% if CurrentUser.user.is_janitor? %>
<% if forum_post.is_deleted %>
<li><%= link_to "Undelete", undelete_forum_post_path(forum_post.id), :method => :post, :remote => true %></li>
<% else %>
<li><%= link_to "Delete", forum_post_path(forum_post.id), :confirm => "Do you really want to delete this post?", :method => :delete, :remote => true %></li>
<% end %>
<li><%= link_to "Edit", edit_forum_post_path(forum_post.id) %></li>
<% end %>
</menu>
</div>
<div class="clearfix"></div>
</article>
<% end %>