From: Andy Allan Date: Wed, 23 Oct 2019 09:26:16 +0000 (+0200) Subject: Convert various moderator? tests to use cancancan permissions checks X-Git-Tag: live~2358^2 X-Git-Url: https://git.openstreetmap.org/rails.git/commitdiff_plain/fb709531baf97b101892d39f6c133178c9ea7922 Convert various moderator? tests to use cancancan permissions checks --- diff --git a/app/views/redactions/show.html.erb b/app/views/redactions/show.html.erb index a87cca604..1eb20f16f 100644 --- a/app/views/redactions/show.html.erb +++ b/app/views/redactions/show.html.erb @@ -12,9 +12,13 @@ <%= @redaction.description.to_html %> -<% if current_user and current_user.moderator? %> +<% if can?(:edit, Redaction) || can?(:destroy, Redaction) %>
- <%= button_to t(".edit"), edit_redaction_path(@redaction), :method => :get %> - <%= button_to t(".destroy"), @redaction, :method => "delete", :remote => true, :data => { :confirm => t(".confirm") } %> + <% if can?(:edit, Redaction) %> + <%= button_to t(".edit"), edit_redaction_path(@redaction), :method => :get %> + <% end %> + <% if can?(:destroy, Redaction) %> + <%= button_to t(".destroy"), @redaction, :method => "delete", :remote => true, :data => { :confirm => t(".confirm") } %> + <% end %>
<% end %> diff --git a/app/views/user_blocks/blocks_by.html.erb b/app/views/user_blocks/blocks_by.html.erb index 15d3c970f..284052a7b 100644 --- a/app/views/user_blocks/blocks_by.html.erb +++ b/app/views/user_blocks/blocks_by.html.erb @@ -4,7 +4,7 @@ <% end %> <% unless @user_blocks.empty? %> -<%= render :partial => "blocks", :locals => { :show_revoke_link => (current_user && current_user.moderator?), :show_user_name => true, :show_creator_name => false } %> +<%= render :partial => "blocks", :locals => { :show_revoke_link => can?(:revoke, UserBlock), :show_user_name => true, :show_creator_name => false } %> <% else %>

<%= t ".empty", :name => h(@user.display_name) %>

<% end %> diff --git a/app/views/user_blocks/blocks_on.html.erb b/app/views/user_blocks/blocks_on.html.erb index 004a967b0..bb71d48c8 100644 --- a/app/views/user_blocks/blocks_on.html.erb +++ b/app/views/user_blocks/blocks_on.html.erb @@ -3,7 +3,7 @@

<%= raw(t(".heading", :name => link_to(h(@user.display_name), user_path(@user)))) %>

<% end %> <% unless @user_blocks.empty? %> -<%= render :partial => "blocks", :locals => { :show_revoke_link => (current_user && current_user.moderator?), :show_user_name => false, :show_creator_name => true } %> +<%= render :partial => "blocks", :locals => { :show_revoke_link => can?(:revoke, UserBlock), :show_user_name => false, :show_creator_name => true } %> <% else %>

<%= t ".empty", :name => h(@user.display_name) %>

<% end %> diff --git a/app/views/user_blocks/index.html.erb b/app/views/user_blocks/index.html.erb index 42e75ecf0..57cef6055 100644 --- a/app/views/user_blocks/index.html.erb +++ b/app/views/user_blocks/index.html.erb @@ -4,7 +4,7 @@ <% end %> <% unless @user_blocks.empty? %> -<%= render :partial => "blocks", :locals => { :show_revoke_link => (current_user && current_user.moderator?), :show_user_name => true, :show_creator_name => true } %> +<%= render :partial => "blocks", :locals => { :show_revoke_link => can?(:revoke, UserBlock), :show_user_name => true, :show_creator_name => true } %> <% else %>

<%= t ".empty" %>

<% end %> diff --git a/app/views/user_blocks/show.html.erb b/app/views/user_blocks/show.html.erb index 7b34d204a..7e225bf14 100644 --- a/app/views/user_blocks/show.html.erb +++ b/app/views/user_blocks/show.html.erb @@ -13,7 +13,7 @@ <% if current_user and current_user.id == @user_block.creator_id %>
  • <%= link_to t(".edit"), edit_user_block_path(@user_block) %>
  • <% end %> - <% if current_user and current_user.moderator? %> + <% if can?(:revoke, UserBlock) %>
  • <%= link_to(t(".revoke"), :controller => "user_blocks", :action => "revoke", :id => @user_block.id) %>
  • <% end %> <% end %> diff --git a/app/views/users/show.html.erb b/app/views/users/show.html.erb index 51dcb4f92..7e8b45185 100644 --- a/app/views/users/show.html.erb +++ b/app/views/users/show.html.erb @@ -35,7 +35,7 @@ <% end %> - <% if current_user and current_user.moderator? and current_user.blocks_created.exists? %> + <% if can?(:create, UserBlock) and current_user.blocks_created.exists? %>
  • <%= link_to t(".blocks by me"), :controller => "user_blocks", :action => "blocks_by", :display_name => current_user.display_name %> <%= number_with_delimiter(current_user.blocks_created.active.size) %> @@ -96,7 +96,7 @@
  • <% end %> - <% if current_user and current_user.moderator? %> + <% if can?(:create, UserBlock) %>
  • <%= link_to t(".create_block"), :controller => "user_blocks", :action => "new", :display_name => @user.display_name %>