]> git.openstreetmap.org Git - rails.git/commitdiff
Merge remote-tracking branch 'upstream/pull/2411'
authorTom Hughes <tom@compton.nu>
Wed, 23 Oct 2019 09:55:02 +0000 (10:55 +0100)
committerTom Hughes <tom@compton.nu>
Wed, 23 Oct 2019 09:55:02 +0000 (10:55 +0100)
app/controllers/diary_entries_controller.rb
app/views/layouts/_header.html.erb
app/views/redactions/show.html.erb
app/views/user_blocks/blocks_by.html.erb
app/views/user_blocks/blocks_on.html.erb
app/views/user_blocks/index.html.erb
app/views/user_blocks/show.html.erb
app/views/users/show.html.erb

index ba2a2976e324abcf36f8ce08c3ce079851a4a738..5f53e81b65ca05e89ef89f1319a89e2f85feb653 100644 (file)
@@ -158,7 +158,7 @@ class DiaryEntriesController < ApplicationController
     @page = (params[:page] || 1).to_i
     @page_size = 20
 
-    @entries = @entries.visible unless current_user&.administrator?
+    @entries = @entries.visible unless can? :unhide, DiaryEntry
     @entries = @entries.order("created_at DESC")
     @entries = @entries.offset((@page - 1) * @page_size)
     @entries = @entries.limit(@page_size)
@@ -203,7 +203,7 @@ class DiaryEntriesController < ApplicationController
     @entry = @user.diary_entries.visible.where(:id => params[:id]).first
     if @entry
       @title = t "diary_entries.show.title", :user => params[:display_name], :title => @entry.title
-      @comments = current_user&.administrator? ? @entry.comments : @entry.visible_comments
+      @comments = can?(:unhidecomment, DiaryEntry) ? @entry.comments : @entry.visible_comments
     else
       @title = t "diary_entries.no_such_entry.title", :id => params[:id]
       render :action => "no_such_entry", :status => :not_found
@@ -237,7 +237,7 @@ class DiaryEntriesController < ApplicationController
   def comments
     conditions = { :user_id => @user }
 
-    conditions[:visible] = true unless current_user&.administrator?
+    conditions[:visible] = true unless can? :unhidecomment, DiaryEntry
 
     @comment_pages, @comments = paginate(:diary_comments,
                                          :conditions => conditions,
index 725000a1364bd2dd0a6ca9fc343f494ce2f2be08..c95cc4a75d447375c544c3b38d1a5a22e1dd6a4f 100644 (file)
@@ -40,7 +40,7 @@
   </nav>
   <nav class='secondary'>
     <ul>
-      <% if current_user and ( current_user.administrator? or current_user.moderator? ) %>
+      <% if can? :index, Issue %>
         <li class="compact-hide <%= current_page_class(issues_path) %>">
           <%= link_to issues_path(:status => "open") do %>
             <%= t("layouts.issues") %>
index a87cca604fd9c220a66fb07d22d24786e3c0fb99..1eb20f16f1564ce0350d51bb5f3d802a0822d72e 100644 (file)
   <%= @redaction.description.to_html %>
 </div>
 
-<% if current_user and current_user.moderator? %>
+<% if can?(:edit, Redaction) || can?(:destroy, Redaction) %>
 <div class="buttons">
-  <%= button_to t(".edit"), edit_redaction_path(@redaction), :method => :get %></td>
-  <%= 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 %></td>
+  <% end %>
+  <% if can?(:destroy, Redaction) %>
+    <%= button_to t(".destroy"), @redaction, :method => "delete", :remote => true, :data => { :confirm => t(".confirm") } %>
+  <% end %>
 </div>
 <% end %>
index 15d3c970f68cba751b7f6d7d8a68ffb9b04ac9a0..284052a7b5413e7a8d344de18b86f02191b60420 100644 (file)
@@ -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 %>
 <p><%= t ".empty", :name => h(@user.display_name) %></p>
 <% end %>
index 004a967b0fbf6dbe2cf47a8fdcf86212a24e8a52..bb71d48c8c1d5f555e2734501611b9eb2c554fb4 100644 (file)
@@ -3,7 +3,7 @@
   <h1><%= raw(t(".heading", :name => link_to(h(@user.display_name), user_path(@user)))) %></h1>
 <% 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 %>
 <p><%= t ".empty", :name => h(@user.display_name) %></p>
 <% end %>
index 42e75ecf0a5597685a62508820baa2c6ea7cee6d..57cef6055992722523a71dc475feb718b6c1423a 100644 (file)
@@ -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 %>
 <p><%= t ".empty" %></p>
 <% end %>
index 7b34d204a96c3edbb5a0ab2b55944be7d647aaa6..7e225bf14e34b2cec45d43c221469a55d2d55af2 100644 (file)
@@ -13,7 +13,7 @@
     <% if current_user and current_user.id == @user_block.creator_id %>
       <li><%= link_to t(".edit"), edit_user_block_path(@user_block) %></li>
     <% end %>
-    <% if current_user and current_user.moderator? %>
+    <% if can?(:revoke, UserBlock) %>
       <li><%= link_to(t(".revoke"), :controller => "user_blocks", :action => "revoke", :id => @user_block.id) %></li>
     <% end %>
   <% end %>
index aee000a97b001571d78f45603082afbd08443f7d..7e8b451851bf48302f3df1a56c19c53cd1ff3ae7 100644 (file)
@@ -35,7 +35,7 @@
             </li>
           <% end %>
 
-          <% if current_user and current_user.moderator? and current_user.blocks_created.exists? %>
+          <% if can?(:create, UserBlock) and current_user.blocks_created.exists? %>
             <li>
               <%= link_to t(".blocks by me"), :controller => "user_blocks", :action => "blocks_by", :display_name => current_user.display_name %>
               <span class='count-number'><%= number_with_delimiter(current_user.blocks_created.active.size) %></span>
@@ -96,7 +96,7 @@
             </li>
           <% end %>
 
-          <% if current_user and current_user.moderator? %>
+          <% if can?(:create, UserBlock) %>
             <li>
             <%= link_to t(".create_block"), :controller => "user_blocks", :action => "new", :display_name => @user.display_name %>
             </li>
 
       <% end %>
 
-      <% if current_user and current_user.administrator? %>
+      <% if can?(:set_status, User) || can?(:delete, User) %>
 
         <ul class='secondary-actions clearfix'>
-          <% if ["active", "confirmed"].include? @user.status %>
-            <li>
-              <%= link_to t(".deactivate_user"), set_status_user_path(:status => "pending", :display_name => @user.display_name), :data => { :confirm => t(".confirm") } %>
-            </li>
-          <% elsif ["pending"].include? @user.status %>
-            <li>
-              <%= link_to t(".activate_user"), set_status_user_path(:status => "active", :display_name => @user.display_name), :data => { :confirm => t(".confirm") } %>
-            </li>
-          <% end %>
+          <% if can? :set_status, User %>
+            <% if ["active", "confirmed"].include? @user.status %>
+              <li>
+                <%= link_to t(".deactivate_user"), set_status_user_path(:status => "pending", :display_name => @user.display_name), :data => { :confirm => t(".confirm") } %>
+              </li>
+            <% elsif ["pending"].include? @user.status %>
+              <li>
+                <%= link_to t(".activate_user"), set_status_user_path(:status => "active", :display_name => @user.display_name), :data => { :confirm => t(".confirm") } %>
+              </li>
+            <% end %>
 
-          <% if ["active", "suspended"].include? @user.status %>
-            <li>
-              <%= link_to t(".confirm_user"), set_status_user_path(:status => "confirmed", :display_name => @user.display_name), :data => { :confirm => t(".confirm") } %>
-            </li>
+            <% if ["active", "suspended"].include? @user.status %>
+              <li>
+                <%= link_to t(".confirm_user"), set_status_user_path(:status => "confirmed", :display_name => @user.display_name), :data => { :confirm => t(".confirm") } %>
+              </li>
+            <% end %>
+              <li>
+                <% if ["pending", "active", "confirmed", "suspended"].include? @user.status %>
+                  <%= link_to t(".hide_user"), set_status_user_path(:status => "deleted", :display_name => @user.display_name), :data => { :confirm => t(".confirm") } %>
+              <% else %>
+                <%= link_to t(".unhide_user"), set_status_user_path(:status => "active", :display_name => @user.display_name), :data => { :confirm => t(".confirm") } %>
+              </li>
+            <% end %>
           <% end %>
+          <% if can? :delete, User %>
             <li>
-              <% if ["pending", "active", "confirmed", "suspended"].include? @user.status %>
-                <%= link_to t(".hide_user"), set_status_user_path(:status => "deleted", :display_name => @user.display_name), :data => { :confirm => t(".confirm") } %>
-            <% else %>
-              <%= link_to t(".unhide_user"), set_status_user_path(:status => "active", :display_name => @user.display_name), :data => { :confirm => t(".confirm") } %>
+              <%= link_to t(".delete_user"), delete_user_path(:display_name => @user.display_name), :data => { :confirm => t(".confirm") } %>
             </li>
           <% end %>
-          <li>
-            <%= link_to t(".delete_user"), delete_user_path(:display_name => @user.display_name), :data => { :confirm => t(".confirm") } %>
-          </li>
         </ul>
 
         <% end %>