From 67904c5ad03d25b9e912aa545d8f565a9591c13c Mon Sep 17 00:00:00 2001 From: Joonas Date: Mon, 30 Sep 2024 16:48:23 +0300 Subject: [PATCH] Fix admin edit bug with official proposals --- .../privacy/coauthorable_extensions.rb | 2 +- spec/system/admin/proposals_spec.rb | 33 +++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 spec/system/admin/proposals_spec.rb diff --git a/app/models/concerns/decidim/privacy/coauthorable_extensions.rb b/app/models/concerns/decidim/privacy/coauthorable_extensions.rb index e2c31ec..6b17500 100644 --- a/app/models/concerns/decidim/privacy/coauthorable_extensions.rb +++ b/app/models/concerns/decidim/privacy/coauthorable_extensions.rb @@ -18,7 +18,7 @@ def authors authors = authors.flat_map do |klass, ids| klass.constantize.where(id: ids) end - @authors = authors.filter { |author| author.is_a?(Decidim::User) && !author.published_at.nil? }.compact.uniq + @authors = authors.filter { |author| !author.is_a?(Decidim::User) || author.published_at.present? }.compact.uniq end end end diff --git a/spec/system/admin/proposals_spec.rb b/spec/system/admin/proposals_spec.rb new file mode 100644 index 0000000..fdadc18 --- /dev/null +++ b/spec/system/admin/proposals_spec.rb @@ -0,0 +1,33 @@ +# frozen_string_literal: true + +require "spec_helper" +require "decidim/privacy/test/rspec_support/component" + +describe "Proposals" do + include ComponentTestHelper + + let!(:organization) { create(:organization) } + let!(:participatory_process) { create(:participatory_process, :with_steps, organization:) } + let!(:user) { create(:user, :admin, :confirmed, organization:) } + let!(:proposal) { create(:proposal, :official, :published, component:) } + + before do + switch_to_host(organization.host) + login_as user, scope: :user + visit decidim_admin.root_path + end + + context "when trying to edit an official proposal" do + let!(:component) { create(:proposal_component, :with_creation_enabled, participatory_space: participatory_process) } + + it "lets the admin user to edit" do + click_on "Processes" + click_on participatory_process.title["en"] + click_on "Proposals" + expect(page).to have_content(proposal.title["en"]) + within("a.action-icon--edit-proposal") do + expect(page).to have_css('svg[aria-label="Edit proposal"]') + end + end + end +end