aliases_controller.rb 1013 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. # frozen_string_literal: true
  2. class Settings::AliasesController < Settings::BaseController
  3. skip_before_action :require_functional!
  4. before_action :require_not_suspended!
  5. before_action :set_aliases, except: :destroy
  6. before_action :set_alias, only: :destroy
  7. def index
  8. @alias = current_account.aliases.build
  9. end
  10. def create
  11. @alias = current_account.aliases.build(resource_params)
  12. if @alias.save
  13. ActivityPub::UpdateDistributionWorker.perform_async(current_account.id)
  14. redirect_to settings_aliases_path, notice: I18n.t('aliases.created_msg')
  15. else
  16. render :index
  17. end
  18. end
  19. def destroy
  20. @alias.destroy!
  21. redirect_to settings_aliases_path, notice: I18n.t('aliases.deleted_msg')
  22. end
  23. private
  24. def resource_params
  25. params.require(:account_alias).permit(:acct)
  26. end
  27. def set_alias
  28. @alias = current_account.aliases.find(params[:id])
  29. end
  30. def set_aliases
  31. @aliases = current_account.aliases.order(id: :desc).reject(&:new_record?)
  32. end
  33. end