-
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 a callout to the survey component management (#11)
* add views * remove google chrome * remove google chrome
- Loading branch information
1 parent
dc3b94f
commit 4dd10fc
Showing
17 changed files
with
160 additions
and
4 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
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
5 changes: 5 additions & 0 deletions
5
app/overrides/decidim/admin/components/_settings_fields/add_linked_group.html.erb.deface
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,5 @@ | ||
<!-- insert_after "erb[loud]:contains('settings_attribute_input')" --> | ||
|
||
<% if manifest.name == :surveys && field_name == :allow_unregistered %> | ||
<%= render "decidim/anonymous_codes/admin/surveys_component_settings/callout", resource: Decidim::Surveys::Survey.find_by(component: @component) %> | ||
<% end %> |
18 changes: 18 additions & 0 deletions
18
app/views/decidim/anonymous_codes/admin/surveys_component_settings/_callout.html.erb
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,18 @@ | ||
<% groups = Decidim::AnonymousCodes::Group.for(@component.organization).where(resource: resource) %> | ||
<% if groups.any? %> | ||
<div class="callout alert"> | ||
<p><strong><%= t(".group_locked") %></strong></p> | ||
<ul> | ||
<% groups.each do |group| %> | ||
<li><%= link_to translated_attribute(group.title), "##{group.id}" %></li> | ||
<% end %> | ||
</ul> | ||
<p class="help-text"><%= t(".group_locked_desc") %></p> | ||
</div> | ||
<% else %> | ||
<div class="callout warning"> | ||
<p><strong><%= t(".group_unlocked") %></strong></p> | ||
<p><%= link_to t(".new_group"), "#" %></p> | ||
<p class="help-text"><%= t(".group_unlocked_desc") %></p> | ||
</div> | ||
<% 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,17 @@ | ||
--- | ||
en: | ||
decidim: | ||
anonymous_codes: | ||
admin: | ||
surveys_component_settings: | ||
callout: | ||
group_locked: This survey can only be answered by using a valid code. | ||
group_locked_desc: Note that, unless "Allow unregistered users to answer" | ||
is enabled, only registered users can answer this survey (and they also | ||
will have to provide the code). | ||
group_unlocked: Anyone can answer this survey, but you can choose to restrict | ||
this by using a answer codes. | ||
group_unlocked_desc: Note that "Allow unregistered users to answer" will | ||
still apply if you choose to use this option. | ||
groups: 'Edit groups:' | ||
new_group: "\U0001F449 Create answer codes here" |
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 |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# frozen_string_literal: true | ||
|
||
if !Rails.env.production? || ENV.fetch("SEED", nil) | ||
print "Creating seeds for decidim_anonymous_codes...\n" unless Rails.env.test? | ||
|
||
organization = Decidim::Organization.first | ||
|
||
group1 = Decidim::AnonymousCodes::Group.create!( | ||
title: { en: "First Group" }, | ||
organization: organization, | ||
expires_at: 1.week.from_now, | ||
active: true, | ||
max_reuses: 1, | ||
resource: Decidim::Surveys::Survey.first | ||
) | ||
|
||
group2 = Decidim::AnonymousCodes::Group.create!( | ||
title: { en: "Second Group" }, | ||
organization: organization, | ||
expires_at: 1.week.from_now, | ||
active: true, | ||
max_reuses: 1, | ||
resource: Decidim::Surveys::Survey.second | ||
) | ||
|
||
5.times do | ||
Decidim::AnonymousCodes::Token.create!(token: Decidim::AnonymousCodes.token_generator, usage_count: 0, group: group1) | ||
end | ||
|
||
25.times do | ||
Decidim::AnonymousCodes::Token.create!(token: Decidim::AnonymousCodes.token_generator, usage_count: 0, group: group2) | ||
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
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 |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# frozen_string_literal: true | ||
|
||
require "spec_helper" | ||
|
||
describe "Surveys Component Settings", type: :system do | ||
let(:organization) { component.organization } | ||
let(:component) { survey.component } | ||
let(:user) { create :user, :admin, :confirmed, organization: organization } | ||
let(:group) { create :anonymous_codes_group, organization: organization, resource: resource } | ||
let!(:token) { create :anonymous_codes_token, group: group } | ||
let!(:survey) { create(:survey) } | ||
let(:resource) { nil } | ||
|
||
def visit_component | ||
visit Decidim::EngineRouter.admin_proxy(component.participatory_space).edit_component_path(component.id) | ||
end | ||
|
||
before do | ||
switch_to_host(organization.host) | ||
login_as user, scope: :user | ||
visit_component | ||
end | ||
|
||
it "has callout" do | ||
within ".callout.warning" do | ||
expect(page).to have_content("Create answer codes here") | ||
end | ||
end | ||
|
||
context "when codes are available" do | ||
let(:resource) { survey } | ||
|
||
it "has callout" do | ||
within ".callout.alert" do | ||
expect(page).to have_content("This survey can only be answered by using a valid code") | ||
end | ||
end | ||
end | ||
|
||
context "when not a surveys component" do | ||
let(:component) { create :proposal_component } | ||
|
||
it "has no callout" do | ||
expect(page).not_to have_css(".callout") | ||
end | ||
end | ||
end |