Skip to content

Commit

Permalink
Fix proposal presenter #author method for private user proposals
Browse files Browse the repository at this point in the history
  • Loading branch information
ahukkanen committed Sep 21, 2023
1 parent 17acc35 commit 25f4c2c
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# frozen_string_literal: true

module Decidim
module Privacy
module ProposalPresenterExtensions
extend ActiveSupport::Concern

included do
def author
@author ||= if official?
Decidim::Proposals::OfficialAuthorPresenter.new
else
coauthorship = coauthorships.includes(:author, :user_group).first
coauthorship.user_group&.presenter || coauthorship.author&.presenter
end
end
end
end
end
end
3 changes: 3 additions & 0 deletions lib/decidim/privacy/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,9 @@ class Engine < ::Rails::Engine
Decidim::Proposals::Permissions.include(
Decidim::Privacy::PermissionsExtensions
)

# presenters
Decidim::Proposals::ProposalPresenter.include(Decidim::Privacy::ProposalPresenterExtensions)
end

if Decidim.module_installed? :comments
Expand Down
18 changes: 18 additions & 0 deletions spec/presenters/decidim/proposals/proposal_presenter_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# frozen_string_literal: true

require "spec_helper"

describe Decidim::Proposals::ProposalPresenter, type: :helper do
let(:component) { create(:proposal_component) }
let(:proposal) { create(:proposal, component: component, users: [author]) }
let(:author) { create(:user, :confirmed, organization: component.organization) }
let(:presenter) { described_class.new(proposal) }

describe "#author" do
subject { presenter.author }

context "when the author is private (default)" do
it { is_expected.to be_nil }
end
end
end

0 comments on commit 25f4c2c

Please sign in to comment.