decidim-restfull-proposals 0.3.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/app/controllers/decidim/api/rest_full/components/proposal_components_controller.rb +91 -0
- data/app/controllers/decidim/api/rest_full/draft_proposals/draft_proposals_controller.rb +116 -0
- data/app/controllers/decidim/api/rest_full/proposals/proposal_extended_data_controller.rb +31 -0
- data/app/controllers/decidim/api/rest_full/proposals/proposals_controller.rb +172 -0
- data/app/controllers/decidim/api/rest_full/vote_proposals/vote_proposals_controller.rb +90 -0
- data/app/jobs/decidim/rest_full/proposals/proposal_webhook_job.rb +67 -0
- data/app/models/decidim/rest_full/proposals/proposal_application_id.rb +14 -0
- data/app/serializers/decidim/api/rest_full/proposals/draft_proposal_serializer.rb +44 -0
- data/app/serializers/decidim/api/rest_full/proposals/proposal_component_serializer.rb +232 -0
- data/app/serializers/decidim/api/rest_full/proposals/proposal_serializer.rb +113 -0
- data/app/serializers/decidim/api/rest_full/proposals/proposal_state_serializer.rb +39 -0
- data/app/serializers/decidim/api/rest_full/proposals/proposal_webhook_serializer.rb +54 -0
- data/app/serializers/decidim/api/rest_full/proposals/vote_proposal_serializer.rb +27 -0
- data/app/services/decidim/rest_full/proposals/draft_proposals_operations.rb +248 -0
- data/app/services/decidim/rest_full/proposals/proposal_vote_eligibility.rb +106 -0
- data/app/services/decidim/rest_full/proposals/proposal_votes_operations.rb +173 -0
- data/app/services/decidim/rest_full/proposals/vote_proposals_operations.rb +114 -0
- data/config/locales/decidim_rest_full_proposals.en.yml +26 -0
- data/lib/decidim/rest_full/http_cache/proposal_show_fingerprint.rb +77 -0
- data/lib/decidim/rest_full/proposals/engine.rb +129 -0
- data/lib/decidim/rest_full/proposals/proposal_client_id_override.rb +18 -0
- data/lib/decidim/rest_full/proposals/proposals_controller_override.rb +28 -0
- data/lib/decidim/rest_full/proposals/ransackers.rb +84 -0
- data/lib/decidim/rest_full/proposals/test_definitions.rb +7 -0
- data/lib/decidim/rest_full/test/definitions/draft_proposal.rb +101 -0
- data/lib/decidim/rest_full/test/definitions/proposal.rb +115 -0
- data/lib/decidim/rest_full/test/definitions/proposal_component_schema.rb +110 -0
- data/lib/decidim/rest_full/test/definitions/proposals.rb +4 -0
- data/lib/decidim/rest_full/test/definitions/tags/draft_proposals_tag.rb +26 -0
- data/lib/decidim/rest_full/test/definitions/tags/proposal_tag.rb +32 -0
- data/lib/decidim/rest_full/test/definitions/vote_proposal.rb +87 -0
- data/lib/decidim-restfull-proposals.rb +17 -0
- data/spec/jobs/decidim/rest_full/proposals/proposal_webhook_job_spec.rb +66 -0
- data/spec/requests/decidim/api/rest_full/components/proposal_components_controller_index_spec.rb +149 -0
- data/spec/requests/decidim/api/rest_full/components/proposal_components_controller_show_spec.rb +140 -0
- data/spec/requests/decidim/api/rest_full/draft_proposals/draft_proposals_controller_create_spec.rb +116 -0
- data/spec/requests/decidim/api/rest_full/draft_proposals/draft_proposals_controller_delete_spec.rb +64 -0
- data/spec/requests/decidim/api/rest_full/draft_proposals/draft_proposals_controller_publish_spec.rb +132 -0
- data/spec/requests/decidim/api/rest_full/draft_proposals/draft_proposals_controller_show_spec.rb +72 -0
- data/spec/requests/decidim/api/rest_full/draft_proposals/draft_proposals_controller_update_spec.rb +307 -0
- data/spec/requests/decidim/api/rest_full/proposals/proposal_extended_data_controller_spec.rb +80 -0
- data/spec/requests/decidim/api/rest_full/proposals/proposals_controller_index_spec.rb +275 -0
- data/spec/requests/decidim/api/rest_full/proposals/proposals_controller_show_spec.rb +187 -0
- data/spec/requests/decidim/api/rest_full/scenarios/draft_publish_async_increments_count_and_lists_newest_spec.rb +144 -0
- data/spec/requests/decidim/api/rest_full/scenarios/participatory_process_phase_change_webhook_and_component_meta_spec.rb +130 -0
- data/spec/requests/decidim/api/rest_full/scenarios/proposals_published_at_desc_prev_next_chain_spec.rb +72 -0
- data/spec/requests/decidim/api/rest_full/scenarios/search_vote_enabled_impersonate_and_vote_spec.rb +88 -0
- data/spec/requests/decidim/api/rest_full/vote_proposals/vote_proposals_controller_spec.rb +231 -0
- data/spec/serializers/decidim/api/rest_full/proposals/proposal_component_serializer_chatbot_menu_spec.rb +147 -0
- data/spec/serializers/decidim/api/rest_full/proposals/proposal_component_serializer_phases_spec.rb +88 -0
- data/spec/serializers/decidim/api/rest_full/proposals/proposal_component_serializer_votes_spec.rb +103 -0
- data/spec/serializers/decidim/api/rest_full/proposals/proposal_serializer_can_vote_spec.rb +86 -0
- data/spec/serializers/decidim/api/rest_full/proposals/proposal_webhook_serializer_spec.rb +63 -0
- data/spec/services/decidim/rest_full/proposals/proposal_vote_eligibility_spec.rb +120 -0
- metadata +132 -0
data/spec/serializers/decidim/api/rest_full/proposals/proposal_component_serializer_phases_spec.rb
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# rubocop:disable RSpec/SpecFilePathFormat, RSpec/DescribeMethod -- descriptive scenario title alongside serializer class
|
|
4
|
+
require "swagger_helper"
|
|
5
|
+
|
|
6
|
+
RSpec.describe Decidim::Api::RestFull::Proposals::ProposalComponentSerializer,
|
|
7
|
+
"participatory process phases (PROPOSE vs VOTE)" do
|
|
8
|
+
let(:organization) { create(:organization, available_locales: %w(en)) }
|
|
9
|
+
let(:meta) { serialize.fetch(:data).fetch(:meta).symbolize_keys }
|
|
10
|
+
let(:participatory_process) { create(:participatory_process, organization:) }
|
|
11
|
+
let!(:propose_phase) { create(:participatory_process_step, :active, participatory_process:, position: 0) }
|
|
12
|
+
let!(:vote_phase) { create(:participatory_process_step, active: false, participatory_process:, position: 1) }
|
|
13
|
+
let(:user) { create(:user, organization:, confirmed_at: Time.zone.now) }
|
|
14
|
+
let(:api_client) { create(:api_client, organization:, scopes: ["public"]) }
|
|
15
|
+
|
|
16
|
+
let!(:proposal_component) do
|
|
17
|
+
create(
|
|
18
|
+
:proposal_component,
|
|
19
|
+
participatory_space: participatory_process,
|
|
20
|
+
step_settings: {
|
|
21
|
+
propose_phase.id.to_s => { creation_enabled: true, votes_enabled: false },
|
|
22
|
+
vote_phase.id.to_s => { creation_enabled: false, votes_enabled: true }
|
|
23
|
+
},
|
|
24
|
+
settings: { awesome_voting_manifest: :voting_cards }
|
|
25
|
+
)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def serialize(component = proposal_component.reload)
|
|
29
|
+
described_class.new(
|
|
30
|
+
component,
|
|
31
|
+
params: {
|
|
32
|
+
only: [],
|
|
33
|
+
locales: %w(en),
|
|
34
|
+
host: organization.host,
|
|
35
|
+
act_as: user,
|
|
36
|
+
client_id: api_client.id
|
|
37
|
+
}
|
|
38
|
+
).serializable_hash
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
describe "Scenario 1: active phase PROPOSE (no voting on step)" do
|
|
42
|
+
it "sets can_vote false and creation true" do
|
|
43
|
+
expect(meta[:votes_enabled]).to be(false)
|
|
44
|
+
expect(meta[:can_vote]).to be(false)
|
|
45
|
+
expect(meta[:creation_enabled]).to be(true)
|
|
46
|
+
expect(meta[:can_create_proposals]).to be(true)
|
|
47
|
+
expect(meta[:votes]).to eq([])
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
describe "Scenario 2: active phase VOTE; participant still has proposals to vote on" do
|
|
52
|
+
let!(:proposal) { create(:proposal, :accepted, component: proposal_component) }
|
|
53
|
+
|
|
54
|
+
before do
|
|
55
|
+
propose_phase.update!(active: false)
|
|
56
|
+
vote_phase.update!(active: true)
|
|
57
|
+
participatory_process.reload
|
|
58
|
+
proposal_component.reload
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
it "sets can_vote true" do
|
|
62
|
+
expect(meta[:votes_enabled]).to be(true)
|
|
63
|
+
expect(meta[:creation_enabled]).to be(false)
|
|
64
|
+
expect(meta[:can_create_proposals]).to be(false)
|
|
65
|
+
expect(meta[:can_vote]).to be(true)
|
|
66
|
+
expect(meta[:votes].map { |v| v[:weight] }).to eq([1, 2, 3])
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
describe "Scenario 3: active phase VOTE; participant has voted on all voteable proposals" do
|
|
71
|
+
let!(:proposal) { create(:proposal, :accepted, component: proposal_component) }
|
|
72
|
+
|
|
73
|
+
before do
|
|
74
|
+
create(:proposal_vote, proposal:, author: user)
|
|
75
|
+
propose_phase.update!(active: false)
|
|
76
|
+
vote_phase.update!(active: true)
|
|
77
|
+
participatory_process.reload
|
|
78
|
+
proposal_component.reload
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
it "sets can_vote false" do
|
|
82
|
+
expect(meta[:votes_enabled]).to be(true)
|
|
83
|
+
expect(meta[:can_vote]).to be(false)
|
|
84
|
+
expect(meta[:votes].map { |v| v[:weight] }).to eq([1, 2, 3])
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
# rubocop:enable RSpec/SpecFilePathFormat, RSpec/DescribeMethod
|
data/spec/serializers/decidim/api/rest_full/proposals/proposal_component_serializer_votes_spec.rb
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# rubocop:disable RSpec/SpecFilePathFormat, RSpec/DescribeMethod -- descriptive scenario title alongside serializer class
|
|
4
|
+
require "swagger_helper"
|
|
5
|
+
|
|
6
|
+
RSpec.describe Decidim::Api::RestFull::Proposals::ProposalComponentSerializer, "meta.votes catalog" do
|
|
7
|
+
let(:organization) { create(:organization, available_locales: %w(en)) }
|
|
8
|
+
let(:meta) { serialize.fetch(:data).fetch(:meta).symbolize_keys }
|
|
9
|
+
let(:participatory_process) { create(:participatory_process, :with_steps, organization:) }
|
|
10
|
+
let(:user) { create(:user, organization:, confirmed_at: Time.zone.now) }
|
|
11
|
+
let(:api_client) { create(:api_client, organization:, scopes: ["public"]) }
|
|
12
|
+
let(:component_settings) { {} }
|
|
13
|
+
let(:votes_enabled) { true }
|
|
14
|
+
|
|
15
|
+
let!(:proposal_component) do
|
|
16
|
+
create(
|
|
17
|
+
:proposal_component,
|
|
18
|
+
participatory_space: participatory_process,
|
|
19
|
+
settings: component_settings,
|
|
20
|
+
step_settings: {
|
|
21
|
+
participatory_process.steps.first.id.to_s => { votes_enabled:, creation_enabled: true }
|
|
22
|
+
}
|
|
23
|
+
)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def serialize(component = proposal_component.reload)
|
|
27
|
+
described_class.new(
|
|
28
|
+
component,
|
|
29
|
+
params: {
|
|
30
|
+
only: [],
|
|
31
|
+
locales: %w(en),
|
|
32
|
+
host: organization.host,
|
|
33
|
+
act_as: user,
|
|
34
|
+
client_id: api_client.id
|
|
35
|
+
}
|
|
36
|
+
).serializable_hash
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def vote_weights
|
|
40
|
+
meta.fetch(:votes).map { |option| option[:weight] || option["weight"] }
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
context "when votes are disabled" do
|
|
44
|
+
let(:votes_enabled) { false }
|
|
45
|
+
let(:component_settings) { { awesome_voting_manifest: :voting_cards, voting_cards_show_abstain: true } }
|
|
46
|
+
|
|
47
|
+
it "returns an empty array, not nil" do
|
|
48
|
+
expect(meta[:votes_enabled]).to be(false)
|
|
49
|
+
expect(meta).to have_key(:votes)
|
|
50
|
+
expect(meta[:votes]).to eq([])
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
context "when simple vote without abstention" do
|
|
55
|
+
let(:component_settings) { { voting_cards_show_abstain: false } }
|
|
56
|
+
|
|
57
|
+
it "returns weight 1 only" do
|
|
58
|
+
expect(vote_weights).to eq([1])
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
context "when simple vote with abstention" do
|
|
63
|
+
let(:component_settings) { { voting_cards_show_abstain: true } }
|
|
64
|
+
|
|
65
|
+
it "returns weights 0 and 1" do
|
|
66
|
+
expect(vote_weights).to eq([0, 1])
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
context "when voting cards without abstention" do
|
|
71
|
+
let(:component_settings) { { awesome_voting_manifest: :voting_cards, voting_cards_show_abstain: false } }
|
|
72
|
+
|
|
73
|
+
it "returns weights 1, 2, 3" do
|
|
74
|
+
expect(vote_weights).to eq([1, 2, 3])
|
|
75
|
+
expect(meta[:awesome_voting_manifest].to_s).to eq("voting_cards")
|
|
76
|
+
expect(meta[:voting_cards_show_abstain]).to be(false)
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
context "when voting cards with abstention" do
|
|
81
|
+
let(:component_settings) { { awesome_voting_manifest: :voting_cards, voting_cards_show_abstain: true } }
|
|
82
|
+
|
|
83
|
+
it "returns weights 0, 1, 2, 3" do
|
|
84
|
+
expect(vote_weights).to eq([0, 1, 2, 3])
|
|
85
|
+
expect(meta[:voting_cards_show_abstain]).to be(true)
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
context "when votes enabled but actor cannot vote anymore" do
|
|
90
|
+
let(:component_settings) { { awesome_voting_manifest: :voting_cards, voting_cards_show_abstain: true } }
|
|
91
|
+
let!(:proposal) { create(:proposal, :accepted, component: proposal_component) }
|
|
92
|
+
|
|
93
|
+
before do
|
|
94
|
+
create(:proposal_vote, proposal:, author: user)
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
it "keeps the vote catalog while can_vote is false" do
|
|
98
|
+
expect(meta[:can_vote]).to be(false)
|
|
99
|
+
expect(vote_weights).to eq([0, 1, 2, 3])
|
|
100
|
+
end
|
|
101
|
+
end
|
|
102
|
+
end
|
|
103
|
+
# rubocop:enable RSpec/SpecFilePathFormat, RSpec/DescribeMethod
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# rubocop:disable RSpec/SpecFilePathFormat, RSpec/DescribeMethod -- descriptive scenario title alongside serializer class
|
|
4
|
+
require "swagger_helper"
|
|
5
|
+
|
|
6
|
+
RSpec.describe Decidim::Api::RestFull::Proposals::ProposalSerializer, "meta.can_vote" do
|
|
7
|
+
subject(:serialized) do
|
|
8
|
+
described_class.new(
|
|
9
|
+
proposal,
|
|
10
|
+
params: {
|
|
11
|
+
only: [],
|
|
12
|
+
locales: %w(en),
|
|
13
|
+
host: organization.host,
|
|
14
|
+
act_as: nil,
|
|
15
|
+
client_id: api_client.id
|
|
16
|
+
}
|
|
17
|
+
).serializable_hash
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
let(:organization) { create(:organization, available_locales: %w(en)) }
|
|
21
|
+
let(:participatory_process) { create(:participatory_process, :with_steps, organization:) }
|
|
22
|
+
let(:step_id) { participatory_process.active_step.id }
|
|
23
|
+
let(:api_client) { create(:api_client, organization:, scopes: ["public"]) }
|
|
24
|
+
let(:meta) { serialized.fetch(:data).fetch(:meta).symbolize_keys }
|
|
25
|
+
|
|
26
|
+
let(:component) do
|
|
27
|
+
create(
|
|
28
|
+
:proposal_component,
|
|
29
|
+
participatory_space: participatory_process,
|
|
30
|
+
step_settings: { step_id => { votes_enabled: true } }
|
|
31
|
+
)
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
context "when status filter is off" do
|
|
35
|
+
let(:proposal) { create(:proposal, :accepted, component:) }
|
|
36
|
+
|
|
37
|
+
it "sets can_vote true for non-rejected proposals" do
|
|
38
|
+
expect(meta[:can_vote]).to be(true)
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
context "with a rejected proposal" do
|
|
42
|
+
let(:proposal) { create(:proposal, :rejected, component:) }
|
|
43
|
+
|
|
44
|
+
it "sets can_vote false" do
|
|
45
|
+
expect(meta[:can_vote]).to be(false)
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
context "when status filter is on", if: (
|
|
51
|
+
Decidim::Toggle.gem_present?("decidim-decidim_awesome") &&
|
|
52
|
+
defined?(Decidim::DecidimAwesome) &&
|
|
53
|
+
Decidim::DecidimAwesome.enabled?(:votes_by_proposal_status)
|
|
54
|
+
) do
|
|
55
|
+
let(:component) do
|
|
56
|
+
create(
|
|
57
|
+
:proposal_component,
|
|
58
|
+
participatory_space: participatory_process,
|
|
59
|
+
step_settings: {
|
|
60
|
+
step_id => {
|
|
61
|
+
votes_enabled: true,
|
|
62
|
+
awesome_votes_enabled_by_status: true,
|
|
63
|
+
awesome_votes_enabled_states: %w(accepted)
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
)
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
context "with an allowed status" do
|
|
70
|
+
let(:proposal) { create(:proposal, :accepted, component:) }
|
|
71
|
+
|
|
72
|
+
it "sets can_vote true" do
|
|
73
|
+
expect(meta[:can_vote]).to be(true)
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
context "with a disallowed status" do
|
|
78
|
+
let(:proposal) { create(:proposal, :evaluating, component:) }
|
|
79
|
+
|
|
80
|
+
it "sets can_vote false" do
|
|
81
|
+
expect(meta[:can_vote]).to be(false)
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
# rubocop:enable RSpec/SpecFilePathFormat, RSpec/DescribeMethod
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "spec_helper"
|
|
4
|
+
|
|
5
|
+
RSpec.describe Decidim::Api::RestFull::Proposals::ProposalWebhookSerializer do
|
|
6
|
+
subject(:serializer) { described_class.new(proposal, event_name:, organization:) }
|
|
7
|
+
|
|
8
|
+
let(:organization) { create(:organization, available_locales: ["en"]) }
|
|
9
|
+
let(:participatory_process) { create(:participatory_process, :with_steps, organization:) }
|
|
10
|
+
let(:component) { create(:proposal_component, participatory_space: participatory_process) }
|
|
11
|
+
let(:event_name) { "proposal_creation.succeeded" }
|
|
12
|
+
|
|
13
|
+
describe "published proposal" do
|
|
14
|
+
let(:proposal) { create(:proposal, :published, component:) }
|
|
15
|
+
|
|
16
|
+
it "builds an envelope with type and proposal data" do
|
|
17
|
+
envelope = serializer.envelope
|
|
18
|
+
|
|
19
|
+
expect(envelope["type"]).to eq(event_name)
|
|
20
|
+
expect(envelope["data"]["type"]).to eq("proposal")
|
|
21
|
+
expect(envelope["data"]["id"]).to eq(proposal.id.to_s)
|
|
22
|
+
expect(envelope["data"]["attributes"]).to include("title", "body")
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
it "exposes event_attributes for WebhookEventForm" do
|
|
26
|
+
attrs = serializer.event_attributes
|
|
27
|
+
|
|
28
|
+
expect(attrs[:type]).to eq(event_name)
|
|
29
|
+
expect(attrs[:data]).to have_key(:data)
|
|
30
|
+
expect(attrs[:timestamp]).to be_a(Integer)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
it "uses ProposalSerializer for published proposals" do
|
|
34
|
+
expect(Decidim::Api::RestFull::Proposals::ProposalSerializer).to receive(:new)
|
|
35
|
+
.and_call_original
|
|
36
|
+
serializer.envelope
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
describe "draft proposal" do
|
|
41
|
+
let(:proposal) { create(:proposal, component:, published_at: nil) }
|
|
42
|
+
let(:event_name) { "draft_proposal_creation.succeeded" }
|
|
43
|
+
|
|
44
|
+
it "uses DraftProposalSerializer for drafts without a separate webhook serializer" do
|
|
45
|
+
expect(Decidim::Api::RestFull::Proposals::DraftProposalSerializer).to receive(:new)
|
|
46
|
+
.and_call_original
|
|
47
|
+
expect(serializer.envelope["data"]["type"]).to eq("draft_proposal")
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
describe ".find_example_resource" do
|
|
52
|
+
let!(:published) { create(:proposal, :published, component:) }
|
|
53
|
+
let!(:draft) { create(:proposal, component:, published_at: nil) }
|
|
54
|
+
|
|
55
|
+
it "returns a draft for draft_* events" do
|
|
56
|
+
expect(described_class.find_example_resource(organization, event_name: "draft_proposal_creation.succeeded")).to eq(draft)
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
it "returns a published proposal for non-draft events" do
|
|
60
|
+
expect(described_class.find_example_resource(organization, event_name: "proposal_creation.succeeded")).to eq(published)
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
end
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "swagger_helper"
|
|
4
|
+
|
|
5
|
+
RSpec.describe Decidim::RestFull::Proposals::ProposalVoteEligibility do
|
|
6
|
+
let(:organization) { create(:organization, available_locales: %w(en)) }
|
|
7
|
+
let(:participatory_process) { create(:participatory_process, :with_steps, organization:) }
|
|
8
|
+
let(:step_id) { participatory_process.active_step.id }
|
|
9
|
+
|
|
10
|
+
describe ".voting_enabled?" do
|
|
11
|
+
it "is true when votes_enabled and not blocked" do
|
|
12
|
+
component = create(
|
|
13
|
+
:proposal_component,
|
|
14
|
+
participatory_space: participatory_process,
|
|
15
|
+
step_settings: { step_id => { votes_enabled: true, votes_blocked: false } }
|
|
16
|
+
)
|
|
17
|
+
expect(described_class.voting_enabled?(component)).to be(true)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
it "is false when votes_blocked" do
|
|
21
|
+
component = create(
|
|
22
|
+
:proposal_component,
|
|
23
|
+
participatory_space: participatory_process,
|
|
24
|
+
step_settings: { step_id => { votes_enabled: true, votes_blocked: true } }
|
|
25
|
+
)
|
|
26
|
+
expect(described_class.voting_enabled?(component)).to be(false)
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
describe ".proposal_can_vote?" do
|
|
31
|
+
context "when status filter is off" do
|
|
32
|
+
let(:component) do
|
|
33
|
+
create(
|
|
34
|
+
:proposal_component,
|
|
35
|
+
participatory_space: participatory_process,
|
|
36
|
+
step_settings: { step_id => { votes_enabled: true } }
|
|
37
|
+
)
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
it "is true for accepted proposals" do
|
|
41
|
+
proposal = create(:proposal, :accepted, component:)
|
|
42
|
+
expect(described_class.proposal_can_vote?(proposal)).to be(true)
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
it "is false for rejected proposals" do
|
|
46
|
+
proposal = create(:proposal, :rejected, component:)
|
|
47
|
+
expect(described_class.proposal_can_vote?(proposal)).to be(false)
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
it "is false when voting is disabled" do
|
|
51
|
+
disabled = create(
|
|
52
|
+
:proposal_component,
|
|
53
|
+
participatory_space: participatory_process,
|
|
54
|
+
step_settings: { step_id => { votes_enabled: false } }
|
|
55
|
+
)
|
|
56
|
+
proposal = create(:proposal, :accepted, component: disabled)
|
|
57
|
+
expect(described_class.proposal_can_vote?(proposal)).to be(false)
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
context "when status filter is on", if: (
|
|
62
|
+
Decidim::Toggle.gem_present?("decidim-decidim_awesome") &&
|
|
63
|
+
defined?(Decidim::DecidimAwesome) &&
|
|
64
|
+
Decidim::DecidimAwesome.enabled?(:votes_by_proposal_status)
|
|
65
|
+
) do
|
|
66
|
+
let(:component) do
|
|
67
|
+
create(
|
|
68
|
+
:proposal_component,
|
|
69
|
+
participatory_space: participatory_process,
|
|
70
|
+
step_settings: {
|
|
71
|
+
step_id => {
|
|
72
|
+
votes_enabled: true,
|
|
73
|
+
awesome_votes_enabled_by_status: true,
|
|
74
|
+
awesome_votes_enabled_states: %w(accepted)
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
)
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
it "is true only for allowed statuses" do
|
|
81
|
+
accepted = create(:proposal, :accepted, component:)
|
|
82
|
+
evaluating = create(:proposal, :evaluating, component:)
|
|
83
|
+
expect(described_class.proposal_can_vote?(accepted)).to be(true)
|
|
84
|
+
expect(described_class.proposal_can_vote?(evaluating)).to be(false)
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
describe ".unvoted_voteable_proposals_exist?" do
|
|
90
|
+
let(:user) { create(:user, organization:, confirmed_at: Time.zone.now) }
|
|
91
|
+
|
|
92
|
+
context "when status filter is on", if: (
|
|
93
|
+
Decidim::Toggle.gem_present?("decidim-decidim_awesome") &&
|
|
94
|
+
defined?(Decidim::DecidimAwesome) &&
|
|
95
|
+
Decidim::DecidimAwesome.enabled?(:votes_by_proposal_status)
|
|
96
|
+
) do
|
|
97
|
+
let(:component) do
|
|
98
|
+
create(
|
|
99
|
+
:proposal_component,
|
|
100
|
+
participatory_space: participatory_process,
|
|
101
|
+
step_settings: {
|
|
102
|
+
step_id => {
|
|
103
|
+
votes_enabled: true,
|
|
104
|
+
awesome_votes_enabled_by_status: true,
|
|
105
|
+
awesome_votes_enabled_states: %w(accepted)
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
)
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
it "ignores proposals outside allowed statuses" do
|
|
112
|
+
create(:proposal, :evaluating, component:)
|
|
113
|
+
expect(described_class.unvoted_voteable_proposals_exist?(component, user)).to be(false)
|
|
114
|
+
|
|
115
|
+
create(:proposal, :accepted, component:)
|
|
116
|
+
expect(described_class.unvoted_voteable_proposals_exist?(component, user)).to be(true)
|
|
117
|
+
end
|
|
118
|
+
end
|
|
119
|
+
end
|
|
120
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: decidim-restfull-proposals
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.3.11
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Hadrien Froger
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2026-11-25 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: decidim-proposals
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - ">="
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: 0.29.0
|
|
20
|
+
- - "<"
|
|
21
|
+
- !ruby/object:Gem::Version
|
|
22
|
+
version: '0.33'
|
|
23
|
+
type: :runtime
|
|
24
|
+
prerelease: false
|
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
26
|
+
requirements:
|
|
27
|
+
- - ">="
|
|
28
|
+
- !ruby/object:Gem::Version
|
|
29
|
+
version: 0.29.0
|
|
30
|
+
- - "<"
|
|
31
|
+
- !ruby/object:Gem::Version
|
|
32
|
+
version: '0.33'
|
|
33
|
+
- !ruby/object:Gem::Dependency
|
|
34
|
+
name: decidim-restfull-core
|
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
|
36
|
+
requirements:
|
|
37
|
+
- - '='
|
|
38
|
+
- !ruby/object:Gem::Version
|
|
39
|
+
version: 0.3.11
|
|
40
|
+
type: :runtime
|
|
41
|
+
prerelease: false
|
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
43
|
+
requirements:
|
|
44
|
+
- - '='
|
|
45
|
+
- !ruby/object:Gem::Version
|
|
46
|
+
version: 0.3.11
|
|
47
|
+
description: Decidim RestFull API — proposals, drafts, votes
|
|
48
|
+
email:
|
|
49
|
+
- hadrien@octree.ch
|
|
50
|
+
executables: []
|
|
51
|
+
extensions: []
|
|
52
|
+
extra_rdoc_files: []
|
|
53
|
+
files:
|
|
54
|
+
- app/controllers/decidim/api/rest_full/components/proposal_components_controller.rb
|
|
55
|
+
- app/controllers/decidim/api/rest_full/draft_proposals/draft_proposals_controller.rb
|
|
56
|
+
- app/controllers/decidim/api/rest_full/proposals/proposal_extended_data_controller.rb
|
|
57
|
+
- app/controllers/decidim/api/rest_full/proposals/proposals_controller.rb
|
|
58
|
+
- app/controllers/decidim/api/rest_full/vote_proposals/vote_proposals_controller.rb
|
|
59
|
+
- app/jobs/decidim/rest_full/proposals/proposal_webhook_job.rb
|
|
60
|
+
- app/models/decidim/rest_full/proposals/proposal_application_id.rb
|
|
61
|
+
- app/serializers/decidim/api/rest_full/proposals/draft_proposal_serializer.rb
|
|
62
|
+
- app/serializers/decidim/api/rest_full/proposals/proposal_component_serializer.rb
|
|
63
|
+
- app/serializers/decidim/api/rest_full/proposals/proposal_serializer.rb
|
|
64
|
+
- app/serializers/decidim/api/rest_full/proposals/proposal_state_serializer.rb
|
|
65
|
+
- app/serializers/decidim/api/rest_full/proposals/proposal_webhook_serializer.rb
|
|
66
|
+
- app/serializers/decidim/api/rest_full/proposals/vote_proposal_serializer.rb
|
|
67
|
+
- app/services/decidim/rest_full/proposals/draft_proposals_operations.rb
|
|
68
|
+
- app/services/decidim/rest_full/proposals/proposal_vote_eligibility.rb
|
|
69
|
+
- app/services/decidim/rest_full/proposals/proposal_votes_operations.rb
|
|
70
|
+
- app/services/decidim/rest_full/proposals/vote_proposals_operations.rb
|
|
71
|
+
- config/locales/decidim_rest_full_proposals.en.yml
|
|
72
|
+
- lib/decidim-restfull-proposals.rb
|
|
73
|
+
- lib/decidim/rest_full/http_cache/proposal_show_fingerprint.rb
|
|
74
|
+
- lib/decidim/rest_full/proposals/engine.rb
|
|
75
|
+
- lib/decidim/rest_full/proposals/proposal_client_id_override.rb
|
|
76
|
+
- lib/decidim/rest_full/proposals/proposals_controller_override.rb
|
|
77
|
+
- lib/decidim/rest_full/proposals/ransackers.rb
|
|
78
|
+
- lib/decidim/rest_full/proposals/test_definitions.rb
|
|
79
|
+
- lib/decidim/rest_full/test/definitions/draft_proposal.rb
|
|
80
|
+
- lib/decidim/rest_full/test/definitions/proposal.rb
|
|
81
|
+
- lib/decidim/rest_full/test/definitions/proposal_component_schema.rb
|
|
82
|
+
- lib/decidim/rest_full/test/definitions/proposals.rb
|
|
83
|
+
- lib/decidim/rest_full/test/definitions/tags/draft_proposals_tag.rb
|
|
84
|
+
- lib/decidim/rest_full/test/definitions/tags/proposal_tag.rb
|
|
85
|
+
- lib/decidim/rest_full/test/definitions/vote_proposal.rb
|
|
86
|
+
- spec/jobs/decidim/rest_full/proposals/proposal_webhook_job_spec.rb
|
|
87
|
+
- spec/requests/decidim/api/rest_full/components/proposal_components_controller_index_spec.rb
|
|
88
|
+
- spec/requests/decidim/api/rest_full/components/proposal_components_controller_show_spec.rb
|
|
89
|
+
- spec/requests/decidim/api/rest_full/draft_proposals/draft_proposals_controller_create_spec.rb
|
|
90
|
+
- spec/requests/decidim/api/rest_full/draft_proposals/draft_proposals_controller_delete_spec.rb
|
|
91
|
+
- spec/requests/decidim/api/rest_full/draft_proposals/draft_proposals_controller_publish_spec.rb
|
|
92
|
+
- spec/requests/decidim/api/rest_full/draft_proposals/draft_proposals_controller_show_spec.rb
|
|
93
|
+
- spec/requests/decidim/api/rest_full/draft_proposals/draft_proposals_controller_update_spec.rb
|
|
94
|
+
- spec/requests/decidim/api/rest_full/proposals/proposal_extended_data_controller_spec.rb
|
|
95
|
+
- spec/requests/decidim/api/rest_full/proposals/proposals_controller_index_spec.rb
|
|
96
|
+
- spec/requests/decidim/api/rest_full/proposals/proposals_controller_show_spec.rb
|
|
97
|
+
- spec/requests/decidim/api/rest_full/scenarios/draft_publish_async_increments_count_and_lists_newest_spec.rb
|
|
98
|
+
- spec/requests/decidim/api/rest_full/scenarios/participatory_process_phase_change_webhook_and_component_meta_spec.rb
|
|
99
|
+
- spec/requests/decidim/api/rest_full/scenarios/proposals_published_at_desc_prev_next_chain_spec.rb
|
|
100
|
+
- spec/requests/decidim/api/rest_full/scenarios/search_vote_enabled_impersonate_and_vote_spec.rb
|
|
101
|
+
- spec/requests/decidim/api/rest_full/vote_proposals/vote_proposals_controller_spec.rb
|
|
102
|
+
- spec/serializers/decidim/api/rest_full/proposals/proposal_component_serializer_chatbot_menu_spec.rb
|
|
103
|
+
- spec/serializers/decidim/api/rest_full/proposals/proposal_component_serializer_phases_spec.rb
|
|
104
|
+
- spec/serializers/decidim/api/rest_full/proposals/proposal_component_serializer_votes_spec.rb
|
|
105
|
+
- spec/serializers/decidim/api/rest_full/proposals/proposal_serializer_can_vote_spec.rb
|
|
106
|
+
- spec/serializers/decidim/api/rest_full/proposals/proposal_webhook_serializer_spec.rb
|
|
107
|
+
- spec/services/decidim/rest_full/proposals/proposal_vote_eligibility_spec.rb
|
|
108
|
+
homepage: https://git.octree.ch/decidim/decidim-chatbot/decidim-module-rest_full
|
|
109
|
+
licenses:
|
|
110
|
+
- AGPL-3.0
|
|
111
|
+
metadata:
|
|
112
|
+
rubygems_mfa_required: 'true'
|
|
113
|
+
post_install_message:
|
|
114
|
+
rdoc_options: []
|
|
115
|
+
require_paths:
|
|
116
|
+
- lib
|
|
117
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
118
|
+
requirements:
|
|
119
|
+
- - ">="
|
|
120
|
+
- !ruby/object:Gem::Version
|
|
121
|
+
version: '3.2'
|
|
122
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
123
|
+
requirements:
|
|
124
|
+
- - ">="
|
|
125
|
+
- !ruby/object:Gem::Version
|
|
126
|
+
version: '0'
|
|
127
|
+
requirements: []
|
|
128
|
+
rubygems_version: 3.4.19
|
|
129
|
+
signing_key:
|
|
130
|
+
specification_version: 4
|
|
131
|
+
summary: Decidim RestFull API — proposals, drafts, votes
|
|
132
|
+
test_files: []
|