diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 96c0cc8..675f96c 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -144,6 +144,8 @@ # if the project is designated as public if @project.is_public? + @plan = @project.plans.first + generate_export else @@ -421,14 +423,12 @@ # ----------------------------------------------------------- def generate_export - plan = @project.plans.first - @exported_plan = ExportedPlan.new.tap do |ep| - ep.plan = plan + ep.plan = @plan ep.user = current_user ||= nil #ep.format = request.format.try(:symbol) ep.format = request.format.to_sym - plan_settings = plan.settings(:export) + plan_settings = @plan.settings(:export) Settings::Dmptemplate::DEFAULT_SETTINGS.each do |key, value| ep.settings(:export).send("#{key}=", plan_settings.send(key)) @@ -439,22 +439,22 @@ file_name = @exported_plan.project_name respond_to do |format| - format.html - format.xml - format.json - format.csv { send_data @exported_plan.as_csv, filename: "#{file_name}.csv" } - format.text { send_data @exported_plan.as_txt, filename: "#{file_name}.txt" } + format.html + format.xml + format.json + format.csv { send_data @exported_plan.as_csv, filename: "#{file_name}.csv" } + format.text { send_data @exported_plan.as_txt, filename: "#{file_name}.txt" } format.docx { headers["Content-Disposition"] = "attachment; filename=\"#{file_name}.docx\""} - format.pdf do - @formatting = plan.settings(:export).formatting - render pdf: file_name, - margin: @formatting[:margin], - footer: { - center: t('helpers.plan.export.pdf.generated_by'), - font_size: 8, - spacing: (@formatting[:margin][:bottom] / 2) - 4, - right: '[page] of [topage]' - } + format.pdf do + @formatting = @plan.settings(:export).formatting + render pdf: file_name, + margin: @formatting[:margin], + footer: { + center: t('helpers.plan.export.pdf.generated_by'), + font_size: 8, + spacing: (@formatting[:margin][:bottom] / 2) - 4, + right: '[page] of [topage]' + } end end end diff --git a/app/models/exported_plan.rb b/app/models/exported_plan.rb index 797e0a8..3782b52 100644 --- a/app/models/exported_plan.rb +++ b/app/models/exported_plan.rb @@ -55,9 +55,13 @@ end def orcid - scheme = IdentifierScheme.find_by(name: 'orcid') + scheme = IdentifierScheme.find_by(name: 'orcid') + if self.user.nil? + '' + else orcid = self.user.user_identifiers.where(identifier_scheme: scheme).first (orcid.nil? ? '' : orcid.identifier) + end end # sections taken from fields settings diff --git a/app/models/project.rb b/app/models/project.rb index 0b50de6..8f1946e 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -6,27 +6,14 @@ #associations between tables belongs_to :dmptemplate belongs_to :organisation + + belongs_to :visibility + has_many :plans has_many :project_groups, :dependent => :destroy has_and_belongs_to_many :guidance_groups, join_table: "project_guidance" 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) - self[:is_public] = false if (val == 1 || val == true) && is_public? # val comes in as 1 or 0 - self[:is_test] = val - end - - # Set the is_test flag to false if we are making this plan public - # ----------------------------------------------------------------- - def is_public=(val) - self[:is_test] = false if (val == 1 || val == true) && is_test? # val comes in as 1 or 0 - self[:is_public] = val - end ## # returns the title of the project @@ -35,9 +22,9 @@ def to_s "#{title}" end - + after_create :create_plans - + ## # sets a new funder for the project # defaults to the first dmptemplate if the current template is nill and the funder has more than one dmptemplate @@ -332,39 +319,56 @@ self.dmptemplate.try(:organisation).try(:abbreviation) end + # Visibility shortcuts + # ------------------------------------------------------------------ + def is_test? + visibility == Visibility.find_by(name: 'test') + end + def is_private? + visibility == Visibility.find_by(name: 'private') + end + def is_organisational? + visibility == Visibility.find_by(name: 'organisational') + end + def is_public? + visibility == Visibility.find_by(name: 'public') + end + + + # ================================================================== private + ## + # adds a user to the project + # if no flags are specified, the user is given read privleges + # + # @param user_id [Integer] the user to be given privleges + # @param is_editor [Boolean] whether or not the user can edit the project + # @param is_administrator [Boolean] whether or not the user can administrate the project + # @param is_creator [Boolean] wheter or not the user created the project + # @return [Array] + def add_user(user_id, is_editor = false, is_administrator = false, is_creator = false) + group = ProjectGroup.new + group.user_id = user_id + group.project_creator = is_creator + group.project_editor = is_editor + group.project_administrator = is_administrator + project_groups << group + end - ## - # adds a user to the project - # if no flags are specified, the user is given read privleges - # - # @param user_id [Integer] the user to be given privleges - # @param is_editor [Boolean] whether or not the user can edit the project - # @param is_administrator [Boolean] whether or not the user can administrate the project - # @param is_creator [Boolean] wheter or not the user created the project - # @return [Array] - def add_user(user_id, is_editor = false, is_administrator = false, is_creator = false) - group = ProjectGroup.new - group.user_id = user_id - group.project_creator = is_creator - group.project_editor = is_editor - group.project_administrator = is_administrator - project_groups << group - end - - ## - # creates a plan for each phase in the dmptemplate associated with this project - # unless the phase is unpublished, it creates a new plan, and a new version of the plan and adds them to the project's plans - # - # @return [Array] - def create_plans - dmptemplate.phases.each do |phase| - latest_published_version = phase.latest_published_version - unless latest_published_version.nil? - new_plan = Plan.new - new_plan.version = latest_published_version - plans << new_plan - end - end - end + ## + # creates a plan for each phase in the dmptemplate associated with this project + # unless the phase is unpublished, it creates a new plan, and a new version of the plan and adds them to the project's plans + # + # @return [Array] + def create_plans + dmptemplate.phases.each do |phase| + latest_published_version = phase.latest_published_version + unless latest_published_version.nil? + new_plan = Plan.new + new_plan.version = latest_published_version + plans << new_plan + end + end + end + end diff --git a/app/models/visibility.rb b/app/models/visibility.rb new file mode 100644 index 0000000..26f7270 --- /dev/null +++ b/app/models/visibility.rb @@ -0,0 +1,5 @@ +class Visibility < ActiveRecord::Base + has_many :projects + + validates :name, uniqueness: true, presence: true +end \ No newline at end of file diff --git a/app/views/projects/public_export.html.erb b/app/views/projects/public_export.html.erb new file mode 100644 index 0000000..37f1a18 --- /dev/null +++ b/app/views/projects/public_export.html.erb @@ -0,0 +1,41 @@ +<%- model_class = Project -%> + + +<%= render :partial => "/projects/project_title", locals: {project: @project} %> + + +<%= render :partial => "project_nav_tabs", locals: {project: @project, active: "export_page"} %> + + +
+ + <%= raw t('helpers.project.export_text_html')%> + + + <% if @project.plans.any? %> + <% if @project.plans.count == 1 then %> + <% @project.plans.each do |plan| %> + <%= render :partial => "/shared/export_links", locals: {plan: plan} %> + <% end %> + <%else%> + <% @project.plans.each do |plan| %> +
+
+ +
+
+ <%= render :partial => "/shared/export_links", locals: {plan: plan} %> +
+
+
+
+ <%end%> + <%end%> + <%end%> + +
\ No newline at end of file diff --git a/app/views/projects/public_export.pdf.erb b/app/views/projects/public_export.pdf.erb new file mode 100644 index 0000000..77d68cb --- /dev/null +++ b/app/views/projects/public_export.pdf.erb @@ -0,0 +1,72 @@ + + + + + + <% if @plan.project.dmptemplate.phases.count > 1 then %> + <%= "#{@plan.project.title} - #{@plan.title}" %> + <% else %> + <%= @plan.project.title %> + <% end %> + + + + +

<%= @plan.title %>

+ <% @exported_plan.admin_details.each do |field| + value = @exported_plan.send(field) + if value.present? + %> +

<%= t("helpers.plan.export.#{field}") -%> <%= value -%>

+ <% end %> + <% end %> + + <% @exported_plan.sections.each do |section| %> +

<%= section.title %>

+ <% questions = @exported_plan.questions_for_section(section.id) %> + <% questions.each_with_index do |question, idx| %> +
+ <% unless idx == 0 && question.text == section.title %> +

<%= raw question.text %>

+ <% end %> + <% answer = @plan.answer(question.id, false) %> + <% if answer.nil? then %> +

<%= t('helpers.plan.export.pdf.question_not_answered') -%>

+ <% else %> + <% q_format = question.question_format%> + + <% if q_format.title == t("helpers.checkbox") || q_format.title == t("helpers.multi_select_box") || + q_format.title == t("helpers.radio_buttons") || q_format.title == t("helpers.dropdown") then%> +
    + <% answer.options.each do |option| %> +
  • <%= option.text %>
  • + <% end %> +
+ + <% if question.option_comment_display == true then%> + <% if !answer.text.nil? then %> + <%= raw answer.text.gsub(/(\s||<\/td>| )*(<\/tr>|)/,"") %> + <%end%> + <%end%> + <%else%> + + <% if !answer.text.nil? then %> + <%= raw answer.text.gsub(/(\s||<\/td>| )*(<\/tr>|)/,"") %> + <%end%> + <% end %> + <% end %> +
+ <% end %> + <% end %> + + \ No newline at end of file diff --git a/db/schema.rb b/db/schema.rb index c885587..218a45e 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -14,92 +14,92 @@ ActiveRecord::Schema.define(version: 20170105165111) do create_table "answers", force: :cascade do |t| - t.text "text", limit: 65535 - t.integer "plan_id", limit: 4 - t.integer "user_id", limit: 4 - t.integer "question_id", limit: 4 + t.text "text" + t.integer "plan_id" + t.integer "user_id" + t.integer "question_id" t.datetime "created_at" t.datetime "updated_at" end create_table "answers_options", id: false, force: :cascade do |t| - t.integer "answer_id", limit: 4, null: false - t.integer "option_id", limit: 4, null: false + t.integer "answer_id", null: false + t.integer "option_id", null: false end - add_index "answers_options", ["answer_id", "option_id"], name: "index_answers_options_on_answer_id_and_option_id", using: :btree + add_index "answers_options", ["answer_id", "option_id"], name: "index_answers_options_on_answer_id_and_option_id" 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.integer "user_id" + t.integer "question_id" + t.text "text" t.datetime "created_at" t.datetime "updated_at" t.boolean "archived" - t.integer "plan_id", limit: 4 - t.integer "archived_by", limit: 4 + t.integer "plan_id" + t.integer "archived_by" end create_table "dmptemplates", force: :cascade do |t| - t.string "title", limit: 255 - t.text "description", limit: 65535 + t.string "title" + t.text "description" t.boolean "published" - t.integer "user_id", limit: 4 - t.integer "organisation_id", limit: 4 + t.integer "user_id" + t.integer "organisation_id" t.datetime "created_at" t.datetime "updated_at" - t.string "locale", limit: 255 + t.string "locale" t.boolean "is_default" end create_table "dmptemplates_guidance_groups", id: false, force: :cascade do |t| - t.integer "dmptemplate_id", limit: 4 - t.integer "guidance_group_id", limit: 4 + t.integer "dmptemplate_id" + t.integer "guidance_group_id" end create_table "exported_plans", force: :cascade do |t| - t.integer "plan_id", limit: 4 - t.integer "user_id", limit: 4 - t.string "format", limit: 255 + t.integer "plan_id" + t.integer "user_id" + t.string "format" t.datetime "created_at" t.datetime "updated_at" end create_table "file_types", force: :cascade do |t| - t.string "name", limit: 255 - t.string "icon_name", limit: 255 - t.integer "icon_size", limit: 4 - t.string "icon_location", limit: 255 + t.string "name" + t.string "icon_name" + t.integer "icon_size" + t.string "icon_location" t.datetime "created_at" t.datetime "updated_at" end create_table "file_uploads", force: :cascade do |t| - t.string "name", limit: 255 - t.string "title", limit: 255 - t.text "description", limit: 65535 - t.integer "size", limit: 4 + t.string "name" + t.string "title" + t.text "description" + t.integer "size" t.boolean "published" - t.string "location", limit: 255 - t.integer "file_type_id", limit: 4 + t.string "location" + t.integer "file_type_id" t.datetime "created_at" t.datetime "updated_at" end create_table "friendly_id_slugs", force: :cascade do |t| - t.string "slug", limit: 191, null: false - t.integer "sluggable_id", limit: 4, null: false + t.string "slug", null: false + t.integer "sluggable_id", null: false t.string "sluggable_type", limit: 40 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, 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 + 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" create_table "guidance_groups", force: :cascade do |t| - t.string "name", limit: 255 - t.integer "organisation_id", limit: 4 + t.string "name" + t.integer "organisation_id" t.datetime "created_at" t.datetime "updated_at" t.boolean "optional_subset" @@ -107,106 +107,106 @@ end create_table "guidance_in_group", id: false, force: :cascade do |t| - t.integer "guidance_id", limit: 4, null: false - t.integer "guidance_group_id", limit: 4, null: false + t.integer "guidance_id", null: false + t.integer "guidance_group_id", 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", using: :btree + add_index "guidance_in_group", ["guidance_id", "guidance_group_id"], name: "index_guidance_in_group_on_guidance_id_and_guidance_group_id" create_table "guidances", force: :cascade do |t| - t.text "text", limit: 65535 - t.integer "guidance_group_id", limit: 4 + t.text "text" + t.integer "guidance_group_id" t.datetime "created_at" t.datetime "updated_at" - t.integer "question_id", limit: 4 + t.integer "question_id" 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" + t.string "description" t.boolean "active" t.datetime "created_at" t.datetime "updated_at" end create_table "languages", force: :cascade do |t| - t.string "abbreviation", limit: 255 - t.string "description", limit: 255 - t.string "name", limit: 255 + t.string "abbreviation" + t.string "description" + t.string "name" t.boolean "default_language" end create_table "option_warnings", force: :cascade do |t| - t.integer "organisation_id", limit: 4 - t.integer "option_id", limit: 4 - t.text "text", limit: 65535 + t.integer "organisation_id" + t.integer "option_id" + t.text "text" t.datetime "created_at" t.datetime "updated_at" end create_table "options", force: :cascade do |t| - t.integer "question_id", limit: 4 - t.string "text", limit: 255 - t.integer "number", limit: 4 + t.integer "question_id" + t.string "text" + t.integer "number" t.boolean "is_default" t.datetime "created_at" t.datetime "updated_at" end create_table "org_token_permissions", force: :cascade do |t| - t.integer "organisation_id", limit: 4 - t.integer "token_permission_type_id", limit: 4 + t.integer "organisation_id" + t.integer "token_permission_type_id" t.datetime "created_at" t.datetime "updated_at" end create_table "organisation_types", force: :cascade do |t| - t.string "name", limit: 255 - t.text "description", limit: 65535 + t.string "name" + t.text "description" t.datetime "created_at" t.datetime "updated_at" end create_table "organisations", force: :cascade do |t| - t.string "name", limit: 255 - t.string "abbreviation", limit: 255 - t.string "target_url", limit: 255 - t.integer "organisation_type_id", limit: 4 - t.string "domain", limit: 255 - t.string "wayfless_entity", limit: 255 - t.integer "stylesheet_file_id", limit: 4 + t.string "name" + t.string "abbreviation" + t.string "target_url" + t.integer "organisation_type_id" + t.string "domain" + t.string "wayfless_entity" + t.integer "stylesheet_file_id" t.datetime "created_at" t.datetime "updated_at" - t.integer "parent_id", limit: 4 + t.integer "parent_id" 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 - t.string "logo_name", limit: 255 - t.string "contact_email", limit: 255 + t.string "sort_name" + t.text "banner_text" + t.string "logo_file_name" + t.integer "region_id" + t.integer "language_id" + t.string "logo_uid" + t.string "logo_name" + t.string "contact_email" end create_table "phases", force: :cascade do |t| - t.string "title", limit: 255 - t.text "description", limit: 65535 - t.integer "number", limit: 4 - t.integer "dmptemplate_id", limit: 4 + t.string "title" + t.text "description" + t.integer "number" + t.integer "dmptemplate_id" t.datetime "created_at" t.datetime "updated_at" - t.string "slug", limit: 191 + t.string "slug" end - 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 + add_index "phases", ["dmptemplate_id"], name: "index_phases_on_dmptemplate_id" + add_index "phases", ["slug"], name: "index_phases_on_slug", unique: true 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.integer "user_id" + t.integer "section_id" + t.integer "plan_id" t.datetime "created_at" t.datetime "updated_at" t.datetime "release_time" @@ -214,8 +214,8 @@ create_table "plans", force: :cascade do |t| t.boolean "locked" - t.integer "project_id", limit: 4 - t.integer "version_id", limit: 4 + t.integer "project_id" + t.integer "version_id" t.datetime "created_at" t.datetime "updated_at" end @@ -223,249 +223,242 @@ create_table "project_groups", force: :cascade do |t| t.boolean "project_creator" t.boolean "project_editor" - t.integer "user_id", limit: 4 - t.integer "project_id", limit: 4 + t.integer "user_id" + t.integer "project_id" t.datetime "created_at" t.datetime "updated_at" t.boolean "project_administrator" end create_table "project_guidance", id: false, force: :cascade do |t| - t.integer "project_id", limit: 4, null: false - t.integer "guidance_group_id", limit: 4, null: false + t.integer "project_id", null: false + t.integer "guidance_group_id", null: false end - add_index "project_guidance", ["project_id", "guidance_group_id"], name: "index_project_guidance_on_project_id_and_guidance_group_id", using: :btree + add_index "project_guidance", ["project_id", "guidance_group_id"], name: "index_project_guidance_on_project_id_and_guidance_group_id" create_table "projects", force: :cascade do |t| - t.string "title", limit: 255 - t.integer "dmptemplate_id", limit: 4 + t.string "title" + t.integer "dmptemplate_id" t.datetime "created_at" t.datetime "updated_at" - t.string "slug", limit: 191 - t.integer "organisation_id", limit: 4 - t.string "grant_number", limit: 255 - t.string "identifier", limit: 255 - t.text "description", limit: 65535 - t.string "principal_investigator", limit: 255 - t.string "principal_investigator_identifier", limit: 255 - t.string "data_contact", limit: 255 - t.string "funder_name", limit: 255 - t.integer "visibility_id", limit: 4 + t.string "slug" + t.integer "organisation_id" + t.string "grant_number" + t.string "identifier" + t.text "description" + t.string "principal_investigator" + t.string "principal_investigator_identifier" + t.string "data_contact" + t.string "funder_name" + t.integer "visibility_id" end - add_index "projects", ["slug"], name: "index_projects_on_slug", unique: true, using: :btree - add_index "projects", ["visibility_id"], name: "fk_rails_391d5d7362", using: :btree + add_index "projects", ["slug"], name: "index_projects_on_slug", unique: true create_table "question_formats", force: :cascade do |t| - t.string "title", limit: 255 - t.text "description", limit: 65535 + t.string "title" + t.text "description" t.datetime "created_at" t.datetime "updated_at" end create_table "questions", force: :cascade do |t| - t.text "text", limit: 65535 - t.text "default_value", limit: 65535 - t.text "guidance", limit: 65535 - t.integer "number", limit: 4 - t.integer "parent_id", limit: 4 - t.integer "dependency_id", limit: 4 - t.text "dependency_text", limit: 65535 - t.integer "section_id", limit: 4 + t.text "text" + t.text "default_value" + t.text "guidance" + t.integer "number" + t.integer "parent_id" + t.integer "dependency_id" + t.text "dependency_text" + t.integer "section_id" t.datetime "created_at" t.datetime "updated_at" - t.integer "question_format_id", limit: 4 - t.boolean "option_comment_display", default: true + t.integer "question_format_id" + t.boolean "option_comment_display", default: true end create_table "questions_themes", id: false, force: :cascade do |t| - t.integer "question_id", limit: 4, null: false - t.integer "theme_id", limit: 4, null: false + t.integer "question_id", null: false + t.integer "theme_id", null: false end - add_index "questions_themes", ["question_id", "theme_id"], name: "index_questions_themes_on_question_id_and_theme_id", using: :btree + add_index "questions_themes", ["question_id", "theme_id"], name: "index_questions_themes_on_question_id_and_theme_id" create_table "region_groups", force: :cascade do |t| - t.integer "super_region_id", limit: 4 - t.integer "region_id", limit: 4 + t.integer "super_region_id" + t.integer "region_id" end create_table "regions", force: :cascade do |t| - t.string "abbreviation", limit: 255 - t.string "description", limit: 255 - t.string "name", limit: 255 + t.string "abbreviation" + t.string "description" + t.string "name" end create_table "roles", force: :cascade do |t| - t.string "name", limit: 191 + t.string "name" 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 + t.integer "resource_id" + t.string "resource_type" end - 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 + add_index "roles", ["name"], name: "index_roles_on_name" + add_index "roles", ["name"], name: "index_roles_on_name_and_resource_type_and_resource_id" create_table "sections", force: :cascade do |t| - t.string "title", limit: 255 - t.text "description", limit: 65535 - t.integer "number", limit: 4 - t.integer "version_id", limit: 4 - t.integer "organisation_id", limit: 4 + t.string "title" + t.text "description" + t.integer "number" + t.integer "version_id" + t.integer "organisation_id" t.datetime "created_at" t.datetime "updated_at" t.boolean "published" end create_table "settings", force: :cascade do |t| - t.string "var", limit: 191, null: false - t.text "value", limit: 65535 - t.integer "target_id", limit: 4, null: false - t.string "target_type", limit: 191, null: false + t.string "var", null: false + t.text "value" + t.integer "target_id", null: false + t.string "target_type", 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, using: :btree + add_index "settings", ["target_type", "target_id", "var"], name: "index_settings_on_target_type_and_target_id_and_var", unique: true create_table "splash_logs", force: :cascade do |t| - t.string "destination", limit: 255 + t.string "destination" 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.integer "question_id" + t.integer "organisation_id" + t.text "text" 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.string "title" + t.text "description" t.datetime "created_at" t.datetime "updated_at" - t.string "locale", limit: 255 + t.string "locale" end create_table "themes_in_guidance", id: false, force: :cascade do |t| - t.integer "theme_id", limit: 4 - t.integer "guidance_id", limit: 4 + t.integer "theme_id" + t.integer "guidance_id" end create_table "token_permission_types", force: :cascade do |t| - t.string "token_type", limit: 255 - t.text "text_description", limit: 65535 + t.string "token_type" + t.text "text_description" t.datetime "created_at" t.datetime "updated_at" end create_table "user_identifiers", force: :cascade do |t| - t.string "identifier", limit: 255 + t.string "identifier" t.datetime "created_at" t.datetime "updated_at" - t.integer "user_id", limit: 4 - t.integer "identifier_scheme_id", limit: 4 + t.integer "user_id" + t.integer "identifier_scheme_id" end - 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.string "name" + t.text "description" 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.string "name" + t.text "description" 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.string "name" + t.text "description" t.datetime "created_at" t.datetime "updated_at" end create_table "users", force: :cascade do |t| - t.string "firstname", limit: 255 - t.string "surname", limit: 255 - t.string "email", limit: 191, default: "", null: false - t.string "orcid_id", limit: 255 - t.string "shibboleth_id", limit: 255 - t.integer "user_type_id", limit: 4 - t.integer "user_status_id", limit: 4 + t.string "firstname" + t.string "surname" + t.string "email", default: "", null: false + t.string "orcid_id" + t.string "shibboleth_id" + t.integer "user_type_id" + t.integer "user_status_id" t.datetime "created_at" t.datetime "updated_at" - t.string "encrypted_password", limit: 255, default: "" - t.string "reset_password_token", limit: 191 + t.string "encrypted_password", default: "" + t.string "reset_password_token" t.datetime "reset_password_sent_at" t.datetime "remember_created_at" - t.integer "sign_in_count", limit: 4, default: 0 + t.integer "sign_in_count", default: 0 t.datetime "current_sign_in_at" t.datetime "last_sign_in_at" - t.string "current_sign_in_ip", limit: 255 - t.string "last_sign_in_ip", limit: 255 - t.string "confirmation_token", limit: 191 + t.string "current_sign_in_ip" + t.string "last_sign_in_ip" + t.string "confirmation_token" t.datetime "confirmed_at" t.datetime "confirmation_sent_at" - t.string "invitation_token", limit: 191 + t.string "invitation_token" t.datetime "invitation_created_at" t.datetime "invitation_sent_at" t.datetime "invitation_accepted_at" - t.string "other_organisation", limit: 255 + t.string "other_organisation" t.boolean "dmponline3" t.boolean "accept_terms" - t.integer "organisation_id", limit: 4 - t.string "api_token", limit: 255 - t.integer "invited_by_id", limit: 4 - t.string "invited_by_type", limit: 255 - t.integer "language_id", limit: 4 + t.integer "organisation_id" + t.string "api_token" + t.integer "invited_by_id" + t.string "invited_by_type" + t.integer "language_id" end - 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 + 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 create_table "users_roles", id: false, force: :cascade do |t| - t.integer "user_id", limit: 4 - t.integer "role_id", limit: 4 + t.integer "user_id" + t.integer "role_id" end - add_index "users_roles", ["user_id", "role_id"], name: "index_users_roles_on_user_id_and_role_id", using: :btree + add_index "users_roles", ["user_id", "role_id"], name: "index_users_roles_on_user_id_and_role_id" create_table "versions", force: :cascade do |t| - t.string "title", limit: 255 - t.text "description", limit: 65535 - t.boolean "published" - t.integer "number", limit: 4 - t.integer "phase_id", limit: 4 + t.string "title" + t.text "description" + t.integer "number" + t.integer "phase_id" t.datetime "created_at" t.datetime "updated_at" + t.boolean "published" end - add_index "versions", ["phase_id"], name: "index_versions_on_phase_id", using: :btree + add_index "versions", ["phase_id"], name: "index_versions_on_phase_id" create_table "visibilities", force: :cascade do |t| - t.string "name", limit: 255 - t.boolean "default", default: false + t.string "name" + t.boolean "default", default: false t.datetime "created_at" t.datetime "updated_at" end - add_foreign_key "projects", "visibilities" - add_foreign_key "user_identifiers", "identifier_schemes" - add_foreign_key "user_identifiers", "users" end diff --git a/test/fixtures/plans.yml b/test/fixtures/plans.yml index dbd8f76..ee53434 100644 --- a/test/fixtures/plans.yml +++ b/test/fixtures/plans.yml @@ -1,9 +1,9 @@ -test_project_1_plan_1: - locked: false - project: test_project_1 - version: funder_template_2_phase_1_version_1 +<% projects = YAML::load(ERB.new(File.read('./test/fixtures/projects.yml')).result) %> +<% versions = YAML::load(ERB.new(File.read('./test/fixtures/versions.yml')).result) %> -test_project_2_plan_2: +<% projects.each do |lbl, hash| %> +<%= lbl %>_plan: + project: <%= lbl %> + version: version.first locked: false - project: test_project_2 - version: funder_template_2_phase_1_version_1 \ No newline at end of file +<% end %> \ No newline at end of file diff --git a/test/fixtures/projects.yml b/test/fixtures/projects.yml index a9950d3..506b5c8 100644 --- a/test/fixtures/projects.yml +++ b/test/fixtures/projects.yml @@ -1,27 +1,9 @@ -# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html -#two: -# title: MyString -# note: MyText -# locked: false -# dmptemplate_id: 1 +<% templates = YAML::load(ERB.new(File.read('./test/fixtures/dmptemplates.yml')).result) %> -test_project_1: - title: 'Test Project 1' - dmptemplate: funder_template_3 +<% templates.each do |lbl, hash| %> +<%= lbl %>_project: + title: <%= "#{lbl} Project" %> + dmptemplate: <%= lbl %> organisation: complete - grant_number: 'ABCD' - identifier: '1234567890' - description: 'The first test project' - principal_investigator_identifier: '1234-ABCD' - data_contact: 'someone@test.project.edu' - funder_name: 'Funder 2' - is_test: false - is_public: false - -test_project_2: - title: 'Test Project 2' - dmptemplate: funder_template_3 - organisation: complete - funder_name: 'Funder 2' - is_test: true - is_public: false \ No newline at end of file + user: complete_user +<% end %> \ No newline at end of file diff --git a/test/fixtures/visibilities.yml b/test/fixtures/visibilities.yml new file mode 100644 index 0000000..55faa6e --- /dev/null +++ b/test/fixtures/visibilities.yml @@ -0,0 +1,15 @@ +test: + name: 'test' + default: false + +private: + name: 'private' + default: false + +organisational: + name: 'organisational' + default: true + +public: + name: 'public' + default: false \ No newline at end of file diff --git a/test/functional/projects_controller_test.rb b/test/functional/projects_controller_test.rb index 3626c0a..69a0cb5 100644 --- a/test/functional/projects_controller_test.rb +++ b/test/functional/projects_controller_test.rb @@ -6,11 +6,14 @@ 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.is_public = true + @project.visibility = @public_visibility @project.save! get public_export_project_path(locale: I18n.locale, id: @project) @@ -27,7 +30,7 @@ # ---------------------------------------------------------- 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.is_public = false + @project.visibility = @test_visibility @project.save! get public_export_project_path(locale: I18n.locale, id: @project)