]> cat aescling's git repositories - mastodon.git/commitdiff
Implement the ability for an Administrator or Moderator to remove an account avatar...
authorEmelia Smith <ThisIsMissEm@users.noreply.github.com>
Mon, 2 Apr 2018 11:45:07 +0000 (13:45 +0200)
committerEugen Rochko <eugen@zeonfederated.com>
Mon, 2 Apr 2018 11:45:07 +0000 (13:45 +0200)
app/controllers/admin/accounts_controller.rb
app/helpers/admin/action_logs_helper.rb
app/policies/account_policy.rb
app/views/admin/accounts/show.html.haml
config/locales/en.yml
config/routes.rb

index 7428c3f229684c50e7b4192cf64212106f768307..e7ca6b9074ab725fb89c1f7de801cb52035238dc 100644 (file)
@@ -2,7 +2,7 @@
 
 module Admin
   class AccountsController < BaseController
-    before_action :set_account, only: [:show, :subscribe, :unsubscribe, :redownload, :enable, :disable, :memorialize]
+    before_action :set_account, only: [:show, :subscribe, :unsubscribe, :redownload, :remove_avatar, :enable, :disable, :memorialize]
     before_action :require_remote_account!, only: [:subscribe, :unsubscribe, :redownload]
     before_action :require_local_account!, only: [:enable, :disable, :memorialize]
 
@@ -60,6 +60,17 @@ module Admin
       redirect_to admin_account_path(@account.id)
     end
 
+    def remove_avatar
+      authorize @account, :remove_avatar?
+
+      @account.avatar = nil
+      @account.save!
+
+      log_action :remove_avatar, @account.user
+
+      redirect_to admin_account_path(@account.id)
+    end
+
     private
 
     def set_account
index 4475034a508b0242182466a57d7b3ead77949077..78278c70047efe4c73541051fea01bd6521a48b4 100644 (file)
@@ -86,7 +86,7 @@ module Admin::ActionLogsHelper
       opposite_verbs?(log) ? 'negative' : 'positive'
     when :update, :reset_password, :disable_2fa, :memorialize
       'neutral'
-    when :demote, :silence, :disable, :suspend
+    when :demote, :silence, :disable, :suspend, :remove_avatar
       'negative'
     when :destroy
       opposite_verbs?(log) ? 'positive' : 'negative'
index 85e2c84199b39b4fbdb5da504b2fdf820680aed9..efabe80d0d58bd357431f36aaab41041d450f343 100644 (file)
@@ -29,6 +29,10 @@ class AccountPolicy < ApplicationPolicy
     admin?
   end
 
+  def remove_avatar?
+    staff?
+  end
+
   def subscribe?
     admin?
   end
index dbbf5fc092c28bf82b6ce6b43dfac13d6eb518a3..fecfd6cc85748b1e7626e44c9eddb4d6b8aec917 100644 (file)
         %th= t('admin.accounts.display_name')
         %td= @account.display_name
 
+      %tr
+        %th= t('admin.accounts.avatar')
+        %th
+          = link_to @account.avatar.url(:original) do
+            = image_tag @account.avatar.url(:original), alt: '', width: 40, height: 40, class: 'avatar'
+          - if @account.local? && @account.avatar?
+            = table_link_to 'trash', t('admin.accounts.remove_avatar'), remove_avatar_admin_account_path(@account.id), method: :post, data: { confirm: t('admin.accounts.are_you_sure') } if can?(:remove_avatar, @account)
+
       - if @account.local?
         %tr
           %th= t('admin.accounts.role')
index e3d76971b4941a8e9e16e5f20ca0155c6a487cbe..fb2bbf4fec2be89b38fbebc5257f1ab282446979 100644 (file)
@@ -60,6 +60,7 @@ en:
       destroyed_msg: Moderation note successfully destroyed!
     accounts:
       are_you_sure: Are you sure?
+      avatar: Avatar
       by_domain: Domain
       confirm: Confirm
       confirmed: Confirmed
@@ -108,6 +109,7 @@ en:
       public: Public
       push_subscription_expires: PuSH subscription expires
       redownload: Refresh avatar
+      remove_avatar: Remove avatar
       reset: Reset
       reset_password: Reset password
       resubscribe: Resubscribe
@@ -150,6 +152,7 @@ en:
         enable_user: "%{name} enabled login for user %{target}"
         memorialize_account: "%{name} turned %{target}'s account into a memoriam page"
         promote_user: "%{name} promoted user %{target}"
+        remove_avatar_user: "%{name} removed %{target}'s avatar"
         reset_password_user: "%{name} reset password of user %{target}"
         resolve_report: "%{name} dismissed report %{target}"
         silence_account: "%{name} silenced %{target}'s account"
index 0542cb68016794671b3f45eb49b04b2a7f997c45..9a446056210797fe018774f8655cf941269c1c8a 100644 (file)
@@ -144,6 +144,7 @@ Rails.application.routes.draw do
         post :enable
         post :disable
         post :redownload
+        post :remove_avatar
         post :memorialize
       end