diff --git a/app/controllers/plans_controller.rb b/app/controllers/plans_controller.rb index 80fff04..89c03ae 100644 --- a/app/controllers/plans_controller.rb +++ b/app/controllers/plans_controller.rb @@ -3,7 +3,7 @@ require 'pp' helper PaginableHelper helper SettingsTemplateHelper - after_action :verify_authorized + after_action :verify_authorized, except: [:overview] def index authorize Plan @@ -357,6 +357,17 @@ end end + def overview + begin + plan = Plan.overview(params[:id]) + authorize plan + render(:overview, locals: { plan: plan }) + rescue ActiveRecord::RecordNotFound + flash[:alert] = _('There is no plan associated with id %{id}') %{ :id => params[:id] } + redirect_to(action: :index) + end + end + private def plan_params params.require(:plan).permit(:org_id, :org_name, :funder_id, :funder_name, :template_id, :title, :visibility, diff --git a/app/models/plan.rb b/app/models/plan.rb index d484635..5cb35bb 100644 --- a/app/models/plan.rb +++ b/app/models/plan.rb @@ -70,6 +70,11 @@ .where(['NOT EXISTS (SELECT 1 FROM roles WHERE plan_id = plans.id AND user_id = ?)', user.id]) .order(:title => :asc) } + + # Retrieves plan, template, org, phases, sections and questions + scope :overview, -> (id) { + Plan.includes(:phases, :sections, :questions, template: [ :org ]).find(id) + } ## # Settings for the template has_settings :export, class_name: 'Settings::Template' do |s| diff --git a/app/policies/plan_policy.rb b/app/policies/plan_policy.rb index cbe3c4c..3da3562 100644 --- a/app/policies/plan_policy.rb +++ b/app/policies/plan_policy.rb @@ -64,4 +64,8 @@ def feedback_complete? @plan.reviewable_by?(@user.id) && Role.find_by(user_id: @user.id, plan_id: @plan.id).active end + + def overview? + @plan.readable_by?(@user.id) && Role.find_by(user_id: @user.id, plan_id: @plan.id).active + end end diff --git a/app/views/plans/_navigation.html.erb b/app/views/plans/_navigation.html.erb index 1c154e5..5956234 100644 --- a/app/views/plans/_navigation.html.erb +++ b/app/views/plans/_navigation.html.erb @@ -3,7 +3,10 @@
+ <%= _('This plan is based on the "%{template_title}" template provided by %{org_name}.') %{ :template_title => plan.template.title, :org_name => plan.template.org.name } %> +
++ <%= raw(plan.template.description) %> +
++ <%= raw(p.description) %> +
+