Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add proposal answer templates #37

Open
wants to merge 18 commits into
base: release/0.26-stable
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ def identify_templateable_resource
when "organizations"
@form.current_organization
when "components"
component = Decidim::Component.where(manifest_name: :proposals).find(resource.last)
component.participatory_space.decidim_organization_id == @form.current_organization.id ? component : nil
component = Decidim::Component.find_by(id: resource.last)
microstudi marked this conversation as resolved.
Show resolved Hide resolved
component&.participatory_space&.decidim_organization_id == @form.current_organization.id ? component : nil
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ def identify_templateable_resource
when "organizations"
@form.current_organization
when "components"
component = Decidim::Component.where(manifest_name: :proposals).find(resource.last)
component.participatory_space.decidim_organization_id == @form.current_organization.id ? component : nil
component = Decidim::Component.find_by(id: resource.last)
component&.participatory_space&.decidim_organization_id == @form.current_organization.id ? component : nil
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,10 @@ def proposal
end

def availability_option_as_text(template)
return unless template.templatable_type

key = "#{template.templatable_type.demodulize.tableize}-#{template.templatable_id}"
avaliablity_options.fetch(key)
avaliablity_options[key].presence || t("templates.missing_resource", scope: "decidim.admin")
end

def availability_options_for_select
Expand Down
1 change: 1 addition & 0 deletions decidim-templates/config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ en:
destroy:
success: Template deleted successfully
empty: There are no templates yet.
missing_resource: "(missing resource)"
update:
error: There was a problem upadting this template.
success: Template updated successfully
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,17 @@
expect(page).to have_i18n_content("Global (available everywhere)")
end
end

context "when a template is scoped to an invalid resource" do
let!(:template) { create(:template, :proposal_answer, organization: organization, templatable: create(:dummy_resource)) }

it "shows a table info about the invalid resource" do
within ".questionnaire-templates" do
expect(page).to have_i18n_content(template.name)
expect(page).to have_i18n_content("(missing resource)")
end
end
end
end

describe "creating a proposal_answer_template" do
Expand Down