2018-04-26 07:28:24 -04:00
|
|
|
module Users
|
|
|
|
class TermsController < ApplicationController
|
2018-04-27 10:50:33 -04:00
|
|
|
include InternalRedirect
|
|
|
|
|
2018-06-08 07:20:44 -04:00
|
|
|
skip_before_action :authenticate_user!
|
2018-04-27 10:50:33 -04:00
|
|
|
skip_before_action :enforce_terms!
|
2018-05-11 03:35:27 -04:00
|
|
|
skip_before_action :check_password_expiration
|
|
|
|
skip_before_action :check_two_factor_requirement
|
|
|
|
skip_before_action :require_email
|
|
|
|
|
2018-04-26 07:28:24 -04:00
|
|
|
before_action :terms
|
|
|
|
|
|
|
|
layout 'terms'
|
|
|
|
|
|
|
|
def index
|
2018-04-27 08:56:50 -04:00
|
|
|
@redirect = redirect_path
|
2018-05-25 19:17:57 -04:00
|
|
|
|
2018-06-08 07:20:44 -04:00
|
|
|
if current_user && @term.accepted_by_user?(current_user)
|
2018-05-25 19:17:57 -04:00
|
|
|
flash.now[:notice] = "You have already accepted the Terms of Service as #{current_user.to_reference}"
|
|
|
|
end
|
2018-04-27 08:56:50 -04:00
|
|
|
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 07:28:24 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2018-04-27 08:56:50 -04:00
|
|
|
def viewed_term
|
|
|
|
@viewed_term ||= ApplicationSetting::Term.find(params[:id])
|
|
|
|
end
|
|
|
|
|
2018-04-26 07:28:24 -04:00
|
|
|
def terms
|
2018-04-27 08:56:50 -04:00
|
|
|
unless @term = Gitlab::CurrentSettings.current_application_settings.latest_terms
|
|
|
|
redirect_to redirect_path
|
2018-04-26 07:28:24 -04:00
|
|
|
end
|
|
|
|
end
|
2018-04-27 08:56:50 -04:00
|
|
|
|
|
|
|
def redirect_path
|
2018-04-27 10:50:33 -04:00
|
|
|
redirect_to_path = safe_redirect_path(params[:redirect]) || safe_redirect_path_for_url(request.referer)
|
|
|
|
|
|
|
|
if redirect_to_path &&
|
|
|
|
excluded_redirect_paths.none? { |excluded| redirect_to_path.include?(excluded) }
|
|
|
|
redirect_to_path
|
|
|
|
else
|
|
|
|
root_path
|
|
|
|
end
|
|
|
|
end
|
2018-04-27 08:56:50 -04:00
|
|
|
|
2018-04-27 10:50:33 -04:00
|
|
|
def excluded_redirect_paths
|
|
|
|
[terms_path, new_user_session_path]
|
2018-04-27 08:56:50 -04:00
|
|
|
end
|
2018-04-26 07:28:24 -04:00
|
|
|
end
|
|
|
|
end
|