diff --git a/app/presenters/concerns/decidim/privacy/proposal_presenter_extensions.rb b/app/presenters/concerns/decidim/privacy/proposal_presenter_extensions.rb new file mode 100644 index 0000000..689034d --- /dev/null +++ b/app/presenters/concerns/decidim/privacy/proposal_presenter_extensions.rb @@ -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 diff --git a/lib/decidim/privacy/engine.rb b/lib/decidim/privacy/engine.rb index a5861fd..c03c543 100644 --- a/lib/decidim/privacy/engine.rb +++ b/lib/decidim/privacy/engine.rb @@ -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 diff --git a/spec/presenters/decidim/proposals/proposal_presenter_spec.rb b/spec/presenters/decidim/proposals/proposal_presenter_spec.rb new file mode 100644 index 0000000..d249f4e --- /dev/null +++ b/spec/presenters/decidim/proposals/proposal_presenter_spec.rb @@ -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 diff --git a/spec/presenters/concerns/user_presenter_spec.rb b/spec/presenters/decidim/user_presenter_spec.rb similarity index 100% rename from spec/presenters/concerns/user_presenter_spec.rb rename to spec/presenters/decidim/user_presenter_spec.rb