diff --git a/app/views/decidim/initiatives/admin/initiatives/_form.html.erb b/app/views/decidim/initiatives/admin/initiatives/_form.html.erb new file mode 100644 index 0000000000..52d016b9db --- /dev/null +++ b/app/views/decidim/initiatives/admin/initiatives/_form.html.erb @@ -0,0 +1,133 @@ +
+
+

<%= t ".title" %>

+
+ +
+
+ <%= form.translated :text_field, :title, autofocus: true, disabled: !allowed_to?(:update, :initiative, initiative: current_initiative) %> +
+ +
+ <%= form.translated :editor, :description, lines: 8, disabled: !allowed_to?(:update, :initiative, initiative: current_initiative) %> +
+ +
+
+ <%= form.text_field :hashtag, disabled: !allowed_to?(:update, :initiative, initiative: current_initiative) %> +
+
+
+
+ +
+
+

<%= t ".settings" %>

+
+ +
+
+
+ <%= form.select :state, + Decidim::Initiative.states.keys.map { |state| [I18n.t(state, scope: "decidim.initiatives.admin_states"), state] }, + {}, + { disabled: !@form.state_updatable? } %> +
+
+ +
+
+ <% unless single_initiative_type? %> + <%= form.select :type_id, + initiative_type_options, + {}, + { + disabled: !@form.signature_type_updatable?, + "data-scope-selector": "initiative_decidim_scope_id", + "data-scope-id": form.object.decidim_scope_id.to_s, + "data-scope-search-url": decidim_initiatives.initiative_type_scopes_search_url, + "data-signature-types-selector": "initiative_signature_type", + "data-signature-type": current_initiative.signature_type, + "data-signature-types-search-url": decidim_initiatives.initiative_type_signature_types_search_url + } %> +
+ <% else %> + <%= form.hidden_field :type_id, + { + disabled: !@form.signature_type_updatable?, + "data-scope-selector": "initiative_decidim_scope_id", + "data-scope-id": form.object.decidim_scope_id.to_s, + "data-scope-search-url": decidim_initiatives.initiative_type_scopes_search_url, + "data-signature-types-selector": "initiative_signature_type", + "data-signature-type": current_initiative.signature_type, + "data-signature-types-search-url": decidim_initiatives.initiative_type_signature_types_search_url + } %> + <% end %> +
+ <%= form.select :decidim_scope_id, [], {}, { disabled: !@form.signature_type_updatable? } %> +
+
+ + <% if current_initiative.published? && current_user.admin? %> +
+
+ <%= form.date_field :signature_start_date %> +
+ +
+ <%= form.date_field :signature_end_date %> +
+
+ <% end %> + + <% if can_edit_custom_signature_end_date?(current_initiative) %> +
+ <%= form.date_field :signature_end_date, disabled: !allowed_to?(:update, :initiative, initiative: current_initiative) %> +
+ <% end %> + + <% if current_initiative.area_enabled? %> +
+ <%= form.areas_select :area_id, + areas_for_select(current_organization), + { + selected: current_initiative.decidim_area_id, + include_blank: current_initiative.decidim_area_id.blank? || current_initiative.created? + }, + disabled: !@form.area_updatable? %> +
+ <% end %> + +
+
+ <%= form.select :signature_type, [], {}, { disabled: !@form.signature_type_updatable? } %> +
+
+ + <% if current_initiative.accepts_offline_votes? && current_user.admin? %> +
+
+ <% @form.offline_votes.each do |scope_id, (votes, scope_name)| %> + <%= label_tag "initiative_offline_votes_#{scope_id}", t("activemodel.attributes.initiative.offline_votes_for_scope", scope_name: translated_attribute(scope_name)) %> + <%= number_field_tag "initiative[offline_votes][#{scope_id}]", votes, min: 0, id: "initiative_offline_votes_#{scope_id}" %> + <% end %> +
+
+ <% end %> +
+
+
+
+

<%= t ".attachments" %>

+
+ +
+
+ <% if allowed_to?(:read, :attachment, initiative: current_participatory_space) %> + <%= render partial: "initiative_attachments", locals: { current_initiative: current_initiative, current_participatory_space: current_participatory_space } %> + <% end %> +
+
+
+ +<%= javascript_pack_tag "decidim_initiatives_admin" %> diff --git a/spec/shared/initiative_administration_shared_context.rb b/spec/shared/initiative_administration_shared_context.rb new file mode 100644 index 0000000000..abb44ddbf1 --- /dev/null +++ b/spec/shared/initiative_administration_shared_context.rb @@ -0,0 +1,20 @@ +# frozen_string_literal: true + +shared_context "when admins initiative" do + let(:organization) { create(:organization) } + let(:user) { create(:user, :admin, :confirmed, organization: organization) } + let(:author) { create(:user, :confirmed, organization: organization) } + let(:other_initiatives_type) { create(:initiatives_type, organization: organization, signature_type: "any") } + let!(:other_initiatives_type_scope) { create(:initiatives_type_scope, type: other_initiatives_type) } + + let(:initiative_type) { create(:initiatives_type, organization: organization) } + let(:initiative_scope) { create(:initiatives_type_scope, type: initiative_type) } + let!(:initiative) { create(:initiative, organization: organization, scoped_type: initiative_scope, author: author) } + + let(:image1_filename) { "city.jpeg" } + let(:image1_path) { Decidim::Dev.asset(image1_filename) } + let(:image2_filename) { "city2.jpeg" } + let(:image2_path) { Decidim::Dev.asset(image2_filename) } + let(:image3_filename) { "city3.jpeg" } + let(:image3_path) { Decidim::Dev.asset(image3_filename) } +end diff --git a/spec/system/admin/update_initiative_spec.rb b/spec/system/admin/update_initiative_spec.rb new file mode 100644 index 0000000000..ff65446f1b --- /dev/null +++ b/spec/system/admin/update_initiative_spec.rb @@ -0,0 +1,124 @@ +# frozen_string_literal: true + +require "spec_helper" + +describe "User prints the initiative", type: :system do + include_context "when admins initiative" + + def submit_and_validate + find("*[type=submit]").click + + within ".callout-wrapper" do + expect(page).to have_content("successfully") + end + end + + context "when initiative update" do + context "and user is admin" do + before do + switch_to_host(organization.host) + login_as user, scope: :user + visit decidim_admin_initiatives.initiatives_path + end + + it "Updates published initiative data" do + page.find(".action-icon--edit").click + within ".edit_initiative" do + fill_in :initiative_hashtag, with: "#hashtag" + end + submit_and_validate + end + + context "when initiative is in created state" do + before do + initiative.created! + end + + it "updates type, scope and signature type" do + page.find(".action-icon--edit").click + within ".edit_initiative" do + select translated(other_initiatives_type.title), from: "initiative_type_id" + select translated(other_initiatives_type_scope.scope.name), from: "initiative_decidim_scope_id" + select "In-person", from: "initiative_signature_type" + end + submit_and_validate + end + + it "displays initiative attachments" do + page.find(".action-icon--edit").click + expect(page).to have_link("Edit") + expect(page).to have_link("New") + end + end + + context "when initiative is in validating state" do + before do + initiative.validating! + end + + it "updates type, scope and signature type" do + page.find(".action-icon--edit").click + within ".edit_initiative" do + select translated(other_initiatives_type.title), from: "initiative_type_id" + select translated(other_initiatives_type_scope.scope.name), from: "initiative_decidim_scope_id" + select "In-person", from: "initiative_signature_type" + end + submit_and_validate + end + + it "displays initiative attachments" do + page.find(".action-icon--edit").click + expect(page).to have_link("Edit") + expect(page).to have_link("New") + end + end + + context "when initiative is in accepted state" do + before do + initiative.accepted! + end + + it "update of type, scope and signature type are disabled" do + page.find(".action-icon--edit").click + + within ".edit_initiative" do + expect(page).to have_css("#initiative_type_id[disabled]") + expect(page).to have_css("#initiative_decidim_scope_id[disabled]") + expect(page).to have_css("#initiative_signature_type[disabled]") + end + end + + it "displays initiative attachments" do + page.find(".action-icon--edit").click + expect(page).to have_link("Edit") + expect(page).to have_link("New") + end + end + + context "when there is a single initiative type" do + let!(:other_initiatives_type) { nil } + let!(:other_initiatives_type_scope) { nil } + + before do + initiative.created! + end + + it "update of type, scope and signature type are disabled" do + page.find(".action-icon--edit").click + + within ".edit_initiative" do + expect(page).not_to have_css("label[for='initiative_type_id']") + expect(page).not_to have_css("#initiative_type_id") + + expect(page).to have_css("label[for='initiative_decidim_scope_id']") + expect(page).to have_css("#initiative_decidim_scope_id") + expect(page).to have_css("option[value='#{initiative_scope.id}'][selected='selected']") + expect(page).to have_css("label[for='initiative_signature_type']") + expect(page).to have_css("#initiative_signature_type") + expect(page).to have_css("option[value='#{initiative.signature_type}'][selected='selected']") + end + end + end + end + end +end