From b8c0cbeed115976ddd9906784d0ae5da128755ad Mon Sep 17 00:00:00 2001 From: albert Date: Mon, 18 Feb 2013 15:59:35 -0500 Subject: [PATCH] restrict deleting forum posts to janitors --- app/controllers/forum_posts_controller.rb | 2 +- app/views/forum_posts/_forum_post.html.erb | 60 +++++++++++----------- 2 files changed, 32 insertions(+), 30 deletions(-) diff --git a/app/controllers/forum_posts_controller.rb b/app/controllers/forum_posts_controller.rb index 62c03aec5..2789d8aab 100644 --- a/app/controllers/forum_posts_controller.rb +++ b/app/controllers/forum_posts_controller.rb @@ -43,7 +43,7 @@ class ForumPostsController < ApplicationController def destroy @forum_post = ForumPost.find(params[:id]) - check_privilege(@forum_post) + raise User::PrivilegeError unless CurrentUser.is_janitor? @forum_post.update_attribute(:is_deleted, true) respond_with(@forum_post) end diff --git a/app/views/forum_posts/_forum_post.html.erb b/app/views/forum_posts/_forum_post.html.erb index baf0d032d..71b989a7e 100644 --- a/app/views/forum_posts/_forum_post.html.erb +++ b/app/views/forum_posts/_forum_post.html.erb @@ -1,30 +1,32 @@ -
-
-

- <%= link_to forum_post.creator.name, user_path(forum_post.creator_id) %> - <% if forum_post.is_deleted? %> - (deleted) - <% end %> -

-

- <%= time_ago_in_words_tagged(forum_post.created_at) %> -

-
-
-
- <%= format_text(forum_post.body) %> -
- -
  • <%= link_to "Quote", new_forum_post_path(:post_id => forum_post.id), :method => :get, :remote => true %>
  • - <% if CurrentUser.user.is_janitor? || CurrentUser.user.id == forum_post.creator_id %> - <% if forum_post.is_deleted %> -
  • <%= link_to "Undelete", undelete_forum_post_path(forum_post.id), :method => :post, :remote => true %>
  • - <% else %> -
  • <%= link_to "Delete", forum_post_path(forum_post.id), :confirm => "Do you really want to delete this post?", :method => :delete, :remote => true %>
  • +<% if CurrentUser.is_janitor? || !forum_post.is_deleted? %> +
    +
    +

    + <%= link_to forum_post.creator.name, user_path(forum_post.creator_id) %> + <% if forum_post.is_deleted? %> + (deleted) <% end %> -
  • <%= link_to "Edit", edit_forum_post_path(forum_post.id) %>
  • - <% end %> -

    -
    -
    -
    \ No newline at end of file + +

    + <%= time_ago_in_words_tagged(forum_post.created_at) %> +

    + +
    +
    + <%= format_text(forum_post.body) %> +
    + +
  • <%= link_to "Quote", new_forum_post_path(:post_id => forum_post.id), :method => :get, :remote => true %>
  • + <% if CurrentUser.user.is_janitor? %> + <% if forum_post.is_deleted %> +
  • <%= link_to "Undelete", undelete_forum_post_path(forum_post.id), :method => :post, :remote => true %>
  • + <% else %> +
  • <%= link_to "Delete", forum_post_path(forum_post.id), :confirm => "Do you really want to delete this post?", :method => :delete, :remote => true %>
  • + <% end %> +
  • <%= link_to "Edit", edit_forum_post_path(forum_post.id) %>
  • + <% end %> +
    +
    +
    + +<% end %> \ No newline at end of file