From 79e7b9308e863dd351398219cb49f82501bab3d5 Mon Sep 17 00:00:00 2001 From: evazion Date: Fri, 20 Mar 2020 04:13:57 -0500 Subject: [PATCH] pundit: convert misc privilege checks in views to pundit. --- app/views/forum_topics/_secondary_links.html.erb | 14 ++++++++------ app/views/static/site_map.html.erb | 16 ++++++++++------ app/views/users/_secondary_links.html.erb | 5 ++++- 3 files changed, 22 insertions(+), 13 deletions(-) diff --git a/app/views/forum_topics/_secondary_links.html.erb b/app/views/forum_topics/_secondary_links.html.erb index 1e95d9bee..2aabcb132 100644 --- a/app/views/forum_topics/_secondary_links.html.erb +++ b/app/views/forum_topics/_secondary_links.html.erb @@ -2,15 +2,17 @@ <%= quick_search_form_for(:body_matches, forum_posts_path, "forum posts") %> <%= subnav_link_to "Listing", forum_topics_path %> - <% if CurrentUser.is_member? %> + <% if policy(ForumTopic).create? %> <%= subnav_link_to "New", new_forum_topic_path %> + <% end %> + <% if policy(ForumTopic).mark_all_as_read? %> <%= subnav_link_to "Mark all as read", mark_all_as_read_forum_topics_path, :method => :post, :"data-shortcut" => "shift+r" %> + <% end %> - <% if @forum_topic %> - <%= subnav_link_to "Request alias/implication", new_bulk_update_request_path(bulk_update_request: { forum_topic_id: @forum_topic.id }) %> - <% else %> - <%= subnav_link_to "Request alias/implication", new_bulk_update_request_path %> - <% end %> + <% if @forum_topic && policy(BulkUpdateRequest.new(forum_topic: @forum_topic)).create? %> + <%= subnav_link_to "Request alias/implication", new_bulk_update_request_path(bulk_update_request: { forum_topic_id: @forum_topic.id }) %> + <% else %> + <%= subnav_link_to "Request alias/implication", new_bulk_update_request_path %> <% end %> <%= subnav_link_to "Search", search_forum_posts_path %> diff --git a/app/views/static/site_map.html.erb b/app/views/static/site_map.html.erb index 517edc1fd..e3ee6b7fc 100644 --- a/app/views/static/site_map.html.erb +++ b/app/views/static/site_map.html.erb @@ -13,7 +13,7 @@
  • <%= link_to("Curated", curated_explore_posts_path) %>
  • <%= link_to("Most Viewed", viewed_explore_posts_path) %>
  • <%= link_to("Votes", post_votes_path) %>
  • - <% if CurrentUser.can_approve_posts? %> + <% if policy(PostApproval).create? %>
  • <%= link_to("Modqueue", modqueue_index_path) %>
  • <% end %> @@ -21,9 +21,7 @@
  • Post Events

  • <%= link_to("Changes", post_versions_path) %>
  • <%= link_to("Approvals", post_approvals_path) %>
  • - <% if CurrentUser.is_approver? %> -
  • <%= link_to("Disapprovals", post_disapprovals_path) %>
  • - <% end %> +
  • <%= link_to("Disapprovals", post_disapprovals_path) %>
  • <%= link_to("Appeals", post_appeals_path) %>
  • <%= link_to("Flags", post_flags_path) %>
  • <%= link_to("Replacements", post_replacements_path) %>
  • @@ -154,8 +152,11 @@
  • <%= link_to("User Name Change Requests", user_name_change_requests_path) %>
  • <% end %> - <% if CurrentUser.is_moderator? %> + <% if policy(ModerationReport).index? %>
  • <%= link_to("Moderation Reports", moderation_reports_path) %>
  • + <% end %> + + <% if policy(IpAddress).index? %>
  • <%= link_to("IP Addresses", ip_addresses_path) %>
  • <% end %> @@ -163,8 +164,11 @@
  • <%= link_to("IP Bans", ip_bans_path) %>
  • <% end %> - <% if CurrentUser.is_admin? %> + <% if policy(NewsUpdate).index? %>
  • <%= link_to("News Updates", news_updates_path) %>
  • + <% end %> + + <% if CurrentUser.is_admin? %>
  • <%= link_to("Admin Dashboard", admin_dashboard_path) %>
  • <% end %> diff --git a/app/views/users/_secondary_links.html.erb b/app/views/users/_secondary_links.html.erb index 739f0132d..e1b885966 100644 --- a/app/views/users/_secondary_links.html.erb +++ b/app/views/users/_secondary_links.html.erb @@ -27,8 +27,11 @@ <% end %> <% end %> - <% if CurrentUser.user.is_moderator? %> + <% if policy(CurrentUser.user).promote? %> <%= subnav_link_to "Promote", edit_admin_user_path(@user) %> + <% end %> + + <% if policy(Ban.new(user: @user)).create? %> <% if @user.is_banned? && @user.recent_ban.present? %> <%= subnav_link_to "Unban", ban_path(@user.recent_ban) %> <% else %>