Skip to content

Commit

Permalink
Backport decidim#4828 to 0.16 stable (decidim#4836)
Browse files Browse the repository at this point in the history
* Backport decidim#4828 to 0.16-stable

* Add CHANGELOG entry
  • Loading branch information
Aitor Lopez Beltran authored and oriolgual committed Feb 13, 2019
1 parent d587a42 commit f523607
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 48 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -17,6 +17,7 @@

**Fixed**:

- **decidim-proposals**: Fix Proposals Last Activity feed. [\#4836](https://github.com/decidim/decidim/pull/4836)
- **decidim-proposals**: Fix attachments not being inherited from collaborative draft when published as proposal. [\#4815](https://github.com/decidim/decidim/pull/4815)
- **decidim-proposals**: Fix participatory texts error uploading files with accents and special characters. [\#4801](https://github.com/decidim/decidim/pull/4801)
- **decidim-proposals** Public view of Participatory Text is now preserving new lines. [\#4801](https://github.com/decidim/decidim/pull/4801)
Expand Down
2 changes: 1 addition & 1 deletion decidim-core/app/commands/decidim/amendable/create.rb
Expand Up @@ -55,7 +55,7 @@ def emendation_attributes

def create_emendation!
@emendation = Decidim.traceability.perform_action!(
:create,
"publish",
form.amendable_type.constantize,
form.current_user,
visibility: "public-only"
Expand Down
Expand Up @@ -18,7 +18,7 @@
expect(Decidim.traceability)
.to receive(:perform_action!)
.with(
:create,
"publish",
form.amendable_type.constantize,
form.current_user,
kind_of(Hash)
Expand Down
43 changes: 21 additions & 22 deletions decidim-proposals/app/commands/decidim/proposals/create_proposal.rb
Expand Up @@ -43,29 +43,28 @@ def call

attr_reader :form, :proposal, :attachment

def proposal_attributes
fields = {}

fields[:title] = title_with_hashtags
fields[:body] = body_with_hashtags
fields[:component] = form.component

fields
end

# This will be the PaperTrail version that is
# shown in the version control feature (1 of 1)
# Prevent PaperTrail from creating an additional version
# in the proposal multi-step creation process (step 1: create)
#
# A first version will be created in step 4: publish
# for diff rendering in the proposal version control
def create_proposal
@proposal = Decidim.traceability.perform_action!(
:create,
Decidim::Proposals::Proposal,
@current_user,
visibility: "public-only"
) do
proposal = Proposal.new(proposal_attributes)
proposal.add_coauthor(@current_user, user_group: user_group)
proposal.save!
proposal
PaperTrail.request(enabled: false) do
@proposal = Decidim.traceability.perform_action!(
:create,
Decidim::Proposals::Proposal,
@current_user,
visibility: "public-only"
) do
proposal = Proposal.new(
title: title_with_hashtags,
body: body_with_hashtags,
component: form.component
)
proposal.add_coauthor(@current_user, user_group: user_group)
proposal.save!
proposal
end
end
end

Expand Down
Expand Up @@ -34,12 +34,34 @@ def call

private

# Prevent PaperTrail from creating an additional version
# in the proposal multi-step creation process (step 4: publish)
# This will be the PaperTrail version that is
# shown in the version control feature (1 of 1)
#
# For an attribute to appear in the new version it has to be reset
# and reassigned, as PaperTrail only keeps track of object CHANGES.
def publish_proposal
title = reset(:title)
body = reset(:body)

Decidim.traceability.perform_action!(
"publish",
@proposal,
@current_user,
visibility: "public-only"
) do
@proposal.update title: title, body: body, published_at: Time.current
end
end

# Reset the attribute to an empty string and return the old value
def reset(attribute)
attribute_value = @proposal[attribute]
PaperTrail.request(enabled: false) do
@proposal.update published_at: Time.current
# rubocop:disable Rails/SkipsModelValidations
@proposal.update_attribute attribute, ""
# rubocop:enable Rails/SkipsModelValidations
end
attribute_value
end

def send_notification
Expand Down
38 changes: 17 additions & 21 deletions decidim-proposals/app/commands/decidim/proposals/update_proposal.rb
Expand Up @@ -53,41 +53,37 @@ def call

attr_reader :form, :proposal, :current_user, :attachment

def proposal_attributes
fields = {}

fields[:title] = title_with_hashtags
fields[:body] = body_with_hashtags
fields[:category] = form.category
fields[:scope] = form.scope
fields[:address] = form.address
fields[:latitude] = form.latitude
fields[:longitude] = form.longitude

fields
end

# Prevent PaperTrail from creating an additional version
# in the proposal multi-step creation process (step 3: complete)
#
# A first version will be created in step 4: publish
# for diff rendering in the proposal control version
def update_draft
PaperTrail.request(enabled: false) do
@proposal.update(proposal_attributes)
@proposal.update(attributes)
@proposal.coauthorships.clear
@proposal.add_coauthor(current_user, user_group: user_group)
end
end

def update_proposal
@proposal = Decidim.traceability.update!(
@proposal,
current_user,
proposal_attributes,
visibility: "public-only"
)
@proposal.update!(attributes)
@proposal.coauthorships.clear
@proposal.add_coauthor(current_user, user_group: user_group)
end

def attributes
{
title: title_with_hashtags,
body: body_with_hashtags,
category: form.category,
scope: form.scope,
address: form.address,
latitude: form.latitude,
longitude: form.longitude
}
end

def proposal_limit_reached?
proposal_limit = form.current_component.settings.proposal_limit

Expand Down

0 comments on commit f523607

Please sign in to comment.