summaryrefslogtreecommitdiff
path: root/app/controllers/settings/chat_names_controller.rb
diff options
context:
space:
mode:
Diffstat (limited to 'app/controllers/settings/chat_names_controller.rb')
-rw-r--r--app/controllers/settings/chat_names_controller.rb66
1 files changed, 66 insertions, 0 deletions
diff --git a/app/controllers/settings/chat_names_controller.rb b/app/controllers/settings/chat_names_controller.rb
new file mode 100644
index 00000000000..88d159f8dd9
--- /dev/null
+++ b/app/controllers/settings/chat_names_controller.rb
@@ -0,0 +1,66 @@
+# frozen_string_literal: true
+
+class Settings::ChatNamesController < Settings::ApplicationController
+ before_action :chat_name_token, only: [:new]
+ before_action :chat_name_params, only: [:new, :create, :deny]
+
+ def index
+ @chat_names = current_user.chat_names
+ end
+
+ def new
+ end
+
+ def create
+ new_chat_name = current_user.chat_names.new(chat_name_params)
+
+ if new_chat_name.save
+ flash[:notice] = _("Authorized %{new_chat_name}") % { new_chat_name: new_chat_name.chat_name }
+ else
+ flash[:alert] = _("Could not authorize chat nickname. Try again!")
+ end
+
+ delete_chat_name_token
+ redirect_to settings_chat_names_path
+ end
+
+ def deny
+ delete_chat_name_token
+
+ flash[:notice] = _("Denied authorization of chat nickname %{user_name}.") % { user_name: chat_name_params[:user_name] }
+
+ redirect_to settings_chat_names_path
+ end
+
+ def destroy
+ @chat_name = chat_names.find(params[:id])
+
+ if @chat_name.destroy
+ flash[:notice] = _("Deleted chat nickname: %{chat_name}!") % { chat_name: @chat_name.chat_name }
+ else
+ flash[:alert] = _("Could not delete chat nickname %{chat_name}.") % { chat_name: @chat_name.chat_name }
+ end
+
+ redirect_to settings_chat_names_path, status: :found
+ end
+
+ private
+
+ def delete_chat_name_token
+ chat_name_token.delete
+ end
+
+ def chat_name_params
+ @chat_name_params ||= chat_name_token.get || render_404
+ end
+
+ def chat_name_token
+ return render_404 unless params[:token] || render_404
+
+ @chat_name_token ||= Gitlab::ChatNameToken.new(params[:token])
+ end
+
+ def chat_names
+ @chat_names ||= current_user.chat_names
+ end
+end