summaryrefslogtreecommitdiff
path: root/app/policies
diff options
context:
space:
mode:
authorBob Van Landuyt <bob@vanlanduyt.co>2018-04-27 14:56:50 +0200
committerBob Van Landuyt <bob@vanlanduyt.co>2018-05-04 13:54:43 +0200
commit10aa55a770c2985c22c92d17b8a7ea90b0a09085 (patch)
tree15b66bb5e3f26d0a49c07bf781c644deb998f0c8 /app/policies
parent65bea3f7d0bf30b5f9a9b3f94567474d3c8f7cbc (diff)
downloadgitlab-ce-10aa55a770c2985c22c92d17b8a7ea90b0a09085.tar.gz
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/policies')
-rw-r--r--app/policies/application_setting/term_policy.rb30
1 files changed, 30 insertions, 0 deletions
diff --git a/app/policies/application_setting/term_policy.rb b/app/policies/application_setting/term_policy.rb
new file mode 100644
index 00000000000..648932ddba9
--- /dev/null
+++ b/app/policies/application_setting/term_policy.rb
@@ -0,0 +1,30 @@
+class ApplicationSetting
+ class TermPolicy < BasePolicy
+ include Gitlab::Utils::StrongMemoize
+
+ condition(:logged_in, scope: :user) { @user }
+
+ condition(:current_terms, scope: :subject) do
+ Gitlab::CurrentSettings.current_application_settings.latest_terms == @subject
+ end
+
+ condition(:terms_accepted, scope: :user, score: 1) do
+ agreement&.accepted
+ end
+
+ rule { logged_in & current_terms }.policy do
+ enable :accept_terms
+ enable :decline_terms
+ end
+
+ rule { terms_accepted }.prevent :accept_terms
+
+ def agreement
+ strong_memoize(:agreement) do
+ next nil if @user.nil? || @subject.nil?
+
+ @user.term_agreements.find_by(term: @subject)
+ end
+ end
+ end
+end