pictures_controller.rb 811 B

1234567891011121314151617181920212223242526272829303132333435
  1. # frozen_string_literal: true
  2. module Settings
  3. class PicturesController < BaseController
  4. before_action :set_account
  5. before_action :set_picture
  6. def destroy
  7. if valid_picture?
  8. if UpdateAccountService.new.call(@account, { @picture => nil, "#{@picture}_remote_url" => '' })
  9. ActivityPub::UpdateDistributionWorker.perform_async(@account.id)
  10. redirect_to settings_profile_path, notice: I18n.t('generic.changes_saved_msg'), status: 303
  11. else
  12. redirect_to settings_profile_path
  13. end
  14. else
  15. bad_request
  16. end
  17. end
  18. private
  19. def set_account
  20. @account = current_account
  21. end
  22. def set_picture
  23. @picture = params[:id]
  24. end
  25. def valid_picture?
  26. %w(avatar header).include?(@picture)
  27. end
  28. end
  29. end