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

release: Add simple proposals and Awesome private fields for proposals #45

Merged
merged 18 commits into from
Nov 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@ gem "decidim-templates", "~> #{DECIDIM_VERSION}.0"

# External Decidim gems
gem "decidim-cache_cleaner"
gem "decidim-decidim_awesome"
gem "decidim-simple_proposal", git: "https://github.com/mainio/decidim-module-simple_proposal", branch: DECIDIM_BRANCH
# TODO : Port the feature on official decidim-decidim_awesome repository and update this Gemfile
gem "decidim-decidim_awesome", git: "https://github.com/octree-gva/decidim-module-decidim_awesome.git", branch: "feat/awesome_decidim_private_fields"
gem "decidim-friendly_signup", git: "https://github.com/OpenSourcePolitics/decidim-module-friendly_signup.git"
gem "decidim-phone_authorization_handler", git: "https://github.com/OpenSourcePolitics/decidim-module_phone_authorization_handler", branch: DECIDIM_BRANCH
gem "decidim-phone_authorization_handler", git: "https://github.com/OpenSourcePolitics/decidim-module_phone_authorization_handler", branch: "0.26/without-exports"
gem "decidim-spam_detection"
gem "decidim-term_customizer", git: "https://github.com/armandfardeau/decidim-module-term_customizer.git", branch: "fix/precompile-on-docker-0.26"

Expand Down
39 changes: 27 additions & 12 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ GIT

GIT
remote: https://github.com/OpenSourcePolitics/decidim-module_phone_authorization_handler
revision: 488cc8827845ec1c5266aa499df2ebf9b20e02a3
branch: release/0.26-stable
revision: f81cb7163cf60ca91bcb7889afb9e18d729d44e4
branch: 0.26/without-exports
specs:
decidim-phone_authorization_handler (1.0.0)
decidim-core (~> 0.26)
Expand Down Expand Up @@ -37,6 +37,25 @@ GIT
decidim-admin (~> 0.26.0)
decidim-core (~> 0.26.0)

GIT
remote: https://github.com/mainio/decidim-module-simple_proposal
revision: b91e238151ec818896bb77d296313406adce7880
branch: release/0.26-stable
specs:
decidim-simple_proposal (0.26.0)
decidim-core (~> 0.26.0)
decidim-proposals (~> 0.26.0)

GIT
remote: https://github.com/octree-gva/decidim-module-decidim_awesome.git
revision: 21ce064a26837ba43835621ddb6f6773b14c59e8
branch: feat/awesome_decidim_private_fields
specs:
decidim-decidim_awesome (0.9.2)
decidim-admin (>= 0.26.0, < 0.28)
decidim-core (>= 0.26.0, < 0.28)
sassc (~> 2.3)

GIT
remote: https://github.com/sgruhier/foundation_rails_helper.git
revision: bc33600db7a2d16ce3cdc1f8369d0d7e7c4245b5
Expand Down Expand Up @@ -322,10 +341,6 @@ GEM
decidim-debates (0.26.7)
decidim-comments (= 0.26.7)
decidim-core (= 0.26.7)
decidim-decidim_awesome (0.8.3)
decidim-admin (>= 0.25.0, < 0.27)
decidim-core (>= 0.25.0, < 0.27)
sassc (~> 2.3)
decidim-dev (0.26.7)
axe-core-rspec (~> 4.1.0)
byebug (~> 11.0)
Expand Down Expand Up @@ -569,7 +584,6 @@ GEM
mime-types-data (3.2022.0105)
mini_magick (4.11.0)
mini_mime (1.1.2)
mini_portile2 (2.8.0)
minitest (5.16.3)
mixlib-cli (2.1.8)
mixlib-config (3.0.27)
Expand All @@ -581,8 +595,7 @@ GEM
multi_xml (0.6.0)
mustache (1.1.1)
nio4r (2.5.8)
nokogiri (1.13.4)
mini_portile2 (~> 2.8.0)
nokogiri (1.13.4-arm64-darwin)
racc (~> 1.4)
nokogiri (1.13.4-x86_64-darwin)
racc (~> 1.4)
Expand Down Expand Up @@ -930,7 +943,8 @@ GEM
zeitwerk (2.6.0)

PLATFORMS
ruby
arm64-darwin-21
arm64-darwin-22
x86_64-darwin-21
x86_64-linux

Expand All @@ -944,10 +958,11 @@ DEPENDENCIES
dalli
decidim (~> 0.26.0)
decidim-cache_cleaner
decidim-decidim_awesome
decidim-decidim_awesome!
decidim-dev (~> 0.26.0)
decidim-friendly_signup!
decidim-phone_authorization_handler!
decidim-simple_proposal!
decidim-spam_detection
decidim-templates (~> 0.26.0)
decidim-term_customizer!
Expand Down Expand Up @@ -983,4 +998,4 @@ RUBY VERSION
ruby 2.7.5p203

BUNDLED WITH
2.4.6
2.4.9
12 changes: 6 additions & 6 deletions OVERLOADS.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,6 @@
## Load decidim-awesome assets only if dependencie is present
* `app/views/layouts/decidim/_head.html.erb:33`

## Fix geocoded proposals
* `app/controllers/decidim/proposals/proposals_controller.rb:44`
```ruby
@all_geocoded_proposals = @base_query.geocoded.where.not(latitude: Float::NAN, longitude: Float::NAN)
```

## Fix meetings orders in indexes
* `app/controllers/decidim/meetings/meetings_controller.rb`
* `app/controllers/decidim/meetings/directory/meetings_controller.rb`
Expand Down Expand Up @@ -175,3 +169,9 @@ d71197d - Add nil safety in migrate task, 2022-04-20

* `lib/decidim/test/promoted_participatory_processes_shared_examples.rb`
f12c07d - Bump Develop on 0.25 (#104), 2022-05-10

* `app/views/decidim/proposals/proposals/_edit_form_fields.html.erb`
Modified from https://github.com/mainio/decidim-module-simple_proposal/blob/85ddd5f9519dc7d1e325a9776d6d5f134caf5943/app/views/decidim/proposals/proposals/_edit_form_fields.html.erb

* `app/controllers/concerns/decidim/simple_proposal/proposals_controller_override.rb`
Modified from https://github.com/mainio/decidim-module-simple_proposal/blob/85ddd5f9519dc7d1e325a9776d6d5f134caf5943/app/controllers/concerns/decidim/simple_proposal/proposals_controller_override.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,200 @@
# frozen_string_literal: true

module Decidim
module SimpleProposal
module ProposalsControllerOverride
extend ActiveSupport::Concern

included do
def index
if component_settings.participatory_texts_enabled?
@proposals = ::Decidim::Proposals::Proposal
.where(component: current_component, deleted_at: nil)
.published
.not_hidden
.only_amendables
.includes(:category, :scope)
.order(position: :asc)
render "decidim/proposals/proposals/participatory_texts/participatory_text"
else
@base_query = search
.results
.where(deleted_at: nil)
.published
.not_hidden

@proposals = @base_query.includes(:component, :coauthorships)
@all_geocoded_proposals = @base_query.geocoded
.where.not(latitude: Float::NAN)
.where.not(longitude: Float::NAN)

@voted_proposals = if current_user
::Decidim::Proposals::ProposalVote.where(
author: current_user,
proposal: @proposals.pluck(:id)
).pluck(:decidim_proposal_id)
else
[]
end
@proposals = paginate(@proposals)
@proposals = reorder(@proposals)
end
end

def new
if proposal_draft.present?
redirect_to edit_draft_proposal_path(proposal_draft, component_id: proposal_draft.component.id, question_slug: proposal_draft.component.participatory_space.slug)
else
enforce_permission_to :create, :proposal
@step = :step_1
@proposal ||= Decidim::Proposals::Proposal.new(component: current_component)
@form = form_proposal_model
@form.body = translated_proposal_body_template
@form.attachment = form_attachment_new
end
end

def create
enforce_permission_to :create, :proposal
@step = :step_1
@form = form(Decidim::Proposals::ProposalForm).from_params(proposal_creation_params)

@proposal = Decidim::Proposals::Proposal.new(@form.attributes.except(
:user_group_id,
:category_id,
:scope_id,
:has_address,
:attachment,
:body_template,
:suggested_hashtags,
:photos,
:add_photos,
:documents,
:add_documents
).merge(
component: current_component
))
user_group = Decidim::UserGroup.find_by(
organization: current_organization,
id: params[:proposal][:user_group_id]
)
@proposal.add_coauthor(current_user, user_group: user_group)

# We could set these when creating proposal, but We want to call update because after that proposal becomes persisted
# and it adds coauthor correctly.
@proposal.update(title: { I18n.locale => @form.attributes[:title] })
@proposal.update(
body: { I18n.locale => @form.attributes[:body] },
private_body: { I18n.locale => @form.attributes[:private_body] }
)

Decidim::Proposals::UpdateProposal.call(@form, current_user, @proposal) do
on(:ok) do |proposal|
flash[:notice] = I18n.t("proposals.update_draft.success", scope: "decidim")
redirect_to "#{Decidim::ResourceLocatorPresenter.new(proposal).path}/preview"
end

on(:invalid) do
flash.now[:alert] = I18n.t("proposals.update_draft.error", scope: "decidim")
render :new
end
end
end

# Overridden because of a core bug when the command posts the "invalid"
# signal and when rendering the form.
def update_draft
enforce_permission_to :edit, :proposal, proposal: @proposal
@step = :step_1

@form = form_proposal_params
Decidim::Proposals::UpdateProposal.call(@form, current_user, @proposal) do
on(:ok) do |proposal|
flash[:notice] = I18n.t("proposals.update_draft.success", scope: "decidim")
redirect_to "#{Decidim::ResourceLocatorPresenter.new(proposal).path}/preview"
end

on(:invalid) do
flash.now[:alert] = I18n.t("proposals.update_draft.error", scope: "decidim")
fix_form_photos_and_documents
render :edit_draft
end
end
end

# On invalid render edit instead of edit_draft
def update
enforce_permission_to :edit, :proposal, proposal: @proposal

@form = form_proposal_params

Decidim::Proposals::UpdateProposal.call(@form, current_user, @proposal) do
on(:ok) do |proposal|
flash[:notice] = I18n.t("proposals.update.success", scope: "decidim")
redirect_to Decidim::ResourceLocatorPresenter.new(proposal).path
end

on(:invalid) do
flash.now[:alert] = I18n.t("proposals.update.error", scope: "decidim")
fix_form_photos_and_documents
render :edit
end
end
end

private

def form_proposal_params
form(Decidim::Proposals::ProposalForm).from_params(params)
end

def default_filter_params
{
search_text: "",
origin: default_filter_origin_params,
activity: "all",
category_id: default_filter_category_params,
state: %w(accepted evaluating state_not_published not_answered rejected),
scope_id: default_filter_scope_params,
related_to: "",
type: "all"
}
end

def can_show_proposal?
return false if @proposal&.deleted_at.present?
return true if @proposal&.amendable? || current_user&.admin?

Decidim::Proposals::Proposal.only_visible_emendations_for(current_user, current_component).published.include?(@proposal)
end

def fix_form_photos_and_documents
return unless @form

@form.photos = map_attachment_objects(@form.photos)
@form.documents = map_attachment_objects(@form.documents)
end

# Maps the attachment objects for the proposal form in case there are errors
# on the form when it is being saved. Without this, the form would throw
# an exception because it expects these objects to be Attachment records.
def map_attachment_objects(attachments)
return attachments unless attachments.is_a?(Array)

attachments.map do |attachment|
if attachment.is_a?(String) || attachment.is_a?(Integer)
Decidim::Attachment.find_by(id: attachment)
else
attachment
end
end
end

# TODO: Remove after feature/configurable_order_for_proposals is merged!
# def default_order
# "recent"
# end
end
end
end
end
Loading
Loading