Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBob Van Landuyt <bob@vanlanduyt.co>2018-04-27 15:56:50 +0300
committerBob Van Landuyt <bob@vanlanduyt.co>2018-05-04 14:54:43 +0300
commit10aa55a770c2985c22c92d17b8a7ea90b0a09085 (patch)
tree15b66bb5e3f26d0a49c07bf781c644deb998f0c8 /app/controllers/users
parent65bea3f7d0bf30b5f9a9b3f94567474d3c8f7cbc (diff)
Allow a user to accept/decline terms
When a user accepts, we store this in the agreements to keep track of which terms they accepted. We also update the flag on the user.
Diffstat (limited to 'app/controllers/users')
-rw-r--r--app/controllers/users/terms_controller.rb43
1 files changed, 40 insertions, 3 deletions
diff --git a/app/controllers/users/terms_controller.rb b/app/controllers/users/terms_controller.rb
index 778e388ff5a..32507bdb7b1 100644
--- a/app/controllers/users/terms_controller.rb
+++ b/app/controllers/users/terms_controller.rb
@@ -2,18 +2,55 @@ module Users
class TermsController < ApplicationController
before_action :terms
-
layout 'terms'
def index
+ @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
end
private
+ def viewed_term
+ @viewed_term ||= ApplicationSetting::Term.find(params[:id])
+ end
+
def terms
- unless @terms = Gitlab::CurrentSettings.current_application_settings.latest_terms
- redirect_to request.referer || root_path
+ unless @term = Gitlab::CurrentSettings.current_application_settings.latest_terms
+ redirect_to redirect_path
end
end
+
+ def redirect_path
+ referer = if request.referer && !request.referer.include?(terms_path)
+ URI(request.referer).path
+ end
+
+ params[:redirect] || referer || root_path
+ end
end
end