diff --git a/app/views/static_pages/public_plans.html.erb b/app/views/static_pages/public_plans.html.erb new file mode 100644 index 0000000..16cdb15 --- /dev/null +++ b/app/views/static_pages/public_plans.html.erb @@ -0,0 +1,41 @@ +<%- model_class = Project -%> +
+ <%= raw t("public_plans_page.body_text_html", {app_name: Rails.configuration.branding[:application][:name]}) %> +
+ +| + |
|---|
| + <%= link_to t("helpers.project.tab_export"), "#{public_export_path(project)}", :class => "dmp_table_link" %> + | +
+ <%= raw t("public_plans_page.no_plans_body_text_html")%> +
+<% end %> diff --git a/test/functional/static_pages_controller_test.rb b/test/functional/static_pages_controller_test.rb new file mode 100644 index 0000000..2b2096d --- /dev/null +++ b/test/functional/static_pages_controller_test.rb @@ -0,0 +1,50 @@ +class StaticPagesControllerTest < ActionDispatch::IntegrationTest + + include Devise::Test::IntegrationHelpers + + setup do + @project = Project.first + + @test_visibility = Visibility.find_by(name: 'test') + @public_visibility = Visibility.find_by(name: 'public') + end + + # ---------------------------------------------------------- + test "should export the publicly available plan" do + @project.visibility = @public_visibility + @project.save! + +# get public_export_path(locale: I18n.locale, id: @project) + + # Should be redirected to the plans controller's export function +# assert_redirected_to "#{export_project_plan_path(@project, @project.plans.first)}", "expected to be redirected to the exported plan" +# follow_redirect! + +# assert_redirected_to "blah" +# assert_response :success +# assert_equal Mime::PDF, response.content_type + end + + # ---------------------------------------------------------- + test "should NOT export a non-public plan to unauthorized users" do + # Set the is_public flag to false and try to access it when not logged in + @project.visibility = @test_visibility + @project.save! + + get public_export_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" + + # Set the is_public flag to false and assign ownership to a different user and then try to access it as a non-owner + @project.assign_creator(User.last) + @project.save! + + sign_in User.first + + 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 +end \ No newline at end of file