diff options
author | Kamil Trzcinski <ayufan@ayufan.eu> | 2016-11-13 20:35:47 +0100 |
---|---|---|
committer | Kamil Trzcinski <ayufan@ayufan.eu> | 2016-11-16 13:42:35 +0100 |
commit | c60437786bfe43344b4a5eb040437f73f37c6396 (patch) | |
tree | fe90ee0dd9e556369e7f53ce4a03e2751b486682 /app/controllers/profiles | |
parent | c5169b5d447ab6c73bbe542c071a4054c5969165 (diff) | |
download | gitlab-ce-c60437786bfe43344b4a5eb040437f73f37c6396.tar.gz |
Create relation between chat user and GitLab user and allow to authorize them [ci skip]
Diffstat (limited to 'app/controllers/profiles')
-rw-r--r-- | app/controllers/profiles/chat_names_controller.rb | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/app/controllers/profiles/chat_names_controller.rb b/app/controllers/profiles/chat_names_controller.rb new file mode 100644 index 00000000000..8c5b83adaf4 --- /dev/null +++ b/app/controllers/profiles/chat_names_controller.rb @@ -0,0 +1,64 @@ +class Profiles::ChatNamesController < Profiles::ApplicationController + before_action :chat_names + before_action :chat_name_token, only: [:new] + before_action :chat_name_params, only: [:new, :create, :deny] + + def index + 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 chat nickname #{new_chat_name.chat_name}" + else + flash[:alert] = "Could not authorize chat nickname. Try again!" + end + + delete_chat_name_token + redirect_to profile_chat_names_path + end + + def deny + delete_chat_name_token + + flash[:alert] = "Denied authorization of chat nickname #{chat_name_params[:user_name]}" + + redirect_to profile_chat_names_path + end + + def destroy + @chat_name = chat_names.find(params[:id]) + + if @chat_name.destroy + flash[:notice] = "Delete chat nickname: #{@chat_name.chat_name}!" + else + flash[:alert] = "Could not delete chat nickname #{@chat_name.chat_name}." + end + + redirect_to profile_chat_names_path + 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 |