Skip to content

Commit

Permalink
🐛 (component) Fix: authorship joining on proposals
Browse files Browse the repository at this point in the history
  • Loading branch information
Hadrien Froger committed Dec 15, 2024
1 parent f553ca0 commit cfdb927
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def self.resources_for(component, act_as)
if act_as.nil?
resources.published
else
resources.published.or(resources.where(published_at: nil, decidim_user_id: act_as.id))
resources.published.or(resources.where(published_at: nil, decidim_author_id: act_as.id))
end
end
has_many :resources, meta: (proc do |component, params|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@ def self.resources_for(component, act_as)
if act_as.nil?
resources.published
else
resources.published.or(resources.where(published_at: nil, decidim_user_id: act_as.id))
resources.joins(:coauthorships).published.or(
resources.joins(:coauthorships).where(
published_at: nil,
coauthorships: { decidim_author_id: act_as.id }
)
)
end
end

Expand Down
16 changes: 12 additions & 4 deletions spec/decidim/rest_full/public/components_show_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@
let(:"locales[]") { %w(en fr) }

let!(:api_client) { create(:api_client, organization: organization) }
let!(:client_creds) { create(:oauth_access_token, scopes: "public", resource_owner_id: nil, application: api_client) }
let(:Authorization) { "Bearer #{client_creds.token}" }
let(:user) { create(:user, locale: "fr", organization: organization) }

let!(:impersonate_token) { create(:oauth_access_token, scopes: "public", resource_owner_id: user.id, application: api_client) }
let(:Authorization) { "Bearer #{impersonate_token.token}" }

before do
host! organization.host
Expand Down Expand Up @@ -64,14 +66,20 @@
end
end

context "with proposal" do
context "with published proposals, and drafted ones" do
let!(:proposal_component) { create(:component, participatory_space: participatory_process, manifest_name: "proposals", published_at: Time.zone.now) }
let!(:proposals) { create_list(:proposal, 10, component: proposal_component, published_at: Time.zone.now) }
let!(:draft_proposals) do
proposal = create(:proposal, component: proposal_component, published_at: nil)
proposal.coauthorships.create(decidim_author_id: user.id, decidim_author_type: "Decidim::UserBaseEntity")
proposal.save!
create(:proposal, component: proposal_component, published_at: nil)
end
let(:id) { proposal_component.id }

run_test!(example_name: :ok_proposal) do |example|
data = JSON.parse(example.body)["data"]
expect(data["relationships"]["resources"]["data"].size).to eq(10)
expect(data["relationships"]["resources"]["data"].size).to eq(11)
end
end

Expand Down

0 comments on commit cfdb927

Please sign in to comment.