2018-09-23 15:44:14 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-11-13 14:35:47 -05:00
|
|
|
class Profiles::ChatNamesController < Profiles::ApplicationController
|
|
|
|
before_action :chat_name_token, only: [:new]
|
|
|
|
before_action :chat_name_params, only: [:new, :create, :deny]
|
|
|
|
|
|
|
|
def index
|
2016-11-17 08:58:03 -05:00
|
|
|
@chat_names = current_user.chat_names
|
2016-11-13 14:35:47 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def new
|
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
|
|
|
new_chat_name = current_user.chat_names.new(chat_name_params)
|
|
|
|
|
|
|
|
if new_chat_name.save
|
2019-04-08 10:17:45 -04:00
|
|
|
flash[:notice] = _("Authorized %{new_chat_name}") % { new_chat_name: new_chat_name.chat_name }
|
2016-11-13 14:35:47 -05:00
|
|
|
else
|
2019-04-08 10:17:45 -04:00
|
|
|
flash[:alert] = _("Could not authorize chat nickname. Try again!")
|
2016-11-13 14:35:47 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
delete_chat_name_token
|
|
|
|
redirect_to profile_chat_names_path
|
|
|
|
end
|
|
|
|
|
|
|
|
def deny
|
|
|
|
delete_chat_name_token
|
|
|
|
|
2019-04-08 10:17:45 -04:00
|
|
|
flash[:notice] = _("Denied authorization of chat nickname %{user_name}.") % { user_name: chat_name_params[:user_name] }
|
2016-11-13 14:35:47 -05:00
|
|
|
|
|
|
|
redirect_to profile_chat_names_path
|
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
|
|
|
@chat_name = chat_names.find(params[:id])
|
|
|
|
|
|
|
|
if @chat_name.destroy
|
2019-04-08 10:17:45 -04:00
|
|
|
flash[:notice] = _("Deleted chat nickname: %{chat_name}!") % { chat_name: @chat_name.chat_name }
|
2016-11-13 14:35:47 -05:00
|
|
|
else
|
2019-04-08 10:17:45 -04:00
|
|
|
flash[:alert] = _("Could not delete chat nickname %{chat_name}.") % { chat_name: @chat_name.chat_name }
|
2016-11-13 14:35:47 -05:00
|
|
|
end
|
|
|
|
|
2018-07-02 06:43:06 -04:00
|
|
|
redirect_to profile_chat_names_path, status: :found
|
2016-11-13 14:35:47 -05:00
|
|
|
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
|