Skip to content
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ must now set a resource name:
- **decidim-participatory_processes**: Remove duplicated space title on page meta tags [\#3278](https://github.com/decidim/decidim/pull/3278)
- **decidim-assemblies**: Remove duplicated space title on page meta tags [\#3278](https://github.com/decidim/decidim/pull/3278)
- **decidim-core**: Add validation to nickname's length. [\#3342](https://github.com/decidim/decidim/pull/3342)
- **decidim-initiatives**: Fix user signing of initiatives [\#3513](https://github.com/decidim/decidim/pull/3513)
- **decidim-core**: Make admin link on user menu stop disappearing [\#3508](https://github.com/decidim/decidim/pull/3508)
- **decidim-core**: Sort static pages by title [\#3479](https://github.com/decidim/decidim/pull/3479)
- **decidim-core**: Data picker form inputs having no bottom margin. [\#3463](https://github.com/decidim/decidim/pull/3463)
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,8 @@ module Initiatives
class CommitteeRequestsController < Decidim::Initiatives::ApplicationController
include Decidim::Initiatives::NeedsInitiative

helper Decidim::ActionAuthorizationHelper
helper InitiativeHelper

include Decidim::Initiatives::ActionAuthorization

layout "layouts/decidim/application"

# GET /initiatives/:initiative_id/committee_requests/new
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,11 @@ class InitiativeVotesController < Decidim::Initiatives::ApplicationController

before_action :authenticate_user!

helper Decidim::ActionAuthorizationHelper
helper InitiativeHelper
include Decidim::Initiatives::ActionAuthorization

# POST /initiatives/:initiative_id/initiative_vote
def create
enforce_permission_to :vote, :initiative, initiative: current_initiative
enforce_permission_to :vote, :initiative, initiative: current_initiative, group_id: params[:group_id]
VoteInitiative.call(current_initiative, current_user, params[:group_id]) do
on(:ok) do
current_initiative.reload
Expand All @@ -31,7 +29,7 @@ def create

# DELETE /initiatives/:initiative_id/initiative_vote
def destroy
enforce_permission_to :unvote, :initiative, initiative: current_initiative
enforce_permission_to :unvote, :initiative, initiative: current_initiative, group_id: params[:group_id]
UnvoteInitiative.call(current_initiative, current_user, params[:group_id]) do
on(:ok) do
current_initiative.reload
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ class InitiativesController < Decidim::Initiatives::ApplicationController
helper Decidim::AttachmentsHelper
helper Decidim::FiltersHelper
helper Decidim::OrdersHelper
helper Decidim::ActionAuthorizationHelper
helper Decidim::ResourceHelper
helper Decidim::IconHelper
helper Decidim::Comments::CommentsHelper
Expand All @@ -20,7 +19,6 @@ class InitiativesController < Decidim::Initiatives::ApplicationController
helper InitiativeHelper
include InitiativeSlug

include Decidim::Initiatives::ActionAuthorization
include FilterResource
include Paginable
include Orderable
Expand Down
6 changes: 3 additions & 3 deletions decidim-initiatives/app/models/decidim/initiative.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,12 @@ class Initiative < ApplicationRecord
scope :public_spaces, -> { published }

scope :order_by_most_recent, -> { order(created_at: :desc) }
scope :order_by_supports, -> { order("initiative_votes_count + coalesce(offline_votes, 0) desc") }
scope :order_by_supports, -> { order(Arel.sql("initiative_votes_count + coalesce(offline_votes, 0) desc")) }
scope :order_by_most_commented, lambda {
select("decidim_initiatives.*")
.left_joins(:comments)
.group("decidim_initiatives.id")
.order("count(decidim_comments_comments.id) desc")
.order(Arel.sql("count(decidim_comments_comments.id) desc"))
}

after_save :notify_state_change
Expand Down Expand Up @@ -224,7 +224,7 @@ def hashtag

def supports_count
face_to_face_votes = offline_votes.nil? || online? ? 0 : offline_votes
digital_votes = offline? ? 0 : initiative_votes_count
digital_votes = offline? ? 0 : (initiative_votes_count + initiative_supports_count)
digital_votes + face_to_face_votes
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,9 @@
spawn_initiative_committee_requests_path(current_initiative),
class: "title-action__action button small hollow" if current_user %>

<%= action_authorized_link_to :spawn,
t(".continue"),
spawn_initiative_committee_requests_path(current_initiative),
class: "title-action__action button small hollow" unless current_user %>
<%= link_to t(".continue"),
spawn_initiative_committee_requests_path(current_initiative),
class: "title-action__action button small hollow" unless current_user %>
</div>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<%= render partial: "count" %>
</h2>
<% if allowed_to? :create, :initiative %>
<%= action_authorized_link_to :create, create_initiative_path(:select_initiative_type), class: "title-action__action button small hollow" do %>
<%= link_to create_initiative_path(:select_initiative_type), class: "title-action__action button small hollow" do %>
<%= t(".new_initiative") %>
<%= icon "plus" %>
<% end %>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
<% if allowed_to? :vote, :initiative, initiative: initiative %>
<%= action_authorized_button_to :vote,
vote_label,
initiative_initiative_vote_path(initiative_slug: initiative.slug),
remote: true,
data: { disable: true },
class: "card__button button expanded button--sc" %>
<%= button_to(
vote_label,
initiative_initiative_vote_path(initiative_slug: current_initiative.slug),
remote: true,
data: { disable: true },
class: "card__button button expanded button--sc"
) %>
<% end %>

<% if allowed_to? :unvote, :initiative, initiative: initiative %>
<%= action_authorized_button_to :vote,
unvote_label,
initiative_initiative_vote_path(initiative_slug: initiative.slug),
method: :delete,
remote: true,
data: { disable: true },
class: "card__button button expanded button--sc success" %>
<%= button_to(
vote_label,
initiative_initiative_vote_path(initiative_slug: current_initiative.slug),
method: :delete,
remote: true,
data: { disable: true },
class: "card__button button expanded button--sc success"
) %>
<% end %>
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,21 @@
<% current_user.user_groups.verified.each do |g| %>
<br />
<% if @voted_groups.include? g.id %>
<%= action_authorized_button_to :vote,
g.name,
initiative_initiative_vote_path(initiative_slug: current_initiative.slug, group_id: g.id),
method: :delete,
remote: true,
data: { disable: true },
class: "card__button button expanded button--sc success" %>
<%= button_to(
g.name,
initiative_initiative_vote_path(initiative_slug: current_initiative.slug, group_id: g.id),
method: :delete,
remote: true,
data: { disable: true },
class: "card__button button expanded button--sc success"
) %>
<% else %>
<%= action_authorized_button_to :vote,
g.name,
initiative_initiative_vote_path(initiative_slug: current_initiative.slug, group_id: g.id),
remote: true,
data: { disable: true },
class: "card__button button expanded button--sc" %>
<%= button_to(
g.name,
initiative_initiative_vote_path(initiative_slug: current_initiative.slug, group_id: g.id),
remote: true,
data: { disable: true },
class: "card__button button expanded button--sc"
) %>
<% end %>
<% end %>
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
published_at { Time.current }
state "published"
signature_type "online"
signature_start_time { Time.now.utc }
signature_start_time { Time.now.utc - 1.hour }
signature_end_time { Time.now.utc + 120.days }

scoped_type do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ module Initiatives

context "when basic search works" do
it "request returns OK" do
expect(response).to be_success
expect(response).to be_successful
end

it "result has id" do
Expand Down
78 changes: 78 additions & 0 deletions decidim-initiatives/spec/system/initiative_signing_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# frozen_string_literal: true

require "spec_helper"

describe "Initiative signing", type: :system do
let(:organization) { create(:organization) }
let(:initiative) do
create(:initiative, :published, organization: organization)
end
let(:authorized_user) { create(:user, :confirmed, organization: organization) }

before do
allow(Decidim::Initiatives)
.to receive(:do_not_require_authorization)
.and_return(true)
switch_to_host(organization.host)
login_as authorized_user, scope: :user
end

context "when the user has not signed the initiative yet and signs it" do
context "when the user has a verified user group" do
let!(:user_group) { create :user_group, :verified, users: [authorized_user], organization: authorized_user.organization }

it "votes as a user group" do
vote_initiative(user_name: user_group.name)
end

it "votes as themselves" do
vote_initiative(user_name: authorized_user.name)
end
end

it "adds the signature" do
vote_initiative
end
end

context "when the user has signed the initiative and unsigns it" do
context "when the user has a verified user group" do
let!(:user_group) { create :user_group, :verified, users: [authorized_user], organization: authorized_user.organization }

it "removes the signature" do
vote_initiative(user_name: user_group.name)

click_button user_group.name

within ".view-side" do
expect(page).to have_content("0\nSIGNATURE")
end
end
end

it "removes the signature" do
vote_initiative

within ".view-side" do
expect(page).to have_content("1\nSIGNATURE")
click_button "Sign"
expect(page).to have_content("0\nSIGNATURE")
end
end
end

def vote_initiative(user_name: nil)
visit decidim_initiatives.initiative_path(initiative)

within ".view-side" do
expect(page).to have_content("0\nSIGNATURE")
click_button "Sign"
end

click_button user_name if user_name.present?

within ".view-side" do
expect(page).to have_content("1\nSIGNATURE")
end
end
end