2018-07-24 06:00:56 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-04-27 08:56:50 -04:00
|
|
|
class ApplicationSetting
|
|
|
|
class TermPolicy < BasePolicy
|
|
|
|
include Gitlab::Utils::StrongMemoize
|
|
|
|
|
|
|
|
condition(:current_terms, scope: :subject) do
|
|
|
|
Gitlab::CurrentSettings.current_application_settings.latest_terms == @subject
|
|
|
|
end
|
|
|
|
|
2018-04-27 10:50:33 -04:00
|
|
|
condition(:terms_accepted, score: 1) do
|
2018-04-27 08:56:50 -04:00
|
|
|
agreement&.accepted
|
|
|
|
end
|
|
|
|
|
2018-04-27 10:50:33 -04:00
|
|
|
rule { ~anonymous & current_terms }.policy do
|
2018-04-27 08:56:50 -04:00
|
|
|
enable :accept_terms
|
|
|
|
enable :decline_terms
|
|
|
|
end
|
|
|
|
|
|
|
|
rule { terms_accepted }.prevent :accept_terms
|
|
|
|
|
2018-08-27 11:31:01 -04:00
|
|
|
# rubocop: disable CodeReuse/ActiveRecord
|
2018-04-27 08:56:50 -04:00
|
|
|
def agreement
|
|
|
|
strong_memoize(:agreement) do
|
|
|
|
next nil if @user.nil? || @subject.nil?
|
|
|
|
|
|
|
|
@user.term_agreements.find_by(term: @subject)
|
|
|
|
end
|
|
|
|
end
|
2018-08-27 11:31:01 -04:00
|
|
|
# rubocop: enable CodeReuse/ActiveRecord
|
2018-04-27 08:56:50 -04:00
|
|
|
end
|
|
|
|
end
|