logo

mastofe

My custom branche(s) on git.pleroma.social/pleroma/mastofe git clone https://hacktivis.me/git/mastofe.git

credentials_controller.rb (1222B)


  1. # frozen_string_literal: true
  2. class Api::V1::Accounts::CredentialsController < Api::BaseController
  3. before_action -> { doorkeeper_authorize! :read }, except: [:update]
  4. before_action -> { doorkeeper_authorize! :write }, only: [:update]
  5. before_action :require_user!
  6. def show
  7. @account = current_account
  8. render json: @account, serializer: REST::CredentialAccountSerializer
  9. end
  10. def update
  11. @account = current_account
  12. UpdateAccountService.new.call(@account, account_params, raise_error: true)
  13. UserSettingsDecorator.new(current_user).update(user_settings_params) if user_settings_params
  14. ActivityPub::UpdateDistributionWorker.perform_async(@account.id)
  15. render json: @account, serializer: REST::CredentialAccountSerializer
  16. end
  17. private
  18. def account_params
  19. params.permit(:display_name, :note, :avatar, :header, :locked)
  20. end
  21. def user_settings_params
  22. return nil unless params.key?(:source)
  23. source_params = params.require(:source)
  24. {
  25. 'setting_default_privacy' => source_params.fetch(:privacy, @account.user.setting_default_privacy),
  26. 'setting_default_sensitive' => source_params.fetch(:sensitive, @account.user.setting_default_sensitive),
  27. }
  28. end
  29. end