diff --git a/app/controllers/plans_controller.rb b/app/controllers/plans_controller.rb index f5125d6..fbed0c9 100644 --- a/app/controllers/plans_controller.rb +++ b/app/controllers/plans_controller.rb @@ -170,10 +170,41 @@ @plan = Plan.find(params[:id]) authorize @plan - if user_signed_in? && @plan.readable_by(current_user.id) then + if (user_signed_in? && @plan.readable_by(current_user.id)) then + generate_export + + elsif !user_signed_in? then + respond_to do |format| + format.html { redirect_to edit_user_registration_path } + end + + elsif !@plan.editable_by(current_user.id) then + respond_to do |format| + format.html { redirect_to projects_url, notice: I18n.t('helpers.settings.plans.errors.no_access_account') } + end + end + end + + # GET /projects/:project_id/plans/:id/public-export + # ------------------------------------------------------------- + def public_export + @plan = Plan.find(params[:id]) + + if @plan.project.is_public? + generate_export + + else + format.html { redirect_to root_path, notice: I18n.t('helpers.settings.plans.errors.no_access_account') } + end + end + + + # ============================================================== + private + def generate_export @exported_plan = ExportedPlan.new.tap do |ep| ep.plan = @plan - ep.user = current_user + ep.user = current_user ||= nil #ep.format = request.format.try(:symbol) ep.format = request.format.to_sym plan_settings = @plan.settings(:export) @@ -205,14 +236,5 @@ } end end - elsif !user_signed_in? then - respond_to do |format| - format.html { redirect_to edit_user_registration_path } - end - elsif !@plan.editable_by(current_user.id) then - respond_to do |format| - format.html { redirect_to projects_url, notice: I18n.t('helpers.settings.plans.errors.no_access_account') } - end - end - end + end end diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index f43a5c5..6eafa2a 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -1,9 +1,10 @@ class ProjectsController < ApplicationController before_filter :get_plan_list_columns, only: %i( index ) - after_action :verify_authorized + after_action :verify_authorized, except: :publicly_available + + respond_to :html # GET /projects - # GET /projects.json # ----------------------------------------------------------- def index authorize Project @@ -26,6 +27,12 @@ end end + # GET /projects/publicly_available + # ----------------------------------------------------------- + def publicly_available + @projects = Project.public_visibility.order(title: :asc) + end + # GET /projects/1 # GET /projects/1.json # ----------------------------------------------------------- diff --git a/app/helpers/projects_helper.rb b/app/helpers/projects_helper.rb index fa76080..88848b8 100644 --- a/app/helpers/projects_helper.rb +++ b/app/helpers/projects_helper.rb @@ -50,6 +50,12 @@ [ "dmp_td_small", l(project.latest_update.to_date, formats: :short) ] when 'description' [ "dmp_td_medium", (project.try(col) || "Unknown") ] + when 'non_link_name' + [ "dmp_td_big", project.title ] + when 'template' + ["dmp_td_big", project.dmptemplate.title] + when 'organisation' + ["dmp_td_medium", (project.organisation.nil? ? project.owner.organisation.name : project.organisation.name)] else [ "dmp_td_small", (project.try(col) || "Unknown") ] end diff --git a/app/models/project.rb b/app/models/project.rb index 821228a..0b50de6 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -12,6 +12,8 @@ friendly_id :title, use: [:slugged, :history, :finders] + scope :public_visibility, -> { where(is_public: true) } + # Set the is_public flag to false if we are making this a test plan # ----------------------------------------------------------------- def is_test=(val) diff --git a/app/views/layouts/_navigation.html.erb b/app/views/layouts/_navigation.html.erb index e4a3c9f..32a4668 100644 --- a/app/views/layouts/_navigation.html.erb +++ b/app/views/layouts/_navigation.html.erb @@ -97,6 +97,16 @@ <% end %> <%= t("helpers.help_label") %> + + + <% if current_path == "/plans/publicly_available" then %> +
  • + <% else %> +
  • + <% end %> + <%= t("helpers.publicly_available_label") %> +
  • +