about summary refs log tree commit diff
path: root/app/controllers/settings/aliases_controller.rb
diff options
context:
space:
mode:
authorThibG <thib@sitedethib.com>2019-09-30 23:29:55 +0200
committerGitHub <noreply@github.com>2019-09-30 23:29:55 +0200
commit65db9df011a3e13efa79f4e56343aa69bdad7716 (patch)
tree1941b85de1f0d1b6f56b73345cddf664a71faf20 /app/controllers/settings/aliases_controller.rb
parentfebcdad2e2c98aee62b55ee21bdf0debf7c6fd6b (diff)
parent3b855b5c82362783969f748ad78bcaf85f938c9f (diff)
Merge pull request #1224 from ThibG/glitch-soc/merge-upstream
Merge upstream changes
Diffstat (limited to 'app/controllers/settings/aliases_controller.rb')
-rw-r--r--app/controllers/settings/aliases_controller.rb43
1 files changed, 43 insertions, 0 deletions
diff --git a/app/controllers/settings/aliases_controller.rb b/app/controllers/settings/aliases_controller.rb
new file mode 100644
index 000000000..b7c9a409d
--- /dev/null
+++ b/app/controllers/settings/aliases_controller.rb
@@ -0,0 +1,43 @@
+# frozen_string_literal: true
+
+class Settings::AliasesController < Settings::BaseController
+  layout 'admin'
+
+  before_action :authenticate_user!
+  before_action :set_aliases, except: :destroy
+  before_action :set_alias, only: :destroy
+
+  def index
+    @alias = current_account.aliases.build
+  end
+
+  def create
+    @alias = current_account.aliases.build(resource_params)
+
+    if @alias.save
+      ActivityPub::UpdateDistributionWorker.perform_async(current_account.id)
+      redirect_to settings_aliases_path, notice: I18n.t('aliases.created_msg')
+    else
+      render :index
+    end
+  end
+
+  def destroy
+    @alias.destroy!
+    redirect_to settings_aliases_path, notice: I18n.t('aliases.deleted_msg')
+  end
+
+  private
+
+  def resource_params
+    params.require(:account_alias).permit(:acct)
+  end
+
+  def set_alias
+    @alias = current_account.aliases.find(params[:id])
+  end
+
+  def set_aliases
+    @aliases = current_account.aliases.order(id: :desc).reject(&:new_record?)
+  end
+end