2015-04-26 12:48:37 +05:30
|
|
|
class InvitesController < ApplicationController
|
2015-09-11 14:41:01 +05:30
|
|
|
before_action :member
|
|
|
|
skip_before_action :authenticate_user!, only: :decline
|
2015-04-26 12:48:37 +05:30
|
|
|
|
|
|
|
respond_to :html
|
|
|
|
|
|
|
|
def show
|
|
|
|
end
|
|
|
|
|
|
|
|
def accept
|
|
|
|
if member.accept_invite!(current_user)
|
|
|
|
label, path = source_info(member.source)
|
|
|
|
|
|
|
|
redirect_to path, notice: "You have been granted #{member.human_access} access to #{label}."
|
|
|
|
else
|
2015-10-24 18:46:33 +05:30
|
|
|
redirect_back_or_default(options: { alert: "The invitation could not be accepted." })
|
2015-04-26 12:48:37 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def decline
|
|
|
|
if member.decline_invite!
|
|
|
|
label, _ = source_info(member.source)
|
|
|
|
|
2015-09-11 14:41:01 +05:30
|
|
|
path =
|
2015-04-26 12:48:37 +05:30
|
|
|
if current_user
|
2015-09-25 12:07:36 +05:30
|
|
|
dashboard_projects_path
|
2015-04-26 12:48:37 +05:30
|
|
|
else
|
|
|
|
new_user_session_path
|
|
|
|
end
|
|
|
|
|
|
|
|
redirect_to path, notice: "You have declined the invitation to join #{label}."
|
|
|
|
else
|
2015-10-24 18:46:33 +05:30
|
|
|
redirect_back_or_default(options: { alert: "The invitation could not be declined." })
|
2015-04-26 12:48:37 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def member
|
|
|
|
return @member if defined?(@member)
|
2015-09-11 14:41:01 +05:30
|
|
|
|
2015-04-26 12:48:37 +05:30
|
|
|
@token = params[:id]
|
|
|
|
@member = Member.find_by_invite_token(@token)
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
return render_404 unless @member
|
2015-04-26 12:48:37 +05:30
|
|
|
|
|
|
|
@member
|
|
|
|
end
|
|
|
|
|
|
|
|
def authenticate_user!
|
|
|
|
return if current_user
|
|
|
|
|
|
|
|
notice = "To accept this invitation, sign in"
|
2018-03-17 18:26:18 +05:30
|
|
|
notice << " or create an account" if Gitlab::CurrentSettings.allow_signup?
|
2015-04-26 12:48:37 +05:30
|
|
|
notice << "."
|
|
|
|
|
|
|
|
store_location_for :user, request.fullpath
|
|
|
|
redirect_to new_user_session_path, notice: notice
|
|
|
|
end
|
|
|
|
|
|
|
|
def source_info(source)
|
|
|
|
case source
|
|
|
|
when Project
|
|
|
|
project = member.source
|
2018-03-27 19:54:05 +05:30
|
|
|
label = "project #{project.full_name}"
|
2017-09-10 17:25:29 +05:30
|
|
|
path = project_path(project)
|
2015-04-26 12:48:37 +05:30
|
|
|
when Group
|
|
|
|
group = member.source
|
|
|
|
label = "group #{group.name}"
|
|
|
|
path = group_path(group)
|
|
|
|
else
|
|
|
|
label = "who knows what"
|
2015-09-25 12:07:36 +05:30
|
|
|
path = dashboard_projects_path
|
2015-04-26 12:48:37 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
[label, path]
|
|
|
|
end
|
|
|
|
end
|