forked from consuldemocracy/consuldemocracy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add setting to enable cookies consent test mode
This way we allow administrators to test the provided cookies consent configuration before showing the feature to common users.
- Loading branch information
Showing
9 changed files
with
117 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,21 @@ | ||
class Layout::CookiesConsent::BaseComponent < ApplicationComponent | ||
delegate :current_user, to: :helpers | ||
|
||
def render? | ||
feature?(:cookies_consent) | ||
feature?(:cookies_consent) && (public_setup? || testing_setup?) | ||
end | ||
|
||
private | ||
|
||
def version_name | ||
Setting["cookies_consent.version_name"] | ||
end | ||
|
||
def public_setup? | ||
!feature?("cookies_consent.admin_test_mode") | ||
end | ||
|
||
def testing_setup? | ||
current_user&.administrator? && !public_setup? | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
spec/components/layout/cookies_consent/setup_component_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
require "rails_helper" | ||
|
||
describe Layout::CookiesConsent::SetupComponent do | ||
before do | ||
Setting["feature.cookies_consent"] = true | ||
Setting["cookies_consent.setup_page"] = true | ||
end | ||
|
||
it "is rendered when the cookies consent and the cookies setup features are enabled" do | ||
render_inline Layout::CookiesConsent::SetupComponent.new | ||
|
||
expect(page).to have_css(".cookies-consent-setup") | ||
end | ||
|
||
it "is not rendered when the cookies consent feature is disabled" do | ||
Setting["feature.cookies_consent"] = false | ||
|
||
render_inline Layout::CookiesConsent::SetupComponent.new | ||
|
||
expect(page).not_to have_css(".cookies-consent-setup") | ||
end | ||
|
||
it "is not rendered when the cookies setup feature is disabled" do | ||
Setting["cookies_consent.setup_page"] = false | ||
|
||
render_inline Layout::CookiesConsent::SetupComponent.new | ||
|
||
expect(page).not_to have_css(".cookies-consent-setup") | ||
end | ||
|
||
it "is rendered when the admin test mode is enabled and the current_user is an administrator" do | ||
Setting["cookies_consent.admin_test_mode"] = true | ||
sign_in(create(:administrator).user) | ||
|
||
render_inline Layout::CookiesConsent::SetupComponent.new | ||
|
||
expect(page).to have_css(".cookies-consent-setup") | ||
end | ||
|
||
it "is not rendered when the admin testing mode is enabled and the current_user is not an administrator" do | ||
Setting["cookies_consent.admin_test_mode"] = true | ||
sign_in(create(:user)) | ||
|
||
render_inline Layout::CookiesConsent::SetupComponent.new | ||
|
||
expect(page).not_to have_css(".cookies-consent-setup") | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters