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 %> +
+ <%= raw t("helpers.project.publicly_available_text", {app_name: Rails.configuration.branding[:application][:name]}) %> +
+ +| + |
|---|
| + <%= link_to t("helpers.project.tab_export"), "#{public_export_project_plan_path(project, project.plans.first)}", :class => "dmp_table_link" %> + | +
+ <%= raw t("helpers.project.project_text_when_no_project")%> +
+<% end %> diff --git a/config/locales/en-UK.yml b/config/locales/en-UK.yml index ded4d2a..e3cc3b7 100644 --- a/config/locales/en-UK.yml +++ b/config/locales/en-UK.yml @@ -338,6 +338,10 @@ about_us_label: "About" roadmap_label: "Future plans" help_label: "Help" + +#----- + publicly_available_label: "Public DMPs" + contact_label: "Contact" jisc: "The %{organisation_abbreviation} is funded by" format: "format" @@ -584,6 +588,11 @@ project_is_test_help_text: "This plan is for testing or practice puposes. It will not be viewable by other users unless you explicitly share it with them (it will however be factored into site statistics)." project_is_public: "Publicly available on the web?" project_is_public_help_text: "Your plan will appear on the Public DMPs page of this site." + +#----- + publicly_available_title: "Public DMPs" + publicly_available_text: "Public DMPs are plans created using %{app_name} and shared publicly by their owners. They are not vetted for quality, completeness, or adherence to funder guidelines." + project_settings_text: "The items you select here will be displayed in the table below. You can sort the data by each of these headings or filter by entering a text string in the search box." project_text_when_no_project: "Welcome. You are now ready to create your first DMP.Click the 'Create plan' button below to begin.
" project_text_when_project: "The table below lists the plans that you have created, and any that have been shared with you by others.These can be edited, shared, exported or deleted at anytime.
" @@ -637,6 +646,10 @@ description: "Description" unknown: " - " visibility: "Visibility" +#----- + template: "Template" + organisation: "Organisation" + filter: placeholder: "Filter plans" submit: "Filter" diff --git a/config/routes.rb b/config/routes.rb index 02f2e14..7660d42 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -48,6 +48,8 @@ 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" #post 'contact_form' => 'contacts', as: 'localized_contact_creation' #get 'contact_form' => 'contacts#new', as: 'localized_contact_form' @@ -141,6 +143,7 @@ get 'export' get 'warning' get 'section_answers' + get 'public-export' end end diff --git a/db/schema.rb b/db/schema.rb index ad437b0..9ef95ef 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -18,8 +18,8 @@ t.integer "plan_id", limit: 4 t.integer "user_id", limit: 4 t.integer "question_id", limit: 4 - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.datetime "created_at" + t.datetime "updated_at" end create_table "answers_options", id: false, force: :cascade do |t| @@ -27,14 +27,14 @@ t.integer "option_id", limit: 4, null: false end - add_index "answers_options", ["answer_id", "option_id"], name: "index_answers_options_on_answer_id_and_option_id" + add_index "answers_options", ["answer_id", "option_id"], name: "index_answers_options_on_answer_id_and_option_id", using: :btree create_table "comments", force: :cascade do |t| t.integer "user_id", limit: 4 t.integer "question_id", limit: 4 t.text "text", limit: 65535 - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.datetime "created_at" + t.datetime "updated_at" t.boolean "archived" t.integer "plan_id", limit: 4 t.integer "archived_by", limit: 4 @@ -46,8 +46,8 @@ t.boolean "published" t.integer "user_id", limit: 4 t.integer "organisation_id", limit: 4 - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.datetime "created_at" + t.datetime "updated_at" t.string "locale", limit: 255 t.boolean "is_default" end @@ -61,8 +61,8 @@ t.integer "plan_id", limit: 4 t.integer "user_id", limit: 4 t.string "format", limit: 255 - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.datetime "created_at" + t.datetime "updated_at" end create_table "file_types", force: :cascade do |t| @@ -70,8 +70,8 @@ t.string "icon_name", limit: 255 t.integer "icon_size", limit: 4 t.string "icon_location", limit: 255 - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.datetime "created_at" + t.datetime "updated_at" end create_table "file_uploads", force: :cascade do |t| @@ -82,8 +82,8 @@ t.boolean "published" t.string "location", limit: 255 t.integer "file_type_id", limit: 4 - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.datetime "created_at" + t.datetime "updated_at" end create_table "friendly_id_slugs", force: :cascade do |t| @@ -93,15 +93,15 @@ t.datetime "created_at" end - add_index "friendly_id_slugs", ["slug", "sluggable_type"], name: "index_friendly_id_slugs_on_slug_and_sluggable_type", unique: true - add_index "friendly_id_slugs", ["sluggable_id"], name: "index_friendly_id_slugs_on_sluggable_id" - add_index "friendly_id_slugs", ["sluggable_type"], name: "index_friendly_id_slugs_on_sluggable_type" + add_index "friendly_id_slugs", ["slug", "sluggable_type"], name: "index_friendly_id_slugs_on_slug_and_sluggable_type", unique: true, using: :btree + add_index "friendly_id_slugs", ["sluggable_id"], name: "index_friendly_id_slugs_on_sluggable_id", using: :btree + add_index "friendly_id_slugs", ["sluggable_type"], name: "index_friendly_id_slugs_on_sluggable_type", using: :btree create_table "guidance_groups", force: :cascade do |t| t.string "name", limit: 255 t.integer "organisation_id", limit: 4 - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.datetime "created_at" + t.datetime "updated_at" t.boolean "optional_subset" t.boolean "published" end @@ -111,24 +111,23 @@ t.integer "guidance_group_id", limit: 4, null: false end - add_index "guidance_in_group", ["guidance_id", "guidance_group_id"], name: "index_guidance_in_group_on_guidance_id_and_guidance_group_id" + add_index "guidance_in_group", ["guidance_id", "guidance_group_id"], name: "index_guidance_in_group_on_guidance_id_and_guidance_group_id", using: :btree create_table "guidances", force: :cascade do |t| t.text "text", limit: 65535 t.integer "guidance_group_id", limit: 4 - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.datetime "created_at" + t.datetime "updated_at" t.integer "question_id", limit: 4 t.boolean "published" end create_table "identifier_schemes", force: :cascade do |t| - t.string "name", limit: 255 - t.string "description", limit: 255 + t.string "name", limit: 255 + t.string "description", limit: 255 t.boolean "active" t.datetime "created_at" t.datetime "updated_at" - t.boolean "use_for_login", default: false end create_table "languages", force: :cascade do |t| @@ -142,8 +141,8 @@ t.integer "organisation_id", limit: 4 t.integer "option_id", limit: 4 t.text "text", limit: 65535 - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.datetime "created_at" + t.datetime "updated_at" end create_table "options", force: :cascade do |t| @@ -151,8 +150,8 @@ t.string "text", limit: 255 t.integer "number", limit: 4 t.boolean "is_default" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.datetime "created_at" + t.datetime "updated_at" end create_table "org_token_permissions", force: :cascade do |t| @@ -165,8 +164,8 @@ create_table "organisation_types", force: :cascade do |t| t.string "name", limit: 255 t.text "description", limit: 65535 - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.datetime "created_at" + t.datetime "updated_at" end create_table "organisations", force: :cascade do |t| @@ -177,12 +176,13 @@ t.string "domain", limit: 255 t.string "wayfless_entity", limit: 255 t.integer "stylesheet_file_id", limit: 4 - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.datetime "created_at" + t.datetime "updated_at" t.integer "parent_id", limit: 4 t.boolean "is_other" t.string "sort_name", limit: 255 t.text "banner_text", limit: 65535 + t.string "logo_file_name", limit: 255 t.integer "region_id", limit: 4 t.integer "language_id", limit: 4 t.string "logo_uid", limit: 255 @@ -195,20 +195,20 @@ t.text "description", limit: 65535 t.integer "number", limit: 4 t.integer "dmptemplate_id", limit: 4 - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.datetime "created_at" + t.datetime "updated_at" t.string "slug", limit: 255 end - add_index "phases", ["dmptemplate_id"], name: "index_phases_on_dmptemplate_id" - add_index "phases", ["slug"], name: "index_phases_on_slug", unique: true + add_index "phases", ["dmptemplate_id"], name: "index_phases_on_dmptemplate_id", using: :btree + add_index "phases", ["slug"], name: "index_phases_on_slug", unique: true, using: :btree create_table "plan_sections", force: :cascade do |t| t.integer "user_id", limit: 4 t.integer "section_id", limit: 4 t.integer "plan_id", limit: 4 - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.datetime "created_at" + t.datetime "updated_at" t.datetime "release_time" end @@ -216,8 +216,8 @@ t.boolean "locked" t.integer "project_id", limit: 4 t.integer "version_id", limit: 4 - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.datetime "created_at" + t.datetime "updated_at" end create_table "project_groups", force: :cascade do |t| @@ -225,8 +225,8 @@ t.boolean "project_editor" t.integer "user_id", limit: 4 t.integer "project_id", limit: 4 - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.datetime "created_at" + t.datetime "updated_at" t.boolean "project_administrator" end @@ -235,13 +235,13 @@ t.integer "guidance_group_id", limit: 4, null: false end - add_index "project_guidance", ["project_id", "guidance_group_id"], name: "index_project_guidance_on_project_id_and_guidance_group_id" + add_index "project_guidance", ["project_id", "guidance_group_id"], name: "index_project_guidance_on_project_id_and_guidance_group_id", using: :btree create_table "projects", force: :cascade do |t| t.string "title", limit: 255 t.integer "dmptemplate_id", limit: 4 - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.datetime "created_at" + t.datetime "updated_at" t.string "slug", limit: 255 t.integer "organisation_id", limit: 4 t.string "grant_number", limit: 255 @@ -255,14 +255,14 @@ t.boolean "is_public", default: false end - add_index "projects", ["id", "is_test", "is_public"], name: "index_projects_on_id_and_is_test_and_is_public" - add_index "projects", ["slug"], name: "index_projects_on_slug", unique: true + add_index "projects", ["id", "is_test", "is_public"], name: "index_projects_on_id_and_is_test_and_is_public", using: :btree + add_index "projects", ["slug"], name: "index_projects_on_slug", unique: true, using: :btree create_table "question_formats", force: :cascade do |t| t.string "title", limit: 255 t.text "description", limit: 65535 - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.datetime "created_at" + t.datetime "updated_at" end create_table "questions", force: :cascade do |t| @@ -274,8 +274,8 @@ t.integer "dependency_id", limit: 4 t.text "dependency_text", limit: 65535 t.integer "section_id", limit: 4 - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.datetime "created_at" + t.datetime "updated_at" t.integer "question_format_id", limit: 4 t.boolean "option_comment_display", default: true end @@ -285,7 +285,7 @@ t.integer "theme_id", limit: 4, null: false end - add_index "questions_themes", ["question_id", "theme_id"], name: "index_questions_themes_on_question_id_and_theme_id" + add_index "questions_themes", ["question_id", "theme_id"], name: "index_questions_themes_on_question_id_and_theme_id", using: :btree create_table "region_groups", force: :cascade do |t| t.integer "super_region_id", limit: 4 @@ -300,15 +300,15 @@ create_table "roles", force: :cascade do |t| t.string "name", limit: 255 - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.datetime "created_at" + t.datetime "updated_at" t.boolean "role_in_plans" t.integer "resource_id", limit: 4 t.string "resource_type", limit: 255 end - add_index "roles", ["name"], name: "index_roles_on_name" - add_index "roles", ["name"], name: "index_roles_on_name_and_resource_type_and_resource_id" + add_index "roles", ["name"], name: "index_roles_on_name", using: :btree + add_index "roles", ["name"], name: "index_roles_on_name_and_resource_type_and_resource_id", using: :btree create_table "sections", force: :cascade do |t| t.string "title", limit: 255 @@ -316,8 +316,8 @@ t.integer "number", limit: 4 t.integer "version_id", limit: 4 t.integer "organisation_id", limit: 4 - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.datetime "created_at" + t.datetime "updated_at" t.boolean "published" end @@ -326,32 +326,32 @@ t.text "value", limit: 65535 t.integer "target_id", limit: 4, null: false t.string "target_type", limit: 255, null: false - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.datetime "created_at" + t.datetime "updated_at" end - add_index "settings", ["target_type", "target_id", "var"], name: "index_settings_on_target_type_and_target_id_and_var", unique: true + add_index "settings", ["target_type", "target_id", "var"], name: "index_settings_on_target_type_and_target_id_and_var", unique: true, using: :btree create_table "splash_logs", force: :cascade do |t| t.string "destination", limit: 255 - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.datetime "created_at" + t.datetime "updated_at" end create_table "suggested_answers", force: :cascade do |t| t.integer "question_id", limit: 4 t.integer "organisation_id", limit: 4 t.text "text", limit: 65535 - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.datetime "created_at" + t.datetime "updated_at" t.boolean "is_example" end create_table "themes", force: :cascade do |t| t.string "title", limit: 255 t.text "description", limit: 65535 - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.datetime "created_at" + t.datetime "updated_at" t.string "locale", limit: 255 end @@ -375,28 +375,28 @@ t.integer "identifier_scheme_id", limit: 4 end - add_index "user_identifiers", ["identifier_scheme_id"], name: "fk_rails_fe95df7db0" - add_index "user_identifiers", ["user_id"], name: "fk_rails_65c9a98cdb" + add_index "user_identifiers", ["identifier_scheme_id"], name: "fk_rails_fe95df7db0", using: :btree + add_index "user_identifiers", ["user_id"], name: "fk_rails_65c9a98cdb", using: :btree create_table "user_role_types", force: :cascade do |t| t.string "name", limit: 255 t.text "description", limit: 65535 - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.datetime "created_at" + t.datetime "updated_at" end create_table "user_statuses", force: :cascade do |t| t.string "name", limit: 255 t.text "description", limit: 65535 - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.datetime "created_at" + t.datetime "updated_at" end create_table "user_types", force: :cascade do |t| t.string "name", limit: 255 t.text "description", limit: 65535 - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.datetime "created_at" + t.datetime "updated_at" end create_table "users", force: :cascade do |t| @@ -407,8 +407,8 @@ t.string "shibboleth_id", limit: 255 t.integer "user_type_id", limit: 4 t.integer "user_status_id", limit: 4 - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.datetime "created_at" + t.datetime "updated_at" t.string "encrypted_password", limit: 255, default: "" t.string "reset_password_token", limit: 255 t.datetime "reset_password_sent_at" @@ -426,6 +426,7 @@ t.datetime "invitation_sent_at" t.datetime "invitation_accepted_at" t.string "other_organisation", limit: 255 + t.boolean "dmponline3" t.boolean "accept_terms" t.integer "organisation_id", limit: 4 t.string "api_token", limit: 255 @@ -434,17 +435,17 @@ t.integer "language_id", limit: 4 end - add_index "users", ["confirmation_token"], name: "index_users_on_confirmation_token", unique: true - add_index "users", ["email"], name: "index_users_on_email", unique: true - add_index "users", ["invitation_token"], name: "index_users_on_invitation_token", unique: true - add_index "users", ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true + add_index "users", ["confirmation_token"], name: "index_users_on_confirmation_token", unique: true, using: :btree + add_index "users", ["email"], name: "index_users_on_email", unique: true, using: :btree + add_index "users", ["invitation_token"], name: "index_users_on_invitation_token", unique: true, using: :btree + add_index "users", ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true, using: :btree create_table "users_roles", id: false, force: :cascade do |t| t.integer "user_id", limit: 4 t.integer "role_id", limit: 4 end - add_index "users_roles", ["user_id", "role_id"], name: "index_users_roles_on_user_id_and_role_id" + add_index "users_roles", ["user_id", "role_id"], name: "index_users_roles_on_user_id_and_role_id", using: :btree create_table "versions", force: :cascade do |t| t.string "title", limit: 255 @@ -452,10 +453,12 @@ t.boolean "published" t.integer "number", limit: 4 t.integer "phase_id", limit: 4 - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.datetime "created_at" + t.datetime "updated_at" end - add_index "versions", ["phase_id"], name: "index_versions_on_phase_id" + add_index "versions", ["phase_id"], name: "index_versions_on_phase_id", using: :btree + add_foreign_key "user_identifiers", "identifier_schemes" + add_foreign_key "user_identifiers", "users" end