summaryrefslogtreecommitdiff
path: root/app/services
diff options
context:
space:
mode:
authorDouwe Maan <douwe@gitlab.com>2018-05-04 15:17:25 +0000
committerDouwe Maan <douwe@gitlab.com>2018-05-04 15:17:25 +0000
commit7603beffc916d06039cac63b223d8e6234b5d666 (patch)
treeb8b52e683a2c5829a97d7a802fae383369ab9eb5 /app/services
parenta1ce521c995cc7943583e6c42e13666e1edd93ac (diff)
parent39916fdfeddfd75279d13fa976fdb07f3b9b0e26 (diff)
downloadgitlab-ce-7603beffc916d06039cac63b223d8e6234b5d666.tar.gz
Merge branch 'bvl-enforce-terms' into 'master'
Enforce application wide terms Closes #44798 See merge request gitlab-org/gitlab-ce!18570
Diffstat (limited to 'app/services')
-rw-r--r--app/services/application_settings/update_service.rb15
-rw-r--r--app/services/users/respond_to_terms_service.rb24
2 files changed, 39 insertions, 0 deletions
diff --git a/app/services/application_settings/update_service.rb b/app/services/application_settings/update_service.rb
index 61589a07250..d6d3a661dab 100644
--- a/app/services/application_settings/update_service.rb
+++ b/app/services/application_settings/update_service.rb
@@ -1,7 +1,22 @@
module ApplicationSettings
class UpdateService < ApplicationSettings::BaseService
def execute
+ update_terms(@params.delete(:terms))
+
@application_setting.update(@params)
end
+
+ private
+
+ def update_terms(terms)
+ return unless terms.present?
+
+ # Avoid creating a new terms record if the text is exactly the same.
+ terms = terms.strip
+ return if terms == @application_setting.terms
+
+ ApplicationSetting::Term.create(terms: terms)
+ @application_setting.reset_memoized_terms
+ end
end
end
diff --git a/app/services/users/respond_to_terms_service.rb b/app/services/users/respond_to_terms_service.rb
new file mode 100644
index 00000000000..06d660186cf
--- /dev/null
+++ b/app/services/users/respond_to_terms_service.rb
@@ -0,0 +1,24 @@
+module Users
+ class RespondToTermsService
+ def initialize(user, term)
+ @user, @term = user, term
+ end
+
+ def execute(accepted:)
+ agreement = @user.term_agreements.find_or_initialize_by(term: @term)
+ agreement.accepted = accepted
+
+ if agreement.save
+ store_accepted_term(accepted)
+ end
+
+ agreement
+ end
+
+ private
+
+ def store_accepted_term(accepted)
+ @user.update_column(:accepted_term_id, accepted ? @term.id : nil)
+ end
+ end
+end