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