7684217d68
This enforces the terms in the web application. These cases are specced: - Logging in: When terms are enforced, and a user logs in that has not accepted the terms, they are presented with the screen. They get directed to their customized root path afterwards. - Signing up: After signing up, the first screen the user is presented with the screen to accept the terms. After they accept they are directed to the dashboard. - While a session is active: - For a GET: The user will be directed to the terms page first, after they accept the terms, they will be directed to the page they were going to - For any other request: They are directed to the terms, after they accept the terms, they are directed back to the page they came from to retry the request. Any information entered would be persisted in localstorage and available on the page.
28 lines
671 B
Ruby
28 lines
671 B
Ruby
class ApplicationSetting
|
|
class TermPolicy < BasePolicy
|
|
include Gitlab::Utils::StrongMemoize
|
|
|
|
condition(:current_terms, scope: :subject) do
|
|
Gitlab::CurrentSettings.current_application_settings.latest_terms == @subject
|
|
end
|
|
|
|
condition(:terms_accepted, score: 1) do
|
|
agreement&.accepted
|
|
end
|
|
|
|
rule { ~anonymous & 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
|