diff --git a/app/controllers/plans_controller.rb b/app/controllers/plans_controller.rb
index fbed0c9..ab877e2 100644
--- a/app/controllers/plans_controller.rb
+++ b/app/controllers/plans_controller.rb
@@ -185,19 +185,6 @@
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
diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb
index 6eafa2a..604a124 100644
--- a/app/controllers/projects_controller.rb
+++ b/app/controllers/projects_controller.rb
@@ -1,6 +1,6 @@
class ProjectsController < ApplicationController
before_filter :get_plan_list_columns, only: %i( index )
- after_action :verify_authorized, except: :publicly_available
+ after_action :verify_authorized, except: [:publicly_available, :public_export]
respond_to :html
@@ -29,7 +29,7 @@
# GET /projects/publicly_available
# -----------------------------------------------------------
- def publicly_available
+ def public_plans
@projects = Project.public_visibility.order(title: :asc)
end
@@ -130,6 +130,28 @@
end
end
+ # GET /projects/[:project_slug]/public_export
+ # -------------------------------------------------------------
+ def public_export
+ @project = Project.find(params[:id])
+
+ if @project.is_public?
+puts "ITS PUBLIC"
+ render action: "export"
+
+ else
+ authorize @project
+
+ if user_signed_in?
+puts "SIGNED IN"
+ render action: "export"
+ else
+puts "NOT SIGNED IN"
+ redirect_to root_path, notice: I18n.t('helpers.settings.plans.errors.no_access_account')
+ end
+ end
+ end
+
# POST /projects
# POST /projects.json
# -----------------------------------------------------------
diff --git a/app/views/layouts/_navigation.html.erb b/app/views/layouts/_navigation.html.erb
index 32a4668..9f97b09 100644
--- a/app/views/layouts/_navigation.html.erb
+++ b/app/views/layouts/_navigation.html.erb
@@ -104,7 +104,7 @@
<% else %>
<% end %>
- <%= t("helpers.publicly_available_label") %>
+ <%= t("helpers.publicly_available_label") %>
diff --git a/app/views/projects/publicly_available.html.erb b/app/views/projects/publicly_available.html.erb
index c72b9a6..a2e94ed 100644
--- a/app/views/projects/publicly_available.html.erb
+++ b/app/views/projects/publicly_available.html.erb
@@ -26,7 +26,7 @@
<% end %>
- <%= link_to t("helpers.project.tab_export"), "#{public_export_project_plan_path(project, project.plans.first)}", :class => "dmp_table_link" %>
+ <%= link_to t("helpers.project.tab_export"), "#{public_export_project_path(project)}", :class => "dmp_table_link" %>
|
<% end %>
diff --git a/config/routes.rb b/config/routes.rb
index 7660d42..59286ba 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -48,8 +48,7 @@
get "roadmap" => 'static_pages#roadmap'
get "terms" => 'static_pages#termsuse'
get "existing_users" => 'existing_users#index'
- get "plans/publicly-available" => 'projects#publicly_available'
-# get "plans/public-export"
+ get "public_plans" => 'projects#public_plans'
#post 'contact_form' => 'contacts', as: 'localized_contact_creation'
#get 'contact_form' => 'contacts#new', as: 'localized_contact_form'
@@ -143,13 +142,13 @@
get 'export'
get 'warning'
get 'section_answers'
- get 'public-export'
end
end
member do
get 'share'
get 'export'
+ get 'public_export'
post 'invite'
end
collection do
diff --git a/test/functional/plans_controller_test.rb b/test/functional/plans_controller_test.rb
index d2931bf..58e763f 100644
--- a/test/functional/plans_controller_test.rb
+++ b/test/functional/plans_controller_test.rb
@@ -2,10 +2,6 @@
class PlansControllerTest < ActionController::TestCase
=begin
- setup do
- @plan = plans(:one)
- end
-
test "should get index" do
get :index
assert_response :success
diff --git a/test/functional/projects_controller_test.rb b/test/functional/projects_controller_test.rb
index 4238699..0a29264 100644
--- a/test/functional/projects_controller_test.rb
+++ b/test/functional/projects_controller_test.rb
@@ -1,11 +1,31 @@
require 'test_helper'
-class ProjectsControllerTest < ActionController::TestCase
-=begin
+class ProjectsControllerTest < ActionDispatch::IntegrationTest
+
+ include Devise::Test::IntegrationHelpers
+
setup do
- @project = projects(:one)
+ @project = Project.first
end
+ # ----------------------------------------------------------
+ test "should export the publicly available plan" do
+
+ end
+
+ # ----------------------------------------------------------
+ test "should NOT export a non-public plan to unauthorized users" do
+ @project.is_public = false
+ @project.save!
+
+ get public_export_project_path(locale: I18n.locale, id: @project)
+
+ assert_redirected_to "#{root_path}?locale=#{I18n.locale}", "expected to be redirected to the home page!"
+ assert_equal I18n.t('helpers.settings.plans.errors.no_access_account'), flash[:notice], "Expected an unauthorized message when trying to export a plan (via the public_export route) when the plan is not actually public"
+ end
+
+=begin
+
test "should get index" do
get :index
assert_response :success
diff --git a/test/routing_test.rb b/test/routing_test.rb
index d9fc73c..ac6f955 100644
--- a/test/routing_test.rb
+++ b/test/routing_test.rb
@@ -14,39 +14,33 @@
# -------------------------------------------------------------------
test 'GET /about_us should resolve to StaticPagesController#about_us' do
target = {controller: "static_pages", action: "about_us", locale: "#{I18n.locale}"}
-
- assert_routing "/#{I18n.locale}/about_us", target
+ assert_routing about_us_path(locale: I18n.locale), target
end
test 'GET /help should resolve to StaticPagesController#help' do
target = {controller: "static_pages", action: "help", locale: "#{I18n.locale}"}
-
- assert_routing "/#{I18n.locale}/help", target
+ assert_routing help_path(locale: I18n.locale), target
end
test 'GET /roadmap should resolve to StaticPagesController#roadmap' do
target = {controller: "static_pages", action: "roadmap", locale: "#{I18n.locale}"}
-
- assert_routing "/#{I18n.locale}/roadmap", target
+ assert_routing roadmap_path(locale: I18n.locale), target
end
test 'GET /terms should resolve to StaticPagesController#terms' do
target = {controller: "static_pages", action: "termsuse", locale: "#{I18n.locale}"}
-
- assert_routing "/#{I18n.locale}/terms", target
+ assert_routing terms_path(locale: I18n.locale), target
end
# Routing for Public DMPs
# -------------------------------------------------------------------
- test 'GET /plans/publicly_available should resolve to ProjectsController#publicly_available' do
- target = {controller: "projects", action: "publicly_available"}
- assert_routing "#{plans_publicly_available_path}", target
+ test 'GET /public_plans should resolve to ProjectsController#public_plans' do
+ target = {controller: "projects", action: "public_plans", locale: "#{I18n.locale}"}
+ assert_routing public_plans_path(locale: I18n.locale), target
end
test 'GET /projects/[:project_id]/plans/[:id]/public_export should resolve to PlansController#public_export' do
project = Project.includes(:plans).where.not(plans: {id: nil}).first
- target = {controller: "plans", action: "public_export", locale: "#{I18n.locale}"}
+ target = {controller: "projects", action: "public_export", locale: "#{I18n.locale}", id: project.id.to_s}
-puts "PATH: /#{I18n.locale}/projects/#{project.id}/plans/#{project.plans.first.id}/public_export"
-
- assert_routing "/#{I18n.locale}/#{public_export_project_plan_path(project, project.plans.first)}", target
+ assert_routing public_export_project_path(locale: I18n.locale, id: project), target
end
# OAuth - Based on providers identified in the en-UK locale file