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

Allow users to edit proposals after imports #234

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
1 change: 1 addition & 0 deletions app/forms/decidim/decidim_awesome/admin/config_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class ConfigForm < Decidim::Form
attribute :allow_images_in_full_editor, Boolean
attribute :allow_images_in_small_editor, Boolean
attribute :allow_images_in_proposals, Boolean
attribute :allow_to_edit_proposals_after_import, Boolean
attribute :use_markdown_editor, Boolean
attribute :allow_images_in_markdown_editor, Boolean
attribute :auto_save_forms, Boolean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def check(status)
def menus
@menus ||= {
editors: config_enabled?([:allow_images_in_full_editor, :allow_images_in_small_editor, :use_markdown_editor, :allow_images_in_markdown_editor]),
proposals: config_enabled?([:allow_images_in_proposals,
proposals: config_enabled?([:allow_images_in_proposals, :allow_to_edit_proposals_after_import,
:validate_title_min_length, :validate_title_max_caps_percent,
:validate_title_max_marks_together, :validate_title_start_with_caps,
:validate_body_min_length, :validate_body_max_caps_percent,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# frozen_string_literal: true

module Decidim
module DecidimAwesome
module Admin
module PermissionsOverride
extend ActiveSupport::Concern

included do
private

def admin_edition_is_available?
return unless proposal

if proposal_imported? && allow_to_edit_proposals_after_import_enabled?
true
else
(proposal.official? || proposal.official_meeting?) && proposal.votes.empty?
end
end

def proposal_imported?
Decidim::ResourceLink.exists?(
name: "copied_from_component",
to_type: "Decidim::Proposals::Proposal",
to_id: proposal.id
)
end

def allow_to_edit_proposals_after_import_enabled?
Decidim::DecidimAwesome::AwesomeConfig.find_by(var: :allow_to_edit_proposals_after_import)&.value == true
end
end
end
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@
<% end %>
</div>

<% if config_enabled? :allow_to_edit_proposals_after_import %>
<p class="text-info"><%= t("edit_proposals_after_import", scope: "decidim.decidim_awesome.admin.config") %></p>

<%= form.check_box :allow_to_edit_proposals_after_import %>
<p class="help-text"><%= t("help.allow_to_edit_proposals_after_import", scope: "decidim.decidim_awesome.admin.config.form") %></p>
<% end %>

<% if config_enabled? %i(validate_title_min_length validate_title_max_caps_percent validate_title_max_marks_together validate_title_start_with_caps) %>
</div> <!-- .card-section -->
</div><!-- .card -->
Expand Down
5 changes: 5 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,9 @@ en:
destroy_scoped_style:
error: Error removing CSS box! %{error}
success: CSS box %{key} removed successfully
edit_proposals_after_import: When proposals are imported between components,
not the original or the duplciated can be edited by the owners. This setting
changes that
form:
edit_label: Rename label
errors:
Expand All @@ -227,6 +230,8 @@ en:
editor, available to any user
allow_images_in_small_editor: This will add an image uploader icon in
all the editors WYSIWYG with minimal options in the toolbar enabled.
allow_to_edit_proposals_after_import: Other component settings still
apply (time limit, owner only, etc)
auto_save_forms: This will use LocalStorage to automatically save data
introduced by users in surveys and other forms while they are filling
it. Data will be restored in a future visit with the same browser
Expand Down
4 changes: 4 additions & 0 deletions lib/decidim/decidim_awesome/awesome.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ module DecidimAwesome
false
end

config_accessor :allow_to_edit_proposals_after_import do
true
antopalidi marked this conversation as resolved.
Show resolved Hide resolved
end

config_accessor :use_markdown_editor do
false
end
Expand Down
2 changes: 2 additions & 0 deletions lib/decidim/decidim_awesome/checksums.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ decidim-proposals:
decidim-0.27: c0ebeac39ebe4926bf0e5fc585a384d7
decidim-0.27.1: a4f902d1c4829a7f7f62299686f8604e
decidim-0.27.3: a9c9ed5eedaf7bf80afaf9ff5a89c254
/app/permissions/decidim/proposals/admin/permissions.rb:
decidim-0.27.3: 751b15ced553b17b7203f66a0152fb75
/app/views/decidim/proposals/collaborative_drafts/_edit_form_fields.html.erb:
# this file is not overriden anymore but it needs to be the last version
decidim-0.26: 519a0d34a9ffbd8b9c26d9b68ff4e2a3
Expand Down
3 changes: 3 additions & 0 deletions lib/decidim/decidim_awesome/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ class Engine < ::Rails::Engine
Decidim::Proposals::ProposalWizardCreateStepForm.include(Decidim::DecidimAwesome::Proposals::ProposalWizardCreateStepFormOverride)
end

# override admin's permissions to edit proposals after import
Decidim::Proposals::Admin::Permissions.include(Decidim::DecidimAwesome::Admin::PermissionsOverride) if DecidimAwesome.enabled?(:allow_to_edit_proposals_after_import)

# override user's admin property
Decidim::User.include(Decidim::DecidimAwesome::UserOverride) if DecidimAwesome.enabled?(:scoped_admins)

Expand Down
1 change: 1 addition & 0 deletions lib/decidim/decidim_awesome/test/initializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
:allow_images_in_full_editor,
:allow_images_in_small_editor,
:allow_images_in_proposals,
:allow_to_edit_proposals_after_import,
:use_markdown_editor,
:allow_images_in_markdown_editor,
:auto_save_forms,
Expand Down
1 change: 1 addition & 0 deletions spec/awesome_summary_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
let!(:allow_images_in_proposals) { create(:awesome_config, organization: organization, var: :allow_images_in_proposals, value: true) }
let!(:allow_images_in_small_editor) { create(:awesome_config, organization: organization, var: :allow_images_in_small_editor, value: true) }
let!(:allow_images_in_full_editor) { create(:awesome_config, organization: organization, var: :allow_images_in_full_editor, value: true) }
let!(:allow_to_edit_proposals_after_import) { create(:awesome_config, organization: organization, var: :allow_to_edit_proposals_after_import, value: true) }
let!(:use_markdown_editor) { create(:awesome_config, organization: organization, var: :use_markdown_editor, value: true) }
let!(:allow_images_in_markdown_editor) { create(:awesome_config, organization: organization, var: :allow_images_in_markdown_editor, value: true) }
let!(:auto_save_forms) { create(:awesome_config, organization: organization, var: :auto_save_forms, value: true) }
Expand Down
1 change: 1 addition & 0 deletions spec/controllers/admin/config_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ module Admin
context "and proposals is disabled" do
let(:disabled) do
editors + [:allow_images_in_proposals,
:allow_to_edit_proposals_after_import,
:validate_title_min_length,
:validate_title_max_caps_percent,
:validate_title_max_marks_together,
Expand Down
2 changes: 1 addition & 1 deletion spec/lib/system_checker_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ module Decidim::DecidimAwesome
end

it "has 5 modified files in proposals" do
expect(subject.overrides["decidim-proposals"].files.length).to eq(5)
expect(subject.overrides["decidim-proposals"].files.length).to eq(6)
end

context "when file" do
Expand Down
4 changes: 2 additions & 2 deletions spec/system/admin/admin_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -138,15 +138,15 @@
end

context "when some proposals hacks are disabled" do
[:allow_images_in_proposals, :validate_title_min_length, :validate_title_max_caps_percent, :validate_title_max_marks_together, :validate_title_start_with_caps, :validate_body_min_length, :validate_body_max_caps_percent, :validate_body_max_marks_together, :validate_body_start_with_caps].each do |var|
[:allow_images_in_proposals, :allow_to_edit_proposals_after_import, :validate_title_min_length, :validate_title_max_caps_percent, :validate_title_max_marks_together, :validate_title_start_with_caps, :validate_body_min_length, :validate_body_max_caps_percent, :validate_body_max_marks_together, :validate_body_start_with_caps].each do |var|
let(:disabled_features) { [var] }

it_behaves_like "has menu link", "proposals"
end
end

context "when all proposals hacks are disabled" do
let(:disabled_features) { [:allow_images_in_proposals, :validate_title_min_length, :validate_title_max_caps_percent, :validate_title_max_marks_together, :validate_title_start_with_caps, :validate_body_min_length, :validate_body_max_caps_percent, :validate_body_max_marks_together, :validate_body_start_with_caps] }
let(:disabled_features) { [:allow_images_in_proposals, :allow_to_edit_proposals_after_import, :validate_title_min_length, :validate_title_max_caps_percent, :validate_title_max_marks_together, :validate_title_start_with_caps, :validate_body_min_length, :validate_body_max_caps_percent, :validate_body_max_marks_together, :validate_body_start_with_caps] }

it_behaves_like "do not have menu link", "proposals"
end
Expand Down
60 changes: 60 additions & 0 deletions spec/system/admin/edit_proposal_after_import_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# frozen_string_literal: true

require "spec_helper"

describe "Edit proposal after import", type: :system do
let!(:organization) { create(:organization) }
let(:manifest_name) { "proposals" }
let(:participatory_space) { create(:participatory_process, organization: organization) }
let!(:component) { create(:proposal_component, organization: organization, participatory_space: participatory_space) }
let!(:original_component) { create(:proposal_component, organization: organization, participatory_space: participatory_space) }
let!(:proposals) { create_list(:proposal, 3, :accepted, component: component) }
let(:user) { create :user, organization: organization }
let!(:allow_to_edit_proposals_after_import) { create(:awesome_config, organization: organization, var: :allow_to_edit_proposals_after_import, value: config_value) }

include_context "when managing a component as an admin"

before do
page.find("a", text: original_component.name["en"]).click
page.find(".imports").click
click_link "Import proposals from another component"

within ".import_proposals" do
select component.name["en"], from: "Origin component"
check "Accepted"
check "Keep original authors"
check "Import proposals"
end

click_button "Import proposals"
end

context "when config is set to true" do
let(:config_value) { true }

it "allows the user to edit all 3 imported proposals" do
page.find("a", text: component.name["en"]).click

proposals.each do |proposal|
expect(page).to have_content(proposal.title["en"])
end

expect(page).to have_css('a[title="Edit proposal"]', count: 3)
expect(Decidim::Proposals::Proposal.count).to eq(6)
end
end

context "when config is set to false" do
let(:config_value) { false }

it "allows the user to edit all 3 imported proposals" do
page.find("a", text: component.name["en"]).click

proposals.each do |proposal|
expect(page).to have_content(proposal.title["en"])
end

expect(page).not_to have_css('a[title="Edit proposal"]')
end
end
end
Loading