diff --git a/app/controllers/plans_controller.rb b/app/controllers/plans_controller.rb index 049fc56..fddb1e9 100644 --- a/app/controllers/plans_controller.rb +++ b/app/controllers/plans_controller.rb @@ -234,12 +234,13 @@ def export - @plan = Plan.includes(:answers).joins(:answers).find(params[:id]) + @plan = Plan.includes(:answers).find(params[:id]) authorize @plan @show_coversheet = params[:export][:project_details].present? @show_sections_questions = params[:export][:question_headings].present? @show_unanswered = params[:export][:unanswered_questions].present? + @public_plan = false @hash = @plan.as_pdf(@show_coversheet) @formatting = @plan.settings(:export).formatting diff --git a/app/controllers/public_pages_controller.rb b/app/controllers/public_pages_controller.rb index 98ffad9..9307c4a 100644 --- a/app/controllers/public_pages_controller.rb +++ b/app/controllers/public_pages_controller.rb @@ -46,7 +46,7 @@ # GET plan_export/:id # ------------------------------------------------------------- def plan_export - @plan = Plan.includes(:answers).joins(:answers).find(params[:id]) + @plan = Plan.includes(:answers).find(params[:id]) # covers authorization for this action. Pundit dosent support passing objects into scoped policies raise Pundit::NotAuthorizedError unless PublicPagePolicy.new(@plan, current_user).plan_organisationally_exportable? || PublicPagePolicy.new(@plan).plan_export? skip_authorization @@ -54,6 +54,7 @@ @show_coversheet = true @show_sections_questions = true @show_unanswered = true + @public_plan = true @hash = @plan.as_pdf(@show_coversheet) @formatting = @plan.settings(:export).formatting diff --git a/app/policies/public_page_policy.rb b/app/policies/public_page_policy.rb index 4721351..1e1ec53 100644 --- a/app/policies/public_page_policy.rb +++ b/app/policies/public_page_policy.rb @@ -25,7 +25,7 @@ plan = @object user = @object2 if plan.is_a?(Plan) && user.is_a?(User) - return plan.publicly_visible? || (plan.organisationally_visible? && plan.template.org_id == user.org_id) + return plan.publicly_visible? || (plan.organisationally_visible? && plan.owner.present? && plan.owner.org_id == user.org_id) end return false; end diff --git a/app/views/shared/export/_plan.erb b/app/views/shared/export/_plan.erb index 283cee0..c7eaf8a 100644 --- a/app/views/shared/export/_plan.erb +++ b/app/views/shared/export/_plan.erb @@ -25,7 +25,7 @@ <% section[:questions].each do |question| %>
<%= _('Question not answered.') -%>
- <% else %> + <% elsif !blank %> <% if answer.question_options.length > 0 %>