Skip to content

Commit

Permalink
Merge pull request #3110 from DMPRoadmap/fix-public-page-policy
Browse files Browse the repository at this point in the history
fix for issue invoking the public page policy for template exports
  • Loading branch information
briri authored Feb 15, 2022
2 parents c76d896 + 268050a commit 9f815ff
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
2 changes: 1 addition & 1 deletion app/controllers/public_pages_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def template_export
@template = Template.live(params[:id])
# covers authorization for this action.
# Pundit dosent support passing objects into scoped policies
unless PublicPagePolicy.new(@template).template_export?
unless PublicPagePolicy.new(current_user, @template).template_export?
msg = 'You are not authorized to export that template'
redirect_to public_templates_path, notice: msg and return
# raise Pundit::NotAuthorizedError
Expand Down
20 changes: 13 additions & 7 deletions app/policies/public_page_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@
# Security rules for the public pages
# Note the method names here correspond with controller actions
class PublicPagePolicy < ApplicationPolicy
# NOTE: @user is the signed_in_user and @record is an instance of Plan
# rubocop:disable Lint/MissingSuper
def initialize(object, object2 = nil)
@object = object
@object2 = object2
end
# rubocop:enable Lint/MissingSuper

def plan_index?
true
Expand All @@ -14,18 +19,19 @@ def template_index?
end

def template_export?
@record.present? && @record.published?
@object.present? && @object2.published?
end

def plan_export?
@record.publicly_visible?
@object2.publicly_visible?
end

def plan_organisationally_exportable?
if @record.is_a?(Plan) && @user.is_a?(User)
return @record.publicly_visible? ||
(@record.organisationally_visible? && @record.owner.present? &&
@record.owner.org_id == @user.org_id)
plan = @object
user = @object2
if plan.is_a?(Plan) && user.is_a?(User)
return plan.publicly_visible? || (plan.organisationally_visible? && plan.owner.present? &&
plan.owner.org_id == user.org_id)
end

false
Expand Down

0 comments on commit 9f815ff

Please sign in to comment.