about summary refs log tree commit diff
path: root/app/controllers/settings
diff options
context:
space:
mode:
authorsternenseemann <git@lukasepple.de>2020-04-20 14:03:03 +0200
committerGitHub <noreply@github.com>2020-04-20 14:03:03 +0200
commit679980f77c0e869d2eebbf64c18faabd8a523a13 (patch)
treec160b40a94b74c16c6c68d9ff2c7db39ae35596b /app/controllers/settings
parent29f5353f8b7af331d6dddea4ee1888913361a545 (diff)
Allow users to delete their header and avatar (#13234)
This is achieved by sending a DELETE request to
/settings/profile/pictures/{avatar,header} via a link that is part of
the upload form's hint of the respective picture.
Diffstat (limited to 'app/controllers/settings')
-rw-r--r--app/controllers/settings/pictures_controller.rb37
1 files changed, 37 insertions, 0 deletions
diff --git a/app/controllers/settings/pictures_controller.rb b/app/controllers/settings/pictures_controller.rb
new file mode 100644
index 000000000..73926707b
--- /dev/null
+++ b/app/controllers/settings/pictures_controller.rb
@@ -0,0 +1,37 @@
+# frozen_string_literal: true
+
+module Settings
+  class PicturesController < BaseController
+    before_action :authenticate_user!
+    before_action :set_account
+    before_action :set_picture
+
+    def destroy
+      if valid_picture
+        account_params = {
+          @picture => nil,
+          (@picture + '_remote_url') => nil,
+        }
+
+        msg = UpdateAccountService.new.call(@account, account_params) ? I18n.t('generic.changes_saved_msg') : nil
+        redirect_to settings_profile_path, notice: msg, status: 303
+      else
+        bad_request
+      end
+    end
+
+    private
+
+    def set_account
+      @account = current_account
+    end
+
+    def set_picture
+      @picture = params[:id]
+    end
+
+    def valid_picture
+      @picture == 'avatar' || @picture == 'header'
+    end
+  end
+end