You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

38 lines
1.4 KiB

  1. # frozen_string_literal: true
  2. class Api::V1::Accounts::CredentialsController < Api::BaseController
  3. before_action -> { doorkeeper_authorize! :read, :'read:accounts' }, except: [:update]
  4. before_action -> { doorkeeper_authorize! :write, :'write:accounts' }, 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, :bot, :discoverable, fields_attributes: [:name, :value])
  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. 'setting_default_language' => source_params.fetch(:language, @account.user.setting_default_language),
  28. }
  29. end
  30. end