2018-04-26 11:28:24 +00:00
|
|
|
module Users
|
|
|
|
class TermsController < ApplicationController
|
|
|
|
before_action :terms
|
|
|
|
|
|
|
|
layout 'terms'
|
|
|
|
|
|
|
|
def index
|
2018-04-27 12:56:50 +00:00
|
|
|
@redirect = redirect_path
|
|
|
|
end
|
|
|
|
|
|
|
|
def accept
|
|
|
|
agreement = Users::RespondToTermsService.new(current_user, viewed_term)
|
|
|
|
.execute(accepted: true)
|
|
|
|
|
|
|
|
if agreement.persisted?
|
|
|
|
redirect_to redirect_path
|
|
|
|
else
|
|
|
|
flash[:alert] = agreement.errors.full_messages.join(', ')
|
|
|
|
redirect_to terms_path, redirect: redirect_path
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def decline
|
|
|
|
agreement = Users::RespondToTermsService.new(current_user, viewed_term)
|
|
|
|
.execute(accepted: false)
|
|
|
|
|
|
|
|
if agreement.persisted?
|
|
|
|
sign_out(current_user)
|
|
|
|
redirect_to root_path
|
|
|
|
else
|
|
|
|
flash[:alert] = agreement.errors.full_messages.join(', ')
|
|
|
|
redirect_to terms_path, redirect: redirect_path
|
|
|
|
end
|
2018-04-26 11:28:24 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2018-04-27 12:56:50 +00:00
|
|
|
def viewed_term
|
|
|
|
@viewed_term ||= ApplicationSetting::Term.find(params[:id])
|
|
|
|
end
|
|
|
|
|
2018-04-26 11:28:24 +00:00
|
|
|
def terms
|
2018-04-27 12:56:50 +00:00
|
|
|
unless @term = Gitlab::CurrentSettings.current_application_settings.latest_terms
|
|
|
|
redirect_to redirect_path
|
2018-04-26 11:28:24 +00:00
|
|
|
end
|
|
|
|
end
|
2018-04-27 12:56:50 +00:00
|
|
|
|
|
|
|
def redirect_path
|
|
|
|
referer = if request.referer && !request.referer.include?(terms_path)
|
|
|
|
URI(request.referer).path
|
|
|
|
end
|
|
|
|
|
|
|
|
params[:redirect] || referer || root_path
|
|
|
|
end
|
2018-04-26 11:28:24 +00:00
|
|
|
end
|
|
|
|
end
|