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

Fix proposal states diff renderer #12660

Draft
wants to merge 4 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 19 additions & 0 deletions decidim-proposals/app/services/decidim/proposals/diff_renderer.rb
Expand Up @@ -22,6 +22,7 @@ def attribute_types
# Parses the values before parsing the changeset.
def parse_changeset(attribute, values, type, diff)
return parse_scope_changeset(attribute, values, type, diff) if type == :scope
return parse_state_changeset(attribute, values, type, diff) if attribute == :decidim_proposals_proposal_state_id

values = parse_values(attribute, values)
old_value = values[0]
Expand All @@ -37,6 +38,24 @@ def parse_changeset(attribute, values, type, diff)
)
end


def parse_state_changeset(attribute, values, type, diff)
return unless diff

old_state = Decidim::Proposals::ProposalState.find_by(id: values[0])
new_state = Decidim::Proposals::ProposalState.find_by(id: values[1])

diff.update(
attribute => {
type:,
label: I18n.t(attribute, scope: i18n_scope),
old_value: old_state ? translated_attribute(old_state.title) : "",
new_value: new_state ? translated_attribute(new_state.title) : ""
}
)
end


# Handles which values to use when diffing emendations and
# normalizes line endings of the :body attribute values.
# Returns and Array of two Strings.
Expand Down
2 changes: 2 additions & 0 deletions decidim-proposals/config/locales/en.yml
@@ -1,5 +1,6 @@
---
en:

activemodel:
attributes:
collaborative_draft:
Expand All @@ -13,6 +14,7 @@ en:
title: Title
user_group_id: Create collaborative draft as
proposal:
decidim_proposals_proposal_state_id: State
address: Address
answer: Answer
answered_at: Answered at
Expand Down