diff --git a/Gemfile b/Gemfile index 6da36d1..35ee76e 100644 --- a/Gemfile +++ b/Gemfile @@ -15,6 +15,7 @@ # ------------------------------------------------ # DATABASE/SERVER +gem 'mysql2', '~> 0.3.18' gem 'pg' gem 'flag_shih_tzu' # Allows for bitfields in activereccord diff --git a/Gemfile.lock b/Gemfile.lock index 3e73784..8359a7c 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -218,6 +218,7 @@ multi_json (1.12.1) multi_xml (0.5.5) multipart-post (2.0.0) + mysql2 (0.3.21) nokogiri (1.6.8) mini_portile2 (~> 2.1.0) pkg-config (~> 1.1.7) @@ -381,6 +382,7 @@ libv8 minitest-rails-capybara minitest-reporters + mysql2 (~> 0.3.18) omniauth omniauth-orcid omniauth-shibboleth diff --git a/app/models/answer.rb b/app/models/answer.rb index 00705da..385f4fe 100644 --- a/app/models/answer.rb +++ b/app/models/answer.rb @@ -11,11 +11,12 @@ # Possibly needed for active_admin # -relies on protected_attributes gem as syntax depricated in rails 4.2 attr_accessible :text, :plan_id, :question_id, :user_id, :option_ids, - :question, :user, :plan, :as => [:default, :admin] + :question, :user, :plan, :question_options, + :as => [:default, :admin] ## # Validations - validates :user, :plan, :question, :text, presence: true + validates :user, :plan, :question, presence: true # Make sure there is only one answer per question! validates :question, uniqueness: {scope: [:user, :plan], diff --git a/app/models/guidance_group.rb b/app/models/guidance_group.rb index 932a921..f55b5d0 100644 --- a/app/models/guidance_group.rb +++ b/app/models/guidance_group.rb @@ -11,7 +11,7 @@ # Possibly needed for active_admin # -relies on protected_attributes gem as syntax depricated in rails 4.2 attr_accessible :organisation_id, :name, :optional_subset, :published, - :organisation, :as => [:default, :admin] + :organisation, :org, :as => [:default, :admin] attr_accessible :dmptemplate_ids, :as => [:default, :admin] @@ -25,7 +25,7 @@ - validates :name, :organisation, presence: true + validates :name, :org, presence: true ## # Converts a guidance group to a string containing the display name diff --git a/app/models/org.rb b/app/models/org.rb index 46f5d72..83899ae 100644 --- a/app/models/org.rb +++ b/app/models/org.rb @@ -20,7 +20,8 @@ attr_accessible :abbreviation, :banner_text, :logo, :remove_logo, :logo_file_name, :name, :target_url, :organisation_type_id, :wayfless_entity, :parent_id, :sort_name, - :token_permission_type_ids, :language_id, :contact_email, :language + :token_permission_type_ids, :language_id, :contact_email, + :language, :org_type, :region, :token_permission_types ## # Validators diff --git a/app/models/phase.rb b/app/models/phase.rb index df47877..a7be93d 100644 --- a/app/models/phase.rb +++ b/app/models/phase.rb @@ -15,7 +15,7 @@ ## # Possibly needed for active_admin # -relies on protected_attributes gem as syntax depricated in rails 4.2 - attr_accessible :description, :number, :title, :template_id, + attr_accessible :description, :number, :title, :template_id, :modifiable, :template, :sections, :as => [:default, :admin] ## diff --git a/app/models/plan.rb b/app/models/plan.rb index a6c36c6..fc52536 100644 --- a/app/models/plan.rb +++ b/app/models/plan.rb @@ -13,7 +13,10 @@ # Possibly needed for active_admin # -relies on protected_attributes gem as syntax depricated in rails 4.2 attr_accessible :locked, :project_id, :version_id, :version, :plan_sections, - :exported_plans, :project, :as => [:default, :admin] + :exported_plans, :project, :title, :template, :grant_number, + :identifier, :principal_investigator, :principal_investigator_identifier, + :description, :data_contact, :funder_name, :visibility, + :as => [:default, :admin] # public is a Ruby keyword so using publicly enum visibility: [:organisationally_visible, :publicly_visible, :is_test, :privately_visible] diff --git a/app/models/question.rb b/app/models/question.rb index d0fde11..7a91897 100644 --- a/app/models/question.rb +++ b/app/models/question.rb @@ -24,7 +24,8 @@ :suggested_answer, :text, :section_id, :question_format_id, :question_options_attributes, :suggested_answers_attributes, :option_comment_display, :theme_ids, :section, :question_format, - :question_options, :suggested_answers, :answers, :themes, :as => [:default, :admin] + :question_options, :suggested_answers, :answers, :themes, + :modifiable, :option_comment_display, :as => [:default, :admin] diff --git a/app/models/question_option.rb b/app/models/question_option.rb index b16b0d9..6fa289d 100644 --- a/app/models/question_option.rb +++ b/app/models/question_option.rb @@ -7,5 +7,6 @@ ## # Possibly needed for active_admin # -relies on protected_attributes gem as syntax depricated in rails 4.2 - attr_accessible :text, :question_id, :is_default, :number, :as => [:default, :admin] + attr_accessible :text, :question_id, :is_default, :number, :question, + :as => [:default, :admin] end diff --git a/app/models/section.rb b/app/models/section.rb index 3577dd9..f967e16 100644 --- a/app/models/section.rb +++ b/app/models/section.rb @@ -10,8 +10,9 @@ accepts_nested_attributes_for :questions, :reject_if => lambda {|a| a[:text].blank? }, :allow_destroy => true # accepts_nested_attributes_for :version - attr_accessible :organisation_id, :description, :number, :title, :published, :questions_attributes, - :organisation, :as => [:default, :admin] + attr_accessible :organisation_id, :description, :number, :title, :published, + :questions_attributes, :organisation, :phase, :modifiable, + :as => [:default, :admin] ## # return the title of the section diff --git a/app/models/suggested_answer.rb b/app/models/suggested_answer.rb index b4df355..5b94c8d 100644 --- a/app/models/suggested_answer.rb +++ b/app/models/suggested_answer.rb @@ -8,7 +8,8 @@ ## # Possibly needed for active_admin # -relies on protected_attributes gem as syntax depricated in rails 4.2 - attr_accessible :org_id, :question_id, :text, :is_example, :as => [:default, :admin] + attr_accessible :org_id, :question_id, :text, :is_example, + :org, :question, :as => [:default, :admin] # EVALUATE CLASS AND INSTANCE METHODS BELOW diff --git a/app/models/template.rb b/app/models/template.rb index fbee582..63b48de 100644 --- a/app/models/template.rb +++ b/app/models/template.rb @@ -12,8 +12,9 @@ ## # Possibly needed for active_admin # -relies on protected_attributes gem as syntax depricated in rails 4.2 - attr_accessible :id, :organisation_id, :description, :published, :title, :locale, :is_default, - :guidance_group_ids, :organisation, :plans, :phases, :as => [:default, :admin] + attr_accessible :id, :org_id, :description, :published, :title, :locale, + :is_default, :guidance_group_ids, :org, :plans, :phases, + :version, :visibility, :published, :as => [:default, :admin] # defines the export setting for a template object has_settings :export, class_name: 'Settings::Template' do |s| diff --git a/app/models/user.rb b/app/models/user.rb index 4070aac..dec3d0e 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -43,7 +43,7 @@ :firstname, :last_login,:login_count, :orcid_id, :password, :shibboleth_id, :user_status_id, :surname, :user_type_id, :org_id, :skip_invitation, :other_organisation, :accept_terms, :role_ids, :dmponline3, :api_token, - :organisation, :language, :language_id + :organisation, :language, :language_id, :perms, :confirmed_at validates :email, email: true, allow_nil: true, uniqueness: true diff --git a/db/schema.rb b/db/schema.rb index 4b37f74..d5a1e90 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -14,349 +14,428 @@ ActiveRecord::Schema.define(version: 20170124235829) do create_table "answers", force: :cascade do |t| - t.text "text" - t.integer "plan_id" - t.integer "user_id" - t.integer "question_id" + t.text "text", limit: 65535 + t.integer "plan_id", limit: 4 + t.integer "user_id", limit: 4 + t.integer "question_id", limit: 4 t.datetime "created_at" t.datetime "updated_at" end + add_index "answers", ["plan_id"], name: "fk_rails_84a6005a3e", using: :btree + add_index "answers", ["question_id"], name: "fk_rails_3d5ed4418f", using: :btree + add_index "answers", ["user_id"], name: "fk_rails_584be190c2", using: :btree + create_table "answers_question_options", id: false, force: :cascade do |t| - t.integer "answer_id", null: false - t.integer "question_option_id", null: false + t.integer "answer_id", limit: 4, null: false + t.integer "question_option_id", limit: 4, null: false end - add_index "answers_question_options", ["answer_id", "question_option_id"], name: "answer_question_option_index" - add_index "answers_question_options", ["question_option_id", "answer_id"], name: "question_option_answer_index" + add_index "answers_question_options", ["answer_id", "question_option_id"], name: "answer_question_option_index", using: :btree + add_index "answers_question_options", ["question_option_id", "answer_id"], name: "question_option_answer_index", using: :btree create_table "exported_plans", force: :cascade do |t| - t.integer "plan_id" - t.integer "user_id" - t.string "format" + t.integer "plan_id", limit: 4 + t.integer "user_id", limit: 4 + t.string "format", limit: 255 t.datetime "created_at" t.datetime "updated_at" end create_table "file_types", force: :cascade do |t| - t.string "name" - t.string "icon_name" - t.integer "icon_size" - t.string "icon_location" + t.string "name", limit: 255 + t.string "icon_name", limit: 255 + t.integer "icon_size", limit: 4 + t.string "icon_location", limit: 255 t.datetime "created_at" t.datetime "updated_at" end create_table "file_uploads", force: :cascade do |t| - t.string "name" - t.string "title" - t.text "description" - t.integer "size" + t.string "name", limit: 255 + t.string "title", limit: 255 + t.text "description", limit: 65535 + t.integer "size", limit: 4 t.boolean "published" - t.string "location" - t.integer "file_type_id" + t.string "location", limit: 255 + t.integer "file_type_id", limit: 4 t.datetime "created_at" t.datetime "updated_at" end create_table "friendly_id_slugs", force: :cascade do |t| - t.string "slug", null: false - t.integer "sluggable_id", null: false + t.string "slug", limit: 255, null: false + t.integer "sluggable_id", limit: 4, 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 - 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" - t.integer "org_id" + t.string "name", limit: 255 + t.integer "org_id", limit: 4 t.datetime "created_at" t.datetime "updated_at" t.boolean "optional_subset" t.boolean "published" end + add_index "guidance_groups", ["org_id"], name: "fk_rails_819c1dbbc7", using: :btree + create_table "guidances", force: :cascade do |t| - t.text "text" - t.integer "guidance_group_id" + t.text "text", limit: 65535 + t.integer "guidance_group_id", limit: 4 t.datetime "created_at" t.datetime "updated_at" - t.integer "question_id" + t.integer "question_id", limit: 4 t.boolean "published" end + add_index "guidances", ["guidance_group_id"], name: "fk_rails_20d29da787", using: :btree + create_table "identifier_schemes", force: :cascade do |t| - t.string "name" - t.string "description" + t.string "name", limit: 255 + t.string "description", limit: 255 t.boolean "active" t.datetime "created_at" t.datetime "updated_at" end create_table "languages", force: :cascade do |t| - t.string "abbreviation" - t.string "description" - t.string "name" + t.string "abbreviation", limit: 255 + t.string "description", limit: 255 + t.string "name", limit: 255 t.boolean "default_language" end create_table "notes", force: :cascade do |t| - t.integer "user_id" - t.text "text" + t.integer "user_id", limit: 4 + t.text "text", limit: 65535 t.boolean "archived" - t.integer "answer_id" - t.integer "archived_by" + t.integer "answer_id", limit: 4 + t.integer "archived_by", limit: 4 t.datetime "created_at" t.datetime "updated_at" end + add_index "notes", ["answer_id"], name: "fk_rails_907f8d48bf", using: :btree + add_index "notes", ["user_id"], name: "fk_rails_7f2323ad43", using: :btree + create_table "org_token_permissions", force: :cascade do |t| - t.integer "org_id" - t.integer "token_permission_type_id" + t.integer "org_id", limit: 4 + t.integer "token_permission_type_id", limit: 4 t.datetime "created_at" t.datetime "updated_at" end + add_index "org_token_permissions", ["org_id"], name: "fk_rails_e1db1b22c5", using: :btree + add_index "org_token_permissions", ["token_permission_type_id"], name: "fk_rails_2aa265f538", using: :btree + create_table "orgs", force: :cascade do |t| - t.string "name" - t.string "abbreviation" - t.string "target_url" - t.string "wayfless_entity" + t.string "name", limit: 255 + t.string "abbreviation", limit: 255 + t.string "target_url", limit: 255 + t.string "wayfless_entity", limit: 255 t.datetime "created_at" t.datetime "updated_at" - t.integer "parent_id" + t.integer "parent_id", limit: 4 t.boolean "is_other" - 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" - t.integer "org_type", default: 0, null: false + 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.integer "org_type", limit: 4, default: 0, null: false end + add_index "orgs", ["language_id"], name: "fk_rails_5640112cab", using: :btree + add_index "orgs", ["region_id"], name: "fk_rails_5a6adf6bab", using: :btree + create_table "perms", force: :cascade do |t| - t.string "name" + t.string "name", limit: 255 t.datetime "created_at" t.datetime "updated_at" end - add_index "perms", ["name"], name: "index_perms_on_name" - add_index "perms", ["name"], name: "index_roles_on_name_and_resource_type_and_resource_id" + add_index "perms", ["name"], name: "index_perms_on_name", using: :btree + add_index "perms", ["name"], name: "index_roles_on_name_and_resource_type_and_resource_id", using: :btree create_table "phases", force: :cascade do |t| - t.string "title" - t.text "description" - t.integer "number" - t.integer "template_id" + t.string "title", limit: 255 + t.text "description", limit: 65535 + t.integer "number", limit: 4 + t.integer "template_id", limit: 4 t.datetime "created_at" t.datetime "updated_at" - t.string "slug" + t.string "slug", limit: 255 t.boolean "modifiable" end + add_index "phases", ["template_id"], name: "fk_rails_0f8036cb2e", using: :btree + create_table "plans", force: :cascade do |t| - t.integer "project_id" - t.string "title" - t.integer "template_id" + t.integer "project_id", limit: 4 + t.string "title", limit: 255 + t.integer "template_id", limit: 4 t.datetime "created_at" t.datetime "updated_at" - t.string "slug" - 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", default: 0, null: false + t.string "slug", limit: 255 + 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", limit: 4, default: 0, null: false end + add_index "plans", ["template_id"], name: "fk_rails_3424ca281f", using: :btree + create_table "question_formats", force: :cascade do |t| - t.string "title" - t.text "description" + t.string "title", limit: 255 + t.text "description", limit: 65535 t.datetime "created_at" t.datetime "updated_at" end create_table "question_options", force: :cascade do |t| - t.integer "question_id" - t.string "text" - t.integer "number" + t.integer "question_id", limit: 4 + t.string "text", limit: 255 + t.integer "number", limit: 4 t.boolean "is_default" t.datetime "created_at" t.datetime "updated_at" end + add_index "question_options", ["question_id"], name: "fk_rails_b9c5f61cf9", using: :btree + create_table "questions", force: :cascade do |t| - t.text "text" - t.text "default_value" - t.text "guidance" - t.integer "number" - t.integer "section_id" + t.text "text", limit: 65535 + t.text "default_value", limit: 65535 + t.text "guidance", limit: 65535 + t.integer "number", limit: 4 + t.integer "section_id", limit: 4 t.datetime "created_at" t.datetime "updated_at" - t.integer "question_format_id" - t.boolean "option_comment_display", default: true + t.integer "question_format_id", limit: 4 + t.boolean "option_comment_display", default: true t.boolean "modifiable" end + add_index "questions", ["question_format_id"], name: "fk_rails_4fbc38c8c7", using: :btree + add_index "questions", ["section_id"], name: "fk_rails_c50eadc3e3", using: :btree + create_table "questions_themes", id: false, force: :cascade do |t| - t.integer "question_id", null: false - t.integer "theme_id", null: false + t.integer "question_id", limit: 4, null: false + t.integer "theme_id", limit: 4, null: false end - add_index "questions_themes", ["question_id", "theme_id"], name: "question_theme_index" - add_index "questions_themes", ["theme_id", "question_id"], name: "theme_question_index" + add_index "questions_themes", ["question_id", "theme_id"], name: "question_theme_index", using: :btree + add_index "questions_themes", ["theme_id", "question_id"], name: "theme_question_index", using: :btree create_table "region_groups", force: :cascade do |t| - t.integer "super_region_id" - t.integer "region_id" + t.integer "super_region_id", limit: 4 + t.integer "region_id", limit: 4 end create_table "regions", force: :cascade do |t| - t.string "abbreviation" - t.string "description" - t.string "name" + t.string "abbreviation", limit: 255 + t.string "description", limit: 255 + t.string "name", limit: 255 end create_table "roles", force: :cascade do |t| - t.integer "user_id" - t.integer "plan_id" + t.integer "user_id", limit: 4 + t.integer "plan_id", limit: 4 t.datetime "created_at" t.datetime "updated_at" - t.integer "access", default: 0, null: false + t.integer "access", limit: 4, default: 0, null: false end + add_index "roles", ["plan_id"], name: "fk_rails_a1ce6c2772", using: :btree + add_index "roles", ["user_id"], name: "fk_rails_ab35d699f0", using: :btree + create_table "sections", force: :cascade do |t| - t.string "title" - t.text "description" - t.integer "number" + t.string "title", limit: 255 + t.text "description", limit: 65535 + t.integer "number", limit: 4 t.datetime "created_at" t.datetime "updated_at" t.boolean "published" - t.integer "phase_id" + t.integer "phase_id", limit: 4 t.boolean "modifiable" end + add_index "sections", ["phase_id"], name: "fk_rails_1853581585", using: :btree + create_table "settings", force: :cascade do |t| - t.string "var", null: false - t.text "value" - t.integer "target_id", null: false - t.string "target_type", null: false + t.string "var", limit: 255, null: false + 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" 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" + t.string "destination", limit: 255 t.datetime "created_at" t.datetime "updated_at" end create_table "suggested_answers", force: :cascade do |t| - t.integer "question_id" - t.integer "org_id" - t.text "text" + t.integer "question_id", limit: 4 + t.integer "org_id", limit: 4 + t.text "text", limit: 65535 t.boolean "is_example" t.datetime "created_at" t.datetime "updated_at" end + add_index "suggested_answers", ["org_id"], name: "fk_rails_473de65779", using: :btree + add_index "suggested_answers", ["question_id"], name: "fk_rails_daa60b5b70", using: :btree + create_table "templates", force: :cascade do |t| - t.string "title" - t.text "description" + t.string "title", limit: 255 + t.text "description", limit: 65535 t.boolean "published" - t.integer "org_id" - t.string "locale" + t.integer "org_id", limit: 4 + t.string "locale", limit: 255 t.boolean "is_default" t.datetime "created_at" t.datetime "updated_at" - t.integer "version" - t.integer "visibility" - t.integer "customization_of" - t.integer "dmptemplate_id" + t.integer "version", limit: 4 + t.integer "visibility", limit: 4 + t.integer "customization_of", limit: 4 + t.integer "dmptemplate_id", limit: 4 end + add_index "templates", ["org_id"], name: "fk_rails_481431e1bd", using: :btree + create_table "themes", force: :cascade do |t| - t.string "title" - t.text "description" + t.string "title", limit: 255 + t.text "description", limit: 65535 t.datetime "created_at" t.datetime "updated_at" - t.string "locale" + t.string "locale", limit: 255 end create_table "themes_in_guidance", id: false, force: :cascade do |t| - t.integer "theme_id" - t.integer "guidance_id" + t.integer "theme_id", limit: 4 + t.integer "guidance_id", limit: 4 end + add_index "themes_in_guidance", ["guidance_id"], name: "fk_rails_a5ab9402df", using: :btree + add_index "themes_in_guidance", ["theme_id"], name: "fk_rails_7d708f6f1e", using: :btree + create_table "token_permission_types", force: :cascade do |t| - t.string "token_type" - t.text "text_description" + t.string "token_type", limit: 255 + t.text "text_description", limit: 65535 t.datetime "created_at" t.datetime "updated_at" end create_table "user_identifiers", force: :cascade do |t| - t.string "identifier" + t.string "identifier", limit: 255 t.datetime "created_at" t.datetime "updated_at" - t.integer "user_id" - t.integer "identifier_scheme_id" + t.integer "user_id", limit: 4 + t.integer "identifier_scheme_id", limit: 4 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 "users", force: :cascade do |t| - t.string "firstname" - t.string "surname" - t.string "email", default: "", null: false - t.string "orcid_id" - t.string "shibboleth_id" + t.string "firstname", limit: 255 + t.string "surname", limit: 255 + t.string "email", limit: 255, default: "", null: false + t.string "orcid_id", limit: 255 + t.string "shibboleth_id", limit: 255 t.datetime "created_at" t.datetime "updated_at" - t.string "encrypted_password", default: "" - t.string "reset_password_token" + t.string "encrypted_password", limit: 255, default: "" + t.string "reset_password_token", limit: 255 t.datetime "reset_password_sent_at" t.datetime "remember_created_at" - t.integer "sign_in_count", default: 0 + t.integer "sign_in_count", limit: 4, default: 0 t.datetime "current_sign_in_at" t.datetime "last_sign_in_at" - t.string "current_sign_in_ip" - t.string "last_sign_in_ip" - t.string "confirmation_token" + t.string "current_sign_in_ip", limit: 255 + t.string "last_sign_in_ip", limit: 255 + t.string "confirmation_token", limit: 255 t.datetime "confirmed_at" t.datetime "confirmation_sent_at" - t.string "invitation_token" + t.string "invitation_token", limit: 255 t.datetime "invitation_created_at" t.datetime "invitation_sent_at" t.datetime "invitation_accepted_at" - t.string "other_organisation" + t.string "other_organisation", limit: 255 t.boolean "dmponline3" t.boolean "accept_terms" - t.integer "org_id" - t.string "api_token" - t.integer "invited_by_id" - t.string "invited_by_type" - t.integer "language_id" + t.integer "org_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 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", ["language_id"], name: "fk_rails_45f4f12508", using: :btree + add_index "users", ["org_id"], name: "fk_rails_e73753bccb", using: :btree + add_index "users", ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true, using: :btree create_table "users_perms", id: false, force: :cascade do |t| - t.integer "user_id" - t.integer "perm_id" + t.integer "user_id", limit: 4 + t.integer "perm_id", limit: 4 end - add_index "users_perms", ["user_id", "perm_id"], name: "index_users_perms_on_user_id_and_perm_id" + add_index "users_perms", ["perm_id"], name: "fk_rails_457217c31c", using: :btree + add_index "users_perms", ["user_id", "perm_id"], name: "index_users_perms_on_user_id_and_perm_id", using: :btree + add_foreign_key "answers", "plans" + add_foreign_key "answers", "questions" + add_foreign_key "answers", "users" + add_foreign_key "answers_question_options", "answers" + add_foreign_key "answers_question_options", "question_options" + add_foreign_key "guidance_groups", "orgs" + add_foreign_key "guidances", "guidance_groups" + add_foreign_key "notes", "answers" + add_foreign_key "notes", "users" + add_foreign_key "org_token_permissions", "orgs" + add_foreign_key "org_token_permissions", "token_permission_types" + add_foreign_key "orgs", "languages" + add_foreign_key "orgs", "regions" + add_foreign_key "phases", "templates" + add_foreign_key "plans", "templates" + add_foreign_key "question_options", "questions" + add_foreign_key "questions", "question_formats" + add_foreign_key "questions", "sections" + add_foreign_key "questions_themes", "questions" + add_foreign_key "questions_themes", "themes" + add_foreign_key "roles", "plans" + add_foreign_key "roles", "users" + add_foreign_key "sections", "phases" + add_foreign_key "suggested_answers", "orgs" + add_foreign_key "suggested_answers", "questions" + add_foreign_key "templates", "orgs" + add_foreign_key "themes_in_guidance", "guidances" + add_foreign_key "themes_in_guidance", "themes" + add_foreign_key "user_identifiers", "identifier_schemes" + add_foreign_key "user_identifiers", "users" + add_foreign_key "users", "languages" + add_foreign_key "users", "orgs" + add_foreign_key "users_perms", "perms" + add_foreign_key "users_perms", "users" end diff --git a/db/seeds.rb b/db/seeds.rb index 8a016e0..f4188d4 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -2,777 +2,794 @@ # This file should contain all the record creation needed to seed the database with its default values. # The data can then be loaded with the rake db:seed (or created alongside the db with db:setup). -languages = { - 'English(UK)' => { - abbreviation: 'en-UK', - description: 'UK English language used as default', - name: 'English(UK)', - default_language: true - }, - 'FR' => { - abbreviation: 'fr', - description: '', - name: 'fr', +# Identifier Schemes +# ------------------------------------------------------- +identifier_schemes = [ + {name: 'orcid', description: 'ORCID researcher identifiers', active: true}, + {name: 'shibboleth', description: 'Shibboleth', active: false}, + {name: 'facebook', description: 'Facebook OAuth', active: false} +] +identifier_schemes.map{ |is| IdentifierScheme.create!(is) if IdentifierScheme.find_by(name: is[:name]).nil? } + +# Question Formats +# ------------------------------------------------------- +question_formats = [ + {title: "Text area"}, + {title: "Text field"}, + {title: "Radio buttons"}, + {title: "Check box"}, + {title: "Dropdown"}, + {title: "Multi select box"}, + {title: "Date"} +] +question_formats.map{ |qf| QuestionFormat.create!(qf) if QuestionFormat.find_by(title: qf[:title]).nil? } + +# Languages (check config/locales for any ones not defined here) +# ------------------------------------------------------- +languages = [ + {abbreviation: 'en-UK', + description: 'UK English', + name: 'English (UK)', + default_language: true}, + {abbreviation: 'en-US', + description: 'US English', + name: 'English (US)', + default_language: false}, + {abbreviation: 'fr', + description: 'French', + name: 'French', + default_language: false}, + {abbreviation: 'de', + description: 'German', + name: 'German', + default_language: false}, + {abbreviation: 'es', + description: 'Spanish', + name: 'Spanish', + default_language: false} +] +languages.map{ |l| Language.create!(l) if Language.find_by(abbreviation: l[:abbreviation]).nil? } + +# Scan through the locale files and add an entry if a file is present but +# not defined in this seed file +Dir.entries("#{Rails.root.join("config", "locales").to_s}").each do |f| + if f[-4..-1] == '.yml' + lang = f.gsub('.yml', '') + + if Language.where(abbreviation: lang).empty? + Language.create!({ + abbreviation: lang, + description: lang, + name: lang, default_language: false - }, - 'DE' => { - abbreviation: 'de', - description: '', - name: 'de', - default_language: false - }, - 'ES' => { - abbreviation: 'es', - description: '', - name: 'es', - default_language: false - } -} - -languages.each do |l, details| - if Language.where(name: details[:name]).empty? - language = Language.new - language.abbreviation = details[:abbreviation] - language.description = details[:description] - language.name = details[:name] - language.default_language = details[:default_language] - language.save! - end -end - -regions = { - 'UK' => { - abbreviation: 'uk', - description: 'default region', - name: 'UK', - }, - 'DE' => { - abbreviation: 'de', - description: '', - name: 'DE', - }, - 'Horizon2020' => { - abbreviation: 'horizon', - description: 'European super region', - name: 'Horizon2020', - } -} - -regions.each do |l, details| - if Region.where(name: details[:name]).empty? - region = Region.new - region.abbreviation = details[:abbreviation] - region.description = details[:description] - region.name = details[:name] - region.save! - end -end - -region_groups = { - 'UK' => { - super_region_name: 'Horizon2020', - region_name: 'UK', - }, - 'DE' => { - super_region_name: 'Horizon2020', - region_name: 'DE', - } -} - -region_groups.each do |l, details| - if RegionGroup.find_by(region_id: details[:region_name]).blank? - region_group = RegionGroup.new - region_group.super_region_id = Region.find_by_name(details[:super_region_name]).id - region_group.region_id = Region.find_by_name(details[:region_name]).id - region_group.save! - end -end - -identifier_schemes = { - 'orcid' => { - name: 'orcid', - description: 'ORCID provides a persistent digital identifier for researchers', - active: true - } -} - -identifier_schemes.each do |l, details| - if IdentifierScheme.where(name: details[:name]).empty? - scheme = IdentifierScheme.new({ - name: details[:name], - description: details[:description], - active: details[:active] - }) - scheme.save! - end -end - -organisation_types = { - 'Organisation' => { - name: "Organisation" - }, - 'Funder' => { - name: "Funder" - }, - 'Project' => { - name: "Project" - }, - 'Institution' => { - name: "Institution" - }, - 'Research Institute' => { - name: "Research Institute" - } - } - - organisation_types.each do |org_type, details| - if OrganisationType.where(name: details[:name]).empty? - organisation_type = OrganisationType.new - organisation_type.name = details[:name] - organisation_type.save! - end - end - - organisations = { - 'Your Organization' => { - name: "My Regional Curation Centre", - abbreviation: "RCC", - sort_name: "MyRegionalCurationCenter", - organisation_type: "Organisation", - description: "An example: Regional Curation Center concerned with research data management (typically the organization hosting this website)", - banner_text: "Example: Your Regional Curation Center", - region: 'UK', - language: 'English(UK)' - }, - 'Global Funding Organization' => { - name: "Global Research Center", - abbreviation: "EGRC", - sort_name: "GlobalResearchCenter", - organisation_type: "Funder", - description: "An example: Research funding agency", - banner_text: "Example: Global Research Center", - region: 'UK', - language: 'English(UK)' - }, - 'Regional Funding Organization' => { - name: "Regional Science Federation", - abbreviation: "RegSciFed", - sort_name: "RegionalScienceFederation", - organisation_type: "Funder", - description: "An example: Regional funding agency for scientific research", - banner_text: "Example: Regional Science Federation", - region: 'UK', - language: 'English(UK)' - }, - 'Example Institution'=> { - name: "Capital City College", - abbreviation: "CapColl", - sort_name: "CapitalCityCollege", - organisation_type: "Institution", - description: "An example: Academic institution", - banner_text: "Example: Capital City College ... go mascots!!", - region: 'UK', - language: 'English(UK)' - } - } - - organisations.each do |org, details| - if Org.where(abbreviation: details[:abbreviation]).empty? - organisation = Org.new - organisation.name = details[:name] - organisation.abbreviation = details[:abbreviation] - organisation.sort_name = details[:sort_name] - organisation.organisation_type = OrganisationType.find_by_name(details[:organisation_type]) - organisation.region_id = Region.find_by_name(details[:region]).id - organisation.language_id = Language.find_by_name(details[:language]).id - organisation.save! - end - end - -roles = { - 'admin' => { - name: "admin" #depricated - }, - 'org_admin' => { - name: "org_admin" #depricated - }, - 'user' => { - name: "user" #depricated - }, - 'add_organisations' => { - name: 'add_organisations' - }, - 'change_org_affiliation' => { - name: 'change_org_affiliation' - }, - 'grant_permissions' => { - name: 'grant_permissions' - }, - 'modify_templates' => { - name: 'modify_templates' - }, - 'modify_guidance' => { - name: 'modify_guidance' - }, - 'use_api' => { - name: 'use_api' - }, - 'change_org_details' => { - name: 'change_org_details' - }, - 'grant_api_to_orgs' => { - name: 'grant_api_to_orgs' - } -} - -roles.each do |role, details| - if Role.where(name: details[:name]).empty? - role = Role.new - role.name = details[:name] - role.save! - end -end - -users = { - 'Super admin' => { - email: "super_admin@example.com", - password: "password123", - firstname: "RCC Super", - surname: "Admin", - password_confirmation: "password123", - organisation: "RCC", - language: 'English(UK)', - roles: ['admin','org_admin','add_organisations','change_org_affiliation','grant_permissions','modify_templates','modify_guidance','use_api','change_org_details','grant_api_to_orgs'], - accept_terms: true, - confirmed_at: Time.zone.now - }, - 'Funder admin' => { - email: "funder_admin@example.com", - password: "password123", - password_confirmation: "password123", - firstname: "Funder", - surname: "Admin", - organisation: "RegSciFed", - language: 'English(UK)', - roles: ['org_admin','grant_permissions','modify_templates','modify_guidance','change_org_details'], - accept_terms: true, - confirmed_at: Time.zone.now - }, - 'Organizational admin' => { - email: "org_admin@example.com", - password: "password123", - password_confirmation: "password123", - firstname: "Organization", - surname: "Admin", - organisation: "CapColl", - language: 'English(UK)', - roles: ['org_admin','grant_permissions','modify_templates','modify_guidance','change_org_details'], - accept_terms: true, - confirmed_at: Time.zone.now - }, - 'Organizational user' => { - email: "org_user@example.com", - password: "password123", - password_confirmation: "password123", - firstname: "Jane", - surname: "Researcher", - organisation: "CapColl", - language: 'English(UK)', - roles: ['user'], - accept_terms: true, - confirmed_at: Time.zone.now - }, - 'Organizational user' => { - email: "org_user@example.com", - password: "password123", - password_confirmation: "password123", - firstname: "Jane", - surname: "Researcher", - organisation: "CapColl", - language: 'English(UK)', - roles: ['user'], - accept_terms: true, - confirmed_at: Time.zone.now - } - } - -users.each do |user, details| - if User.where(email: details[:email]).empty? - usr = User.new - else - usr = User.where(email: details[:email]) - end - usr.email = details[:email] - usr.password = details[:password] - usr.password_confirmation = details[:password_confirmation] - usr.confirmed_at = details[:confirmed_at] - usr.organisation_id = Org.find_by_abbreviation(details[:organisation]).id - usr.language_id = Language.find_by_name(details[:language]).id - details[:roles].each do |role| - usr.roles << Role.find_by_name(role) + }) end - usr.accept_terms = details[:accept_terms] - usr.save! -end - - themes = { - "Theme 1" => { - title: "Theme 1", - locale: "en" - }, - "Theme 2" => { - title: "Theme 2", - locale: "en" - }, - "Theme 3" => { - title: "Theme 3", - locale: "en", - description: "Theme 3 description." - }, - "Theme 4" => { - title: "Theme 4", - locale: "en", - description: "Theme 4 description." - } - } - - themes.each do |t, details| - if Theme.where(title: details[:title]).empty? - theme = Theme.new - theme.title = details[:title] - theme.locale = details[:locale] - theme.description = details[:description] - theme.save! - end - end - - question_formats = { - "Text area" => { - title: "Text area" - }, - "Text field" => { - title: "Text field" - }, - "Radio buttons" => { - title: "Radio buttons" - }, - "Check box" => { - title: "Check box" - }, - "Dropdown" => { - title: "Dropdown" - }, - "Multi select box" => { - title: "Multi select box" - }, - } - - question_formats.each do |qf, details| - if QuestionFormat.where(title: details[:title]).empty? - question_format = QuestionFormat.new - question_format.title = details[:title] - question_format.save! - end - end - - guidance_groups = { - "RCC Guidance" => { - name: "My organization guidance (optional generic guidance you provide for users)", - organisation: "RCC", - optional_subset: true - }, - "Global Research Center Guidance" => { - name: "Global Research Center (Funder specific guidance)", - organisation: "EGRC", - optional_subset: false - }, - "Regional Science Federation Guidance" => { - name: "Regional Science Federation (Funder specific guidance)", - organisation: "RegSciFed", - optional_subset: false - }, - "Institutional Guidance" => { - name: "CapColl - School of Math and Science (optional institutional guidance)", - organisation: "CapColl", - optional_subset: true - } - } - - guidance_groups.each do |gg, details| - if GuidanceGroup.where(name: details[:name]).empty? - guidance_group = GuidanceGroup.new - guidance_group.name = details[:name] - guidance_group.organisation = Org.find_by_abbreviation(details[:organisation]) - guidance_group.optional_subset = details[:optional_subset] - guidance_group.save! - end - end - - guidances = { - "Guidance 1" => { - text: "Guidance text", - guidance_group: "My organization guidance (optional generic guidance you provide for users)", - themes: ["Theme 4"] - }, - "Guidance 2" => { - text: "Guidance text", - guidance_group: "Global Research Center (Funder specific guidance)", - themes: ["Theme 2"] - }, - "Guidance 3" => { - text: "Guidance text", - guidance_group: "Global Research Center (Funder specific guidance)", - themes: ["Theme 3"] - }, - "Guidance 4" => { - text: "Guidance text", - guidance_group: "Regional Science Federation (Funder specific guidance)", - themes: ["Theme 1"] - }, - "Guidance 4" => { - text: "Guidance text", - guidance_group: "CapColl - School of Math and Science (optional institutional guidance)", - themes: ["Theme 1"] - } - } - - guidances.each do |g, details| - if Guidance.where(text: details[:text]).empty? - guidance = Guidance.new - guidance.text = details[:text] - guidance.guidance_groups << GuidanceGroup.find_by_name(details[:guidance_group]) - details[:themes].each do |theme| - guidance.themes << Theme.find_by_title(theme) - end - guidance.save! - end - end - - templates = { - "RCC" => { - title: "Regional Curation Center Template", - description: "The default RCC template", - published: true, - organisation: "RCC", - locale: "en", - is_default: true - }, - "Global Research Center" => { - title: "Global Research Center Award", - description: "Funder template description", - published: true, - organisation: "EGRC", - locale: "en", - is_default: false - }, - "Regional Science Federation" => { - title: "Regional Science Federation Grant - Summary", - description: "Funder template description for phase 1", - published: true, - organisation: "RegSciFed", - locale: "en", - is_default: false - }, - "Regional Science Federation2" => { - title: "Regional Science Federation Grant - Finalized", - description: "Funder template description for phase 2", - published: true, - organisation: "RegSciFed", - locale: "en", - is_default: false - } - } - - templates.each do |t, details| - org = Org.where(abbreviation: details[:organisation]).first - - if Dmptemplate.where(organisation: org).where(title: details[:title]).empty? - template = Dmptemplate.new - template.title = details[:title] - template.description = details[:description] - template.published = details[:published] - template.locale = details[:locale] - template.is_default = details[:is_default] - template.organisation = org - template.save! - end - end - - phases = { - "RCC" => { - title: "Regional CurationCenter Data Management Plan", - number: 1, - template: "Regional Curation Center Template" - }, - "EGRC Template" => { - title: "Global Research Center Annual Award", - number: 1, - template: "Global Research Center Award" - }, - "RegSciFed Template" => { - title: "Regional Science Federation - Preliminary", - number: 1, - template: "Regional Science Federation Grant - Summary" - }, - "RegSciFed Template2" => { - title: "Regional Science Federation - Final", - number: 1, - template: "Regional Science Federation Grant - Finalized" - } - } - - phases.each do |p, details| - if Phase.where(title: details[:title]).empty? - phase = Phase.new - phase.title = details[:title] - phase.number = details[:number] - phase.dmptemplate = Dmptemplate.find_by_title(details[:template]) - phase.save! - end - end - - versions = { - "RCC" => { - title: "Default Template v1", - number: 1, - phase: "Regional CurationCenter Data Management Plan" - }, - "EGRC" => { - title: "Annual Award v1", - number: 1, - phase: "Global Research Center Annual Award" - }, - "RegSciFed_1" => { - title: "Grant Summary v1", - number: 1, - phase: "Regional Science Federation - Preliminary" - }, - "RegSciFed_2" => { - title: "Grant Finalized Award v1", - number: 1, - phase: "Regional Science Federation - Final" - }, - "RegSciFed_2.1" => { - title: "Grant Finalized v2", - number: 1, - phase: "Regional Science Federation - Final" - }, - } - - versions.each do |v, details| - if Version.where(title: details[:title]).empty? - version = Version.new - version.title = details[:title] - version.number = details[:number] - version.phase = Phase.find_by_title(details[:phase]) - version.save! - end - end - - sections = { - "Section 1" => { - title: "Data Collection", - number: 1, - description: "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.", - version: "Default Template v1", - organisation: "RCC" - }, - "Section 2" => { - title: "Documentation and Metadata", - number: 2, - description: "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.", - version: "Default Template v1", - organisation: "RCC" - }, - "Section A" => { - title: "Data Overview", - number: 1, - version: "Annual Award v1", - organisation: "EGRC" - }, - "Section B" => { - title: "Ethics and Legal Compliance", - number: 2, - version: "Annual Award v1", - organisation: "EGRC" - }, - "Section C" => { - title: "Storage and Backup", - number: 3, - version: "Annual Award v1", - organisation: "EGRC" - }, - "Section D" => { - title: "Preservation, Sustainability and Use", - number: 4, - version: "Annual Award v1", - organisation: "EGRC" - }, - "regSciFed Summary" => { - title: "Data Collection Guidelines", - number: 1, - description: "This is what we plan on collecting and how we're going to store it.", - version: "Grant Summary v1", - organisation: "RegSciFed" - }, - "RegSciFed Final 1" => { - title: "Data Collection and Storage", - number: 1, - version: "Grant Finalized Award v1", - organisation: "RegSciFed" - }, - "RegSciFed Final 1_2" => { - title: "Data Preservation", - number: 2, - version: "Grant Finalized v2", - organisation: "RegSciFed" - }, - "RegSciFed Final 2_2" => { - title: "Ongoing Access", - number: 3, - version: "Grant Finalized v2", - organisation: "RegSciFed" - } - } - - sections.each do |s, details| - if Section.where(title: details[:title]).empty? - section = Section.new - section.title = details[:title] - section.number = details[:number] - section.description = details[:description] - section.version = Version.find_by_title(details[:version]) - section.organisation = Org.find_by_abbreviation(details[:organisation]) - section.save! - end - end - - questions = { - "What data will you collect or create?" => { - text: "What data will you collect or create?", - section: "Data Collection", - number: 1, - guidance: "

Questions to consider:

Guidance:

Give a brief description of the data, including any existing data or third-party sources that will be used, in each case noting its content, type and coverage. Outline and justify your choice of format and consider the implications of data format and data volumes in terms of storage, backup and access.

", - themes: ["Theme 2"] - }, - "How will the data be collected or created?" => { - text: "How will the data be collected or created?", - section: "Data Collection", - number: 2, - guidance: "

Questions to consider:

Guidance:

Outline how the data will be collected/created and which community data standards (if any) will be used. Consider how the data will be organised during the project, mentioning for example naming conventions, version control and folder structures. Explain how the consistency and quality of data collection will be controlled and documented. This may include processes such as calibration, repeat samples or measurements, standardised data capture or recording, data entry validation, peer review of data or representation with controlled vocabularies.

", - themes: ["Theme 3"] - }, - "What documentation and metadata will accompany the data?" => { - text: "What documentation and metadata will accompany the data?", - section: "Documentation and Metadata", - number: 1, - guidance: "

Questions to consider:

Guidance:

Describe the types of documentation that will accompany the data to help secondary users to understand and reuse it. This should at least include basic details that will help people to find the data, including who created or contributed to the data, its title, date of creation and under what conditions it can be accessed.

Documentation may also include details on the methodology used, analytical and procedural information, definitions of variables, vocabularies, units of measurement, any assumptions made, and the format and file type of the data. Consider how you will capture this information and where it will be recorded. Wherever possible you should identify and use existing community standards.

", - themes: ["Theme 1"] - }, - "Data Overview" => { - text: "Overview of the Data", - section: "Data Overview", - number: 1, - guidance: "

Things to consider: