diff --git a/Gemfile b/Gemfile index 6ccc952..cabb261 100644 --- a/Gemfile +++ b/Gemfile @@ -16,7 +16,7 @@ # ------------------------------------------------ # DATABASE/SERVER gem 'pg' -gem 'mysql2', '~> 0.3.18' +#gem 'mysql2', '~> 0.3.18' # ------------------------------------------------ # JS <-> RUBY BRIDGE diff --git a/Gemfile.lock b/Gemfile.lock index d2532a9..d3f1394 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -211,7 +211,6 @@ ruby-progressbar multi_json (1.12.1) multipart-post (2.0.0) - mysql2 (0.3.21) nokogiri (1.6.8) mini_portile2 (~> 2.1.0) pkg-config (~> 1.1.7) @@ -351,7 +350,6 @@ libv8 minitest-rails-capybara minitest-reporters - mysql2 (~> 0.3.18) omniauth omniauth-shibboleth pg @@ -382,4 +380,4 @@ ruby 2.2.2p95 BUNDLED WITH - 1.13.2 + 1.13.7 diff --git a/app/admin/organisation.rb b/app/admin/organisation.rb index 5acc929..2357eb3 100644 --- a/app/admin/organisation.rb +++ b/app/admin/organisation.rb @@ -5,7 +5,7 @@ # [+Copyright:+] Digital Curation Centre and University of California Curation Center ActiveAdmin.register Organisation do - permit_params :abbreviation, :banner_file_id, :description, :domain, :logo_file_id, :name, :stylesheet_file_id, :target_url, :organisation_type_id, :wayfless_entity, :parent_id + permit_params :abbreviation, :banner_file_id, :description, :logo_file_id, :name, :target_url, :organisation_type_id, :wayfless_entity, :parent_id menu :priority => 14, :label => proc{I18n.t('admin.org')}, :parent => "Organisations management" @@ -59,7 +59,6 @@ end # row :target_url row :logo_file_name - row :domain row :wayfless_entity row I18n.t('admin.token_permission_type') do (organisation.token_permission_types.map{|tpt| link_to tpt.token_type, [:admin, tpt]}).join(', ').html_safe @@ -89,7 +88,6 @@ # f.input :target_url f.input :banner_text f.input :logo_file_name - f.input :domain f.input :wayfless_entity f.input :token_permission_types, label: I18n.t('admin.token_permission_type'), as: :select, multiple: true, include_blank: I18n.t('helpers.none'), diff --git a/app/admin/question.rb b/app/admin/question.rb index 8d46df1..45d8e18 100644 --- a/app/admin/question.rb +++ b/app/admin/question.rb @@ -5,7 +5,7 @@ # [+Copyright:+] Digital Curation Centre and University of California Curation Center ActiveAdmin.register Question do - permit_params :default_value, :dependency_id, :dependency_text, :guidance, :number, :parent_id, :suggested_answer, :text, :question_type, :section_id + permit_params :default_value, :dependency_id, :dependency_text, :guidance, :number, :suggested_answer, :text, :question_type, :section_id menu :priority => 7, :label => proc{I18n.t('admin.question')}, :parent => "Templates management" @@ -54,28 +54,6 @@ row I18n.t('admin.question_format') do |format| link_to format.question_format.title, [:admin, format.question_format] end - #row :guidance do |qguidance| - # if !qguidance.guidance.nil? then - # qguidance.guidance.html_safe - # end - #end - #row :parent_id do |qparent| - # if !qparent.parent_id.nil? then - # parent_q = Question.where('id = ?', qparent.parent_id) - # link_to parent_q.text, [:admin, parent_q] - # end - #end - #row :dependency_id do |qdepend| - # if !qdepend.dependency_id.nil? then - # qdep = Question.where('id = ?', qparent.dependency_id) - # link_to qdep.text, [:admin, qdep] - # end - #end - #row :dependency_text do |dep_text| - # if !dep_text.dependency_text.nil? then - # dep_text.dependency_text.html_safe - # end - #end row I18n.t('admin.themes') do (question.themes.map{|t_q| link_to t_q.title, [:admin, t_q]}).join(', ').html_safe end @@ -95,14 +73,6 @@ :as => :select, :collection => Section.order('title').map{ |sec| ["#{sec.version.phase.dmptemplate.title} - #{sec.title}", sec.id] } f.input :default_value - # f.input :guidance - # f.input :parent_id, :label => "Parent", - # :as => :select, - # :collection => Question.find(:all, :order => 'text ASC').map{|que|[que.text, que.id]} - #f.input :dependency_id, :label => "Dependency question", - # :as => :select, - # :collection => Question.find(:all, :order => 'text ASC').map{|que|[que.text, que.id]} - # f.input :dependency_text end f.inputs "Question Format" do diff --git a/app/admin/role.rb b/app/admin/role.rb index dc386de..378fe2d 100644 --- a/app/admin/role.rb +++ b/app/admin/role.rb @@ -5,7 +5,7 @@ # [+Copyright:+] Digital Curation Centre and University of California Curation Center ActiveAdmin.register Role do - permit_params :name, :role_in_plans + permit_params :name menu :priority => 5, :label => proc{I18n.t('admin.role')}, :parent => "User management" @@ -21,7 +21,6 @@ show do attributes_table do row :name - row :role_in_plans row :created_at row :updated_at end @@ -48,7 +47,6 @@ form do |f| f.inputs "Details" do f.input :name - f.input :role_in_plans end f.actions diff --git a/app/admin/user.rb b/app/admin/user.rb index 464798b..8f89d6b 100644 --- a/app/admin/user.rb +++ b/app/admin/user.rb @@ -52,18 +52,6 @@ end end row :other_organisation - # row I18n.t('admin.user_status'), :user_status_id do |us| - # if !us.user_status.nil? then - # link_to us.user_status.name, [:admin, us.user_status] - # end - # end - # row I18n.t('admin.user_type'), :user_type_id do |ut| - # if !ut.user_type.nil? then - # link_to ut.user_type.name, [:admin, ut.user_type] - # else - # '-' - # end - # end row I18n.t('admin.user_role') do (user.roles.map{|ro| link_to ro.name, [:admin, ro]}).join(', ').html_safe end @@ -88,12 +76,6 @@ :as => :select, :collection => Organisation.order('name').map{|orgp|[orgp.name, orgp.id]} f.input :other_organisation - # f.input :user_status_id, :label => I18n.t('admin.user_status'), - # :as => :select, - # :collection => UserStatus.find(:all, :order => 'name ASC').map{|us|[us.name, us.id]} - # f.input :user_type_id, :label => I18n.t('admin.user_type'), - # :as => :select, - # :collection => UserType.find(:all, :order => 'name ASC').map{|ut|[ut.name, ut.id]} f.input :role_ids, :label => I18n.t('admin.user_role'), :as => :select, :multiple => true, diff --git a/app/admin/user_role_type.rb b/app/admin/user_role_type.rb deleted file mode 100644 index e40f5ee..0000000 --- a/app/admin/user_role_type.rb +++ /dev/null @@ -1,30 +0,0 @@ -# [+Project:+] DMPRoadmap -# [+Description:+] -# -# [+Created:+] 03/09/2014 -# [+Copyright:+] Digital Curation Centre and University of California Curation Center - -ActiveAdmin.register UserRoleType do - permit_params :description, :name - menu false - #:priority => 5, :label => proc{I18n.t('admin.user_role_type')}, :parent => "User management" - - index do - column I18n.t('admin.title'), :sortable => :name do |user_n| - link_to user_n.name, [:admin, user_n] - end - column I18n.t('admin.desc'),:description do |descr| - if !descr.description.nil? then - descr.description.html_safe - end - end - - actions - end - - controller do - def permitted_params - params.permit! - end - end -end diff --git a/app/admin/user_status.rb b/app/admin/user_status.rb deleted file mode 100644 index 856577c..0000000 --- a/app/admin/user_status.rb +++ /dev/null @@ -1,31 +0,0 @@ -# [+Project:+] DMPRoadmap -# [+Description:+] -# -# [+Created:+] 03/09/2014 -# [+Copyright:+] Digital Curation Centre and University of California Curation Center - -ActiveAdmin.register UserStatus do - permit_params :description, :name - - menu false - #:priority => 5, :label => proc{I18n.t('admin.user_status')}, :parent => "User management" - - index do - column I18n.t('admin.title'), :sortable => :name do |user_n| - link_to user_n.name, [:admin, user_n] - end - column I18n.t('admin.desc'),:description do |descr| - if !descr.description.nil? then - descr.description.html_safe - end - end - - actions - end - - controller do - def permitted_params - params.permit! - end - end -end diff --git a/app/admin/user_type.rb b/app/admin/user_type.rb deleted file mode 100644 index 7836401..0000000 --- a/app/admin/user_type.rb +++ /dev/null @@ -1,42 +0,0 @@ -# [+Project:+] DMPRoadmap -# [+Description:+] -# -# [+Created:+] 03/09/2014 -# [+Copyright:+] Digital Curation Centre and University of California Curation Center - -ActiveAdmin.register UserType do - permit_params :description, :name - - menu false - #:priority => 5, :label => proc{I18n.t('admin.user_type')}, :parent => "User management" - - index do - column I18n.t('admin.user_type'), :sortable => :name do |user_n| - link_to user_n.name, [:admin, user_n] - end - - actions - end - - # show Template details - show do - attributes_table do - row :name - row :description do |descr| - if !descr.description.nil? then - descr.description.html_safe - end - end - row :created_at - row :updated_at - end - end - - controller do - def permitted_params - params.permit! - end - end - - -end diff --git a/app/controllers/plans_controller.rb b/app/controllers/plans_controller.rb index f5125d6..8e8c70d 100644 --- a/app/controllers/plans_controller.rb +++ b/app/controllers/plans_controller.rb @@ -154,18 +154,6 @@ end end - def warning - @plan = Plan.find(params[:id]) - authorize @plan - if user_signed_in? && @plan.readable_by(current_user.id) then - respond_to do |format| - format.json { render json: @plan.warning(params[:option_id]) } - end - else - render(:file => File.join(Rails.root, 'public/403.html'), :status => 403, :layout => false) - end - end - def export @plan = Plan.find(params[:id]) authorize @plan diff --git a/app/models/dmptemplate.rb b/app/models/dmptemplate.rb index 981b585..17dbd12 100644 --- a/app/models/dmptemplate.rb +++ b/app/models/dmptemplate.rb @@ -1,7 +1,7 @@ class Dmptemplate < ActiveRecord::Base include GlobalHelpers - attr_accessible :id, :organisation_id, :description, :published, :title, :user_id, :locale, + attr_accessible :id, :organisation_id, :description, :published, :title, :locale, :is_default, :guidance_group_ids, :as => [:default, :admin] #associations between tables diff --git a/app/models/new_answer.rb b/app/models/new_answer.rb new file mode 100644 index 0000000..e8dd797 --- /dev/null +++ b/app/models/new_answer.rb @@ -0,0 +1,7 @@ +class NewAnswer < ActiveRecord::Base + belongs_to :new_plan + belongs_to :new_question + has_and_belongs_to_many :question_options, join_table: "new_answers_question_options" + has_many :notes + belongs_to :user +end diff --git a/app/models/new_phase.rb b/app/models/new_phase.rb new file mode 100644 index 0000000..1919787 --- /dev/null +++ b/app/models/new_phase.rb @@ -0,0 +1,4 @@ +class NewPhase < ActiveRecord::Base + belongs_to :template + has_many :new_sections +end diff --git a/app/models/new_plan.rb b/app/models/new_plan.rb new file mode 100644 index 0000000..1dac7cd --- /dev/null +++ b/app/models/new_plan.rb @@ -0,0 +1,5 @@ +class NewPlan < ActiveRecord::Base + belongs_to :template + has_many :roles + has_many :users, through: :roles +end diff --git a/app/models/new_question.rb b/app/models/new_question.rb new file mode 100644 index 0000000..3935fba --- /dev/null +++ b/app/models/new_question.rb @@ -0,0 +1,8 @@ +class NewQuestion < ActiveRecord::Base + belongs_to :new_section + has_one :new_answer + has_one :note + has_many :question_options + belongs_to :question_format + has_and_belongs_to_many :themes, join_table: :new_questions_themes +end diff --git a/app/models/new_section.rb b/app/models/new_section.rb new file mode 100644 index 0000000..4c5c155 --- /dev/null +++ b/app/models/new_section.rb @@ -0,0 +1,4 @@ +class NewSection < ActiveRecord::Base + belongs_to :new_phase + has_many :new_questions +end diff --git a/app/models/new_suggested_answer.rb b/app/models/new_suggested_answer.rb new file mode 100644 index 0000000..6578f1d --- /dev/null +++ b/app/models/new_suggested_answer.rb @@ -0,0 +1,4 @@ +class NewSuggestedAnswer < ActiveRecord::Base + belongs_to :new_question + belongs_to :organisation +end diff --git a/app/models/note.rb b/app/models/note.rb new file mode 100644 index 0000000..681fee3 --- /dev/null +++ b/app/models/note.rb @@ -0,0 +1,4 @@ +class Note < ActiveRecord::Base + belongs_to :new_answer + belongs_to :user +end diff --git a/app/models/organisation.rb b/app/models/organisation.rb index 5aabbf0..14c5672 100644 --- a/app/models/organisation.rb +++ b/app/models/organisation.rb @@ -9,7 +9,6 @@ has_many :dmptemplates has_many :sections has_many :users - has_many :option_warnings has_many :suggested_answers has_and_belongs_to_many :token_permission_types, join_table: "org_token_permissions" @@ -22,8 +21,8 @@ accepts_nested_attributes_for :dmptemplates accepts_nested_attributes_for :token_permission_types - attr_accessible :abbreviation, :banner_text, :logo, :remove_logo, :domain, - :logo_file_name, :name, :stylesheet_file_id, :target_url, + 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 @@ -150,20 +149,6 @@ end ## - # takes in the id of, and returns an OptionWarning - # - # @param option_id [number] the id of the desired warning - # @return [OptionWarning] the specified warning - def warning(option_id) - warning = option_warnings.find_by_option_id(option_id) - if warning.nil? && !parent.nil? then - return parent.warning(option_id) - else - return warning - end - end - - ## # returns all published templates belonging to the organisation # # @return [Array] published dmptemplates diff --git a/app/models/perm.rb b/app/models/perm.rb new file mode 100644 index 0000000..f935495 --- /dev/null +++ b/app/models/perm.rb @@ -0,0 +1,6 @@ +class Perm < ActiveRecord::Base + has_and_belongs_to_many :users, :join_table => :users_perms + + attr_accessible :name, :as => [:default, :admin] + +end diff --git a/app/models/plan.rb b/app/models/plan.rb index f25998c..f964fa4 100644 --- a/app/models/plan.rb +++ b/app/models/plan.rb @@ -173,19 +173,6 @@ end ## - # finds the specified warning for the plan's project's organisation - # - # @param option_id [Integer] the id to find the OptionWarning associated - # @return [OptionWarning] the desired OptionWarning - def warning(option_id) - if project.organisation.nil? - return nil - else - return project.organisation.warning(option_id) - end - end - - ## # determines if the plan is editable by the specified user # NOTE: This should be renamed to editable_by? # diff --git a/app/models/question.rb b/app/models/question.rb index aed95fb..cf3fb61 100644 --- a/app/models/question.rb +++ b/app/models/question.rb @@ -20,7 +20,7 @@ accepts_nested_attributes_for :suggested_answers, :allow_destroy => true accepts_nested_attributes_for :themes - attr_accessible :default_value, :dependency_id, :dependency_text, :guidance,:number, :parent_id, :suggested_answer, :text, :section_id,:question_format_id,:options_attributes, :suggested_answers_attributes, :option_comment_display, :theme_ids, :as => [:default, :admin] + attr_accessible :default_value, :dependency_id, :dependency_text, :guidance,:number, :suggested_answer, :text, :section_id,:question_format_id,:options_attributes, :suggested_answers_attributes, :option_comment_display, :theme_ids, :as => [:default, :admin] ## # returns the text from the question diff --git a/app/models/question_option.rb b/app/models/question_option.rb new file mode 100644 index 0000000..b672800 --- /dev/null +++ b/app/models/question_option.rb @@ -0,0 +1,4 @@ +class QuestionOption < ActiveRecord::Base + belongs_to :question + has_and_belongs_to_many :new_answers, join_table: :new_answers_question_options +end diff --git a/app/models/role.rb b/app/models/role.rb index dbe0a80..ea6573c 100644 --- a/app/models/role.rb +++ b/app/models/role.rb @@ -1,8 +1,4 @@ class Role < ActiveRecord::Base - has_and_belongs_to_many :users, :join_table => :users_roles - - belongs_to :resource, :polymorphic => true - - attr_accessible :name, :role_in_plans, :resource_id, :resource_type, :as => [:default, :admin] - + belongs_to :user + belongs_to :new_plan end diff --git a/app/models/template.rb b/app/models/template.rb new file mode 100644 index 0000000..cb586f6 --- /dev/null +++ b/app/models/template.rb @@ -0,0 +1,5 @@ +class Template < ActiveRecord::Base + belongs_to :organisation + has_many :new_phases + has_many :new_plans +end diff --git a/app/models/theme.rb b/app/models/theme.rb index 0b31f36..3df17bd 100644 --- a/app/models/theme.rb +++ b/app/models/theme.rb @@ -3,6 +3,7 @@ #associations between tables has_and_belongs_to_many :questions, join_table: "questions_themes" has_and_belongs_to_many :guidances, join_table: "themes_in_guidance" + has_and_belongs_to_many :new_questions, join_table: "new_questions_themes" # accepts_nested_attributes_for :guidances diff --git a/app/models/user.rb b/app/models/user.rb index f6fbde2..1a0b897 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -8,12 +8,11 @@ :trackable, :validatable, :confirmable, :omniauthable, :omniauth_providers => [:shibboleth] #associations between tables - belongs_to :user_type - belongs_to :user_status has_many :answers - has_many :user_org_roles has_many :project_groups, :dependent => :destroy has_many :user_role_types, through: :user_org_roles + has_many :roles + has_many :new_plans, through: :roles belongs_to :language belongs_to :organisation @@ -38,7 +37,7 @@ end end - has_and_belongs_to_many :roles, :join_table => :users_roles + has_and_belongs_to_many :perms, :join_table => :users_perms has_many :plan_sections @@ -49,7 +48,7 @@ :other_organisation, :accept_terms, :role_ids, :dmponline3, :api_token, :organisation, :language, :language_id - validates :email, email: true, allow_nil: true, uniqueness: true + #validates :email, email: true, allow_nil: true, uniqueness: true # FIXME: The duplication in the block is to set defaults. It might be better if # they could be set in Settings::PlanList itself, if possible. diff --git a/app/models/user_role_type.rb b/app/models/user_role_type.rb deleted file mode 100644 index e012aca..0000000 --- a/app/models/user_role_type.rb +++ /dev/null @@ -1,7 +0,0 @@ -class UserRoleType < ActiveRecord::Base - - #associations between tables - has_many :user_org_roles - - attr_accessible :description, :name, :as => [:default, :admin] -end diff --git a/app/models/user_status.rb b/app/models/user_status.rb deleted file mode 100644 index a8c4dcd..0000000 --- a/app/models/user_status.rb +++ /dev/null @@ -1,6 +0,0 @@ -class UserStatus < ActiveRecord::Base - attr_accessible :description, :name, :as => [:default, :admin] - - #associations between tables - has_many :users -end diff --git a/app/models/user_type.rb b/app/models/user_type.rb deleted file mode 100644 index 8ceb4d4..0000000 --- a/app/models/user_type.rb +++ /dev/null @@ -1,6 +0,0 @@ -class UserType < ActiveRecord::Base - attr_accessible :description, :name, :as => [:default, :admin] - - #associations between tables - has_many :users -end diff --git a/app/policies/plan_policy.rb b/app/policies/plan_policy.rb index 2d4d08a..585e2ac 100644 --- a/app/policies/plan_policy.rb +++ b/app/policies/plan_policy.rb @@ -52,7 +52,4 @@ @plan.readable_by(@user.id) end - def warning? - @plan.readable_by(@user.id) - end end \ No newline at end of file diff --git a/app/views/plans/_answer_form.html.erb b/app/views/plans/_answer_form.html.erb index 53fcbae..bb5c044 100644 --- a/app/views/plans/_answer_form.html.erb +++ b/app/views/plans/_answer_form.html.erb @@ -96,15 +96,6 @@ <%= f.input :options, :as => :select, :collection => options, :label => false, :input_html => { :multiple => false, :id => "options-#{question.id}" } %> <% end %> <% end %> - - - <% if question.option_comment_display == true then%> <%= label_tag("answer-text-#{question.id}".to_sym, t("helpers.comment")) %> diff --git a/config/branding.yml b/config/branding.yml index 578347c..e69de29 100644 --- a/config/branding.yml +++ b/config/branding.yml @@ -1,29 +0,0 @@ -defaults: &defaults - legal_entity: 'the University of Edinburgh, University of Glasgow and the University of California' - - organisation: - name: 'Digital Curation Center and University of California Curation Center' - abbreviation: 'DCC and UC3' - url: 'https://github.com/DMPRoadmap/roadmap/wiki' - copywrite_name: 'DCC and UC3' - email: 'dmponline@dcc.ac.uk' - - application: - name: 'DMPRoadmap' - url: 'https://github.com/DMPRoadmap/roadmap' - version: '0.1.0' - release_notes_url: 'https://github.com/DMPRoadmap/roadmap/wiki/Releases' - issue_list_url: 'https://github.com/DMPRoadmap/roadmap/issues' - user_group_subscription_url: 'http://listserv.ucop.edu/cgi-bin/wa.exe?SUBED1=ROADMAP-L&A=1' - -development: - <<: *defaults - -test: - <<: *defaults - -staging: - <<: *defaults - -production: - <<: *defaults \ No newline at end of file diff --git a/config/environments/development.rb b/config/environments/development.rb index 0978811..6e02253 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -48,4 +48,9 @@ config.action_mailer.perform_deliveries = false BetterErrors::Midleware.allow_ip! "10.0.2.2" if defined?(BetterErrors) && Rails.env == :development + + config.after_initialize do + ActiveRecord::Base.logger = Rails.logger.clone + ActiveRecord::Base.logger.level = Logger::INFO + end end diff --git a/db/migrate/20161115105808_drop_unused_user_tables.rb b/db/migrate/20161115105808_drop_unused_user_tables.rb new file mode 100644 index 0000000..9558098 --- /dev/null +++ b/db/migrate/20161115105808_drop_unused_user_tables.rb @@ -0,0 +1,9 @@ +class DropUnusedUserTables < ActiveRecord::Migration + def change + drop_table :user_statuses + remove_column :users, :user_status_id + drop_table :user_role_types + drop_table :user_types + remove_column :users, :user_type_id + end +end diff --git a/db/migrate/20161115114309_drop_option_warning_table.rb b/db/migrate/20161115114309_drop_option_warning_table.rb new file mode 100644 index 0000000..4ce7c19 --- /dev/null +++ b/db/migrate/20161115114309_drop_option_warning_table.rb @@ -0,0 +1,5 @@ +class DropOptionWarningTable < ActiveRecord::Migration + def change + drop_table :option_warnings + end +end diff --git a/db/migrate/20161115121831_remove_parent_id_from_questions.rb b/db/migrate/20161115121831_remove_parent_id_from_questions.rb new file mode 100644 index 0000000..47545b6 --- /dev/null +++ b/db/migrate/20161115121831_remove_parent_id_from_questions.rb @@ -0,0 +1,5 @@ +class RemoveParentIdFromQuestions < ActiveRecord::Migration + def change + remove_column :questions, :parent_id, :integer + end +end diff --git a/db/migrate/20161115123658_remove_unused_fields_from_roles.rb b/db/migrate/20161115123658_remove_unused_fields_from_roles.rb new file mode 100644 index 0000000..0f768cc --- /dev/null +++ b/db/migrate/20161115123658_remove_unused_fields_from_roles.rb @@ -0,0 +1,7 @@ +class RemoveUnusedFieldsFromRoles < ActiveRecord::Migration + def change + remove_column :roles, :role_in_plans, :boolean + remove_column :roles, :resource_id, :integer + remove_column :roles, :resource_type, :string + end +end diff --git a/db/migrate/20161115124634_remove_unused_fields_from_organisations.rb b/db/migrate/20161115124634_remove_unused_fields_from_organisations.rb new file mode 100644 index 0000000..f97fe8d --- /dev/null +++ b/db/migrate/20161115124634_remove_unused_fields_from_organisations.rb @@ -0,0 +1,6 @@ +class RemoveUnusedFieldsFromOrganisations < ActiveRecord::Migration + def change + remove_column :organisations, :stylesheet_file_id, :integer + remove_column :organisations, :domain, :string + end +end diff --git a/db/migrate/20161115132137_remove_unused_fields_from_dmptemplates.rb b/db/migrate/20161115132137_remove_unused_fields_from_dmptemplates.rb new file mode 100644 index 0000000..77594d4 --- /dev/null +++ b/db/migrate/20161115132137_remove_unused_fields_from_dmptemplates.rb @@ -0,0 +1,5 @@ +class RemoveUnusedFieldsFromDmptemplates < ActiveRecord::Migration + def change + remove_column :dmptemplates, :user_id, :integer + end +end diff --git a/db/migrate/20161115143222_rename_roles_to_perms.rb b/db/migrate/20161115143222_rename_roles_to_perms.rb new file mode 100644 index 0000000..45d1730 --- /dev/null +++ b/db/migrate/20161115143222_rename_roles_to_perms.rb @@ -0,0 +1,15 @@ +class RenameRolesToPerms < ActiveRecord::Migration + def self.up + rename_table :roles, :perms + rename_table :users_roles, :users_perms + rename_column :users_perms, :role_id, :perm_id + #remove_index :users_perms, + end + + def self.down + #rename_index :users_perms, :index_users_perms_on_user_id_and_perms_id, :index_users_roles_on_user_id_and_role_id + rename_column :users_perms, :perm_id, :role_id + rename_table :users_perms, :users_roles + rename_table :perms, :roles + end +end diff --git a/db/migrate/20161122152339_new_plan_template_structure.rb b/db/migrate/20161122152339_new_plan_template_structure.rb new file mode 100644 index 0000000..661ac12 --- /dev/null +++ b/db/migrate/20161122152339_new_plan_template_structure.rb @@ -0,0 +1,439 @@ +class NewPlanTemplateStructure < ActiveRecord::Migration + def up + # new template tables + create_table :templates do |t| + t.string :title + t.text :description + t.boolean :published + t.integer :organisation_id + t.string :locale + t.boolean :is_default + t.timestamps + # new fields + t.integer :version + t.integer :visibility + t.integer :customization_of + t.integer :dmptemplate_id # remove on next migration + end + + create_table :new_phases do |t| + t.string :title + t.text :description + t.integer :number + t.integer :template_id + t.timestamps + t.string :slug + t.integer :vid # remove on next migration + # new fields + t.boolean :modifiable + end + + create_table :new_sections do |t| + t.string :title + t.text :description + t.integer :number + t.timestamps + t.boolean :published + # new fields + t.integer :new_phase_id + t.boolean :modifiable + end + + create_table :new_questions do |t| + t.text :text + t.text :default_value + t.text :guidance + t.integer :number + t.integer :new_section_id + t.timestamps + t.integer :question_format_id + t.boolean :option_comment_display, default: true + # new fields + t.boolean :modifiable + t.integer :question_id # remove on next migration + end + + create_join_table :new_questions, :themes do |t| + end + + create_table :new_answers do |t| + t.text :text + t.integer :new_plan_id + t.integer :user_id + t.integer :new_question_id + t.timestamps + end + + create_table :question_options do |t| + t.integer :new_question_id + t.integer :option_id # remove on next migration + t.string :text + t.integer :number + t.boolean :is_default + t.timestamps + end + + create_join_table :new_answers, :question_options do |t| + end + + create_table :notes do |t| + t.integer :user_id + t.text :text + t.boolean :archived # do we need this? + t.integer :new_answer_id + t.integer :archived_by # do we need this? + t.timestamps + end + + create_table :new_suggested_answers do |t| + t.integer :new_question_id + t.integer :organisation_id + t.text :text + t.boolean :is_example + t.timestamps + end + + # new plans table + create_table :new_plans do |t| + t.integer :project_id + t.string :title + t.integer :template_id + t.timestamps + 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 + end + + create_table :roles do |t| + t.boolean :creator + t.boolean :editor + t.boolean :administrator + t.integer :user_id + t.integer :new_plan_id + t.timestamps + end + + # migrate all of the data from plans into templates (user facing) + # first migrate all "pure"(uncustomised) plans + # find template for plan + # find versions for plan + # find phases for template + # find sections for version + # find questions for section + # find question_options for question + # find answers for question + # find notes from question & link to answer + # find guidance_by_question for question + # find themes for question + # IF EXISTS Template SUCH THAT: + # dmptemplate.name = template.name, + # phase.title = new_phase.title, + # new_phase.version_id in versions.id + # SUCCESSFUL MATCH, copy over all data + # Then migrate all customised plans + # migrate most current template into templates (org facing) + proj_number = 0 + # migrating uncustomised plans + Template.transaction do + Project.includes( { dmptemplate: [ { phases: [ { versions: [:sections] } ] } ] }, {plans: [:version ]}, :organisation).find_each(batch_size: 20) do |project| + puts "" + puts "beginning number #{proj_number}" + proj_number +=1 + if project.dmptemplate.nil? # one of the templates dosent exist + next + end + new_plan = initNewPlan(project) # copy data from project to NewPlan object + plans = project.plans # select plans for project + version_ids = [] + versions = [] + plans.each do |plan| # select version ids from plans list + version_ids << plan.version.id + versions << plan.version + end + dmptemplate = project.dmptemplate # select template for project + phases = dmptemplate.phases # select phases for project + temp_match = false # flag for if we found a matching template + + puts "checking for matching templates for #{dmptemplate.title} customised by #{project.organisation.name}" unless project.organisation.nil? + puts "checking for matching templates for #{dmptemplate.title} uncustomised" unless project.organisation.present? + possible_templates = project.organisation.nil? ? + Template.includes(:new_phases).where(dmptemplate_id: dmptemplate.id, organisation_id: dmptemplate.organisation_id) : + Template.includes(:new_phases).where(dmptemplate_id: dmptemplate.id, organisation_id: project.organisation_id) + possible_templates.find_each do |t| # for templates with same id + # early cut for un-even number of phases + new_phase_versions = t.new_phases.pluck(:vid) + if new_phase_versions.sort == version_ids.sort + temp_match = true # flag that we found match + # we can point the new_plan to this template and init all data + new_plan.template_id = t.id + new_plan.save! + puts "found a match: #{t.title} version #{t.version}" + break + end + end + + + # this section handles for customisations + unless temp_match # no matches found, init template & phase & sections & questions & themes & options + puts "creating new template for #{dmptemplate.title}" unless project.organisation.present? + puts "creating new template for #{dmptemplate.title} customised by #{project.organisation.name}" unless project.organisation.nil? + modifiable = project.organisation.nil? || project.organisation_id == dmptemplate.organisation_id + template = initTemplate(dmptemplate, modifiable, project.organisation_id) # needs to select next version of temp based on old_temp_id + # some differences between a customised and un-customised template + # customised templates need a different organisation_id + template.organisation_id = project.organisation_id unless project.organisation_id.nil? # updated to not overwrite with nil + # customised templates follow different version rules + template.save! + # since template was not a match, need to gen/copy all data below the template level + versions.each do |version| + new_phase = initNewPhase(version.phase, version, template, modifiable) + new_phase.save! + sections = [] + sections += version.sections.where("organisation_id = ? ", dmptemplate.organisation_id).pluck(:id) + unless project.organisation_id.nil? + sections += Section.where(organisation_id: project.organisation_id, version_id: version.id).pluck(:id) + end + Section.includes(questions: [:themes, :options, :suggested_answers]).where(id: sections).each do |section| + new_section = initNewSection(section, new_phase, modifiable) + new_section.save! + section.questions.each do |question| + new_question = initNewQuestion(question, new_section, modifiable) + new_question.save! + question.themes.each do |theme| + new_question.themes << theme + end + question.options.each do |option| + question_option = initQuestionOption(option, new_question) + question_option.save! + end + question.suggested_answers.each do |suggested_answer| + new_suggested_answer = initNewSuggestedAnswers(suggested_answer, new_question) + new_suggested_answer.save! + end + end + end + end + new_plan.template_id = template.id + new_plan.save! + end + + # up to this point, we have either found a matching template and pointed the + # new_plan obj at it, or we have generated a new: + # template/phases/sections/questions/question_options/question_themes + # now need to init answers, notes, answers_options + #new_plan.template.new_phases.each do |new_phase| + puts "transfering plan data" + project.project_groups.each do |group| + role = initRole(group, new_plan) + role.save! + end + template = Template.includes(new_phases: {new_sections: :new_questions}).find(new_plan.template_id) + template.new_phases.each do |new_phase| + old_plan = project.plans.where(version_id: new_phase.vid).first + new_phase.new_sections.each do |new_section| + new_section.new_questions.each do |new_question| + # init new answer + old_ans = Answer.where(question_id: new_question.question_id, plan_id: old_plan.id).order("created_at DESC").first + # init comments on answer + new_ans = nil + comments = Comment.where(question_id: new_question.question_id, plan_id: old_plan.id) + # unless there is no old answer, and no comments, create an answer + unless old_ans.nil? && comments.length < 1 + new_ans = initNewAnswer(old_ans, new_plan, new_question) + new_ans.save! + end + comments.find_each do |comment| + note = initNote(comment, new_ans) + note.save! + end + end + end + end + end + end + + # indexes on join tables at the end + change_table :new_answers_question_options do |t| + t.index [:new_answer_id, :question_option_id], name: 'answer_question_option_index' + t.index [:question_option_id, :new_answer_id], name: 'question_option_answer_index' + end + + change_table :new_questions_themes do |t| + t.index [:new_question_id, :theme_id], name: 'question_theme_index' + t.index [:theme_id, :new_question_id], name: 'theme_question_index' + end + + end + + def down + drop_table :templates + drop_table :new_phases + drop_table :new_sections + drop_table :new_questions + drop_join_table :new_questions, :themes + drop_table :new_answers + drop_table :question_options + drop_join_table :new_answers, :question_options + drop_table :notes + drop_table :new_suggested_answers + drop_table :new_plans + drop_table :roles + end +end + + + +def initTemplate(dmptemp, modifiable, organisation_id) + template = Template.new + template.title = dmptemp.title + template.description = dmptemp.description + template.published = dmptemp.published + template.organisation_id = organisation_id.present? ? organisation_id : dmptemp.organisation_id + template.locale = dmptemp.locale + template.is_default = dmptemp.is_default + template.created_at = dmptemp.created_at + template.updated_at = dmptemp.updated_at + template.visibility = 0 # dummy value for private + template.customization_of = modifiable ? nil : dmptemp.id + template.dmptemplate_id = dmptemp.id + # if no templates with the same dmptemplate_id and organisation_id exist + # 0 + # otherwise + # take the maximum version from templates with the same dmptemplate_id and organisation_id and add 1 + template.version = Template.where(dmptemplate_id: dmptemp.id, organisation_id: template.organisation_id).blank? ? + 0 : Template.where(dmptemplate_id: dmptemp.id, organisation_id: template.organisation_id).pluck(:version).max + 1 + puts "NEW TEMPLATE: \n title: #{template.title} \n version: #{template.version} \n others_present? #{Template.where(dmptemplate_id: dmptemp.id).count}" + return template +end + +def initNewPhase(phase, version, temp, modifiable) + new_phase = NewPhase.new + new_phase.title = phase.title + new_phase.description = phase.description + new_phase.number = phase.number + new_phase.template_id = temp.id + new_phase.created_at = phase.created_at + new_phase.updated_at = phase.updated_at + new_phase.slug = phase.slug + new_phase.vid = version.id + new_phase.modifiable = modifiable + return new_phase +end + +def initNewSection(section, new_phase, modifiable) + new_section = NewSection.new + new_section.title = section.title + new_section.description = section.description + new_section.number = section.number + new_section.published = section.published + new_section.new_phase_id = new_phase.id + new_section.modifiable = modifiable + new_section.created_at = section.created_at + new_section.updated_at = section.updated_at + return new_section +end + +def initNewQuestion(question, new_section, modifiable) + new_question = NewQuestion.new + new_question.text = question.text + new_question.default_value = question.default_value + new_question.guidance = question.guidance.nil? ? "" : question.guidance + Guidance.where(question_id: question.id).each do |guidance| + new_question.guidance += guidance.text + end + new_question.number = question.number + new_question.new_section_id = new_section.id + new_question.question_format_id = question.question_format_id + new_question.option_comment_display = question.option_comment_display + new_question.modifiable = modifiable + new_question.question_id = question.id + new_question.updated_at = question.updated_at + new_question.created_at = question.created_at + return new_question +end + +def initNewAnswer(answer, new_plan, new_question) + new_answer = NewAnswer.new + unless answer.nil? + new_answer.text = answer.text + new_answer.new_plan_id = new_plan.id + new_answer.new_question_id = new_question.id + new_answer.user_id = answer.user_id + new_answer.created_at = answer.created_at + new_answer.updated_at = answer.updated_at + # not sure if these get saved properly as new_answer has no id yet + answer.options.each do |option| + new_answer.question_options << QuestionOption.find_by(option_id: option.id) + end + end + return new_answer +end + +def initQuestionOption(option, new_question) + question_option = QuestionOption.new + question_option.new_question_id = new_question.id + question_option.option_id = option.id + question_option.text = option.text + question_option.number = option.number + question_option.is_default = option.is_default + question_option.created_at = option.created_at + question_option.updated_at = option.updated_at + return question_option +end + +def initNote(comment, new_answer) + note = Note.new + note.user_id = comment.user_id + note.text = comment.text + note.archived = comment.archived + note.archived_by = comment.archived_by + note.new_answer_id = new_answer.id + note.created_at = comment.created_at + note.updated_at = comment.updated_at + return note +end + +def initNewPlan(project) + new_plan = NewPlan.new + new_plan.project_id = project.id + new_plan.title = project.title + new_plan.slug = project.slug + new_plan.grant_number = project.grant_number + new_plan.identifier = project.identifier + new_plan.description = project.description + new_plan.principal_investigator = project.principal_investigator + new_plan.principal_investigator_identifier = project.principal_investigator_identifier + new_plan.data_contact = project.data_contact + new_plan.funder_name = project.funder_name + new_plan.created_at = project.created_at + new_plan.updated_at = project.updated_at + return new_plan +end + +def initNewSuggestedAnswers(suggested_answer, new_question) + new_suggested_answer = NewSuggestedAnswer.new + new_suggested_answer.text = suggested_answer.text + new_suggested_answer.organisation_id = suggested_answer.organisation_id + new_suggested_answer.new_question_id = new_question.id + new_suggested_answer.is_example = suggested_answer.is_example + new_suggested_answer.created_at = suggested_answer.created_at + new_suggested_answer.updated_at = suggested_answer.updated_at + return new_suggested_answer +end + +def initRole(project_group, new_plan) + role = Role.new + role.creator = project_group.project_creator + role.administrator = project_group.project_administrator + role.editor = project_group.project_editor + role.created_at = project_group.created_at + role.updated_at = project_group.updated_at + role.user_id = project_group.user_id + role.new_plan_id = new_plan.id + return role +end diff --git a/db/schema.rb b/db/schema.rb index a1cf34f..4951228 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,15 +11,18 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20150809210811) do +ActiveRecord::Schema.define(version: 20161122152339) do + + # These are extensions that must be enabled in order to support this database + enable_extension "plpgsql" create_table "answers", :force => true do |t| t.text "text" t.integer "plan_id" t.integer "user_id" t.integer "question_id" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false end create_table "answers_options", :id => false, :force => true do |t| @@ -27,14 +30,14 @@ 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" + add_index "answers_options", ["answer_id", "option_id"], name: "index_answers_options_on_answer_id_and_option_id", using: :btree create_table "comments", :force => true do |t| t.integer "user_id" t.integer "question_id" t.text "text" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false t.boolean "archived" t.integer "plan_id" t.integer "archived_by" @@ -44,10 +47,9 @@ t.string "title" t.text "description" t.boolean "published" - t.integer "user_id" t.integer "organisation_id" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false t.string "locale" t.boolean "is_default" end @@ -61,8 +63,8 @@ t.integer "plan_id" t.integer "user_id" t.string "format" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false end create_table "file_types", :force => true do |t| @@ -70,8 +72,8 @@ t.string "icon_name" t.integer "icon_size" t.string "icon_location" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false end create_table "file_uploads", :force => true do |t| @@ -82,8 +84,8 @@ t.boolean "published" t.string "location" t.integer "file_type_id" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false end create_table "friendly_id_slugs", :force => true do |t| @@ -93,15 +95,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 => true do |t| t.string "name" t.integer "organisation_id" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false t.boolean "optional_subset" t.boolean "published" end @@ -111,22 +113,118 @@ 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" + 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 => true do |t| t.text "text" t.integer "guidance_group_id" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false t.integer "question_id" end - create_table "option_warnings", :force => true do |t| - t.integer "organisation_id" - t.integer "option_id" + create_table "languages", force: :cascade do |t| + t.string "abbreviation" + t.string "description" + t.string "name" + t.boolean "default_language" + end + + create_table "new_answers", force: :cascade do |t| t.text "text" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.integer "new_plan_id" + t.integer "user_id" + t.integer "new_question_id" + t.datetime "created_at" + t.datetime "updated_at" + end + + create_table "new_answers_question_options", id: false, force: :cascade do |t| + t.integer "new_answer_id", null: false + t.integer "question_option_id", null: false + end + + add_index "new_answers_question_options", ["new_answer_id", "question_option_id"], name: "answer_question_option_index", using: :btree + add_index "new_answers_question_options", ["question_option_id", "new_answer_id"], name: "question_option_answer_index", using: :btree + + create_table "new_phases", force: :cascade do |t| + t.string "title" + t.text "description" + t.integer "number" + t.integer "template_id" + t.datetime "created_at" + t.datetime "updated_at" + t.string "slug" + t.integer "vid" + t.boolean "modifiable" + end + + create_table "new_plans", force: :cascade do |t| + t.integer "project_id" + t.string "title" + t.integer "template_id" + 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" + end + + create_table "new_questions", force: :cascade do |t| + t.text "text" + t.text "default_value" + t.text "guidance" + t.integer "number" + t.integer "new_section_id" + t.datetime "created_at" + t.datetime "updated_at" + t.integer "question_format_id" + t.boolean "option_comment_display", default: true + t.boolean "modifiable" + t.integer "question_id" + end + + create_table "new_questions_themes", id: false, force: :cascade do |t| + t.integer "new_question_id", null: false + t.integer "theme_id", null: false + end + + add_index "new_questions_themes", ["new_question_id", "theme_id"], name: "question_theme_index", using: :btree + add_index "new_questions_themes", ["theme_id", "new_question_id"], name: "theme_question_index", using: :btree + + create_table "new_sections", force: :cascade do |t| + t.string "title" + t.text "description" + t.integer "number" + t.datetime "created_at" + t.datetime "updated_at" + t.boolean "published" + t.integer "new_phase_id" + t.boolean "modifiable" + end + + create_table "new_suggested_answers", force: :cascade do |t| + t.integer "new_question_id" + t.integer "organisation_id" + t.text "text" + t.boolean "is_example" + t.datetime "created_at" + t.datetime "updated_at" + end + + create_table "notes", force: :cascade do |t| + t.integer "user_id" + t.text "text" + t.boolean "archived" + t.integer "new_answer_id" + t.integer "archived_by" + t.datetime "created_at" + t.datetime "updated_at" end create_table "options", :force => true do |t| @@ -134,15 +232,22 @@ t.string "text" t.integer "number" t.boolean "is_default" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + + create_table "org_token_permissions", force: :cascade do |t| + t.integer "organisation_id" + t.integer "token_permission_type_id" + t.datetime "created_at" + t.datetime "updated_at" end create_table "organisation_types", :force => true do |t| t.string "name" t.text "description" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false end create_table "organisations", :force => true do |t| @@ -151,37 +256,49 @@ t.text "description" t.string "target_url" t.integer "organisation_type_id" - t.string "domain" - t.integer "wayfless_entity" - t.integer "stylesheet_file_id" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.string "wayfless_entity" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false t.integer "parent_id" 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" end - create_table "phases", :force => true do |t| + create_table "perms", force: :cascade do |t| + t.string "name" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + + 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 "dmptemplate_id" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false t.string "slug" 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 => true do |t| t.integer "user_id" t.integer "section_id" t.integer "plan_id" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false t.datetime "release_time" end @@ -189,8 +306,8 @@ t.boolean "locked" t.integer "project_id" t.integer "version_id" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false end create_table "project_groups", :force => true do |t| @@ -198,8 +315,8 @@ t.boolean "project_editor" t.integer "user_id" t.integer "project_id" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false t.boolean "project_administrator" end @@ -208,13 +325,13 @@ 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" + 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 => true do |t| t.string "title" t.integer "dmptemplate_id" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false t.string "slug" t.integer "organisation_id" t.string "grant_number" @@ -226,13 +343,23 @@ t.string "funder_name" end - add_index "projects", ["slug"], :name => "index_projects_on_slug", :unique => true + add_index "projects", ["slug"], name: "index_projects_on_slug", unique: true, using: :btree create_table "question_formats", :force => true do |t| t.string "title" t.text "description" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + + create_table "question_options", force: :cascade do |t| + t.integer "new_question_id" + t.integer "option_id" + t.string "text" + t.integer "number" + t.boolean "is_default" + t.datetime "created_at" + t.datetime "updated_at" end create_table "questions", :force => true do |t| @@ -240,12 +367,11 @@ 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", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false t.integer "question_format_id" t.boolean "option_comment_display", :default => true end @@ -255,62 +381,86 @@ 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" + add_index "questions_themes", ["question_id", "theme_id"], name: "index_questions_themes_on_question_id_and_theme_id", using: :btree - create_table "roles", :force => true do |t| - t.string "name" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false - t.boolean "role_in_plans" - t.integer "resource_id" - t.string "resource_type" + create_table "region_groups", force: :cascade do |t| + t.integer "super_region_id" + t.integer "region_id" 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" + create_table "regions", force: :cascade do |t| + t.string "abbreviation" + t.string "description" + t.string "name" + end - create_table "sections", :force => true do |t| + create_table "roles", force: :cascade do |t| + t.boolean "creator" + t.boolean "editor" + t.boolean "administrator" + t.integer "user_id" + t.integer "new_plan_id" + t.datetime "created_at" + t.datetime "updated_at" + end + + create_table "sections", force: :cascade do |t| t.string "title" t.text "description" t.integer "number" t.integer "version_id" t.integer "organisation_id" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false t.boolean "published" end create_table "settings", :force => true do |t| t.string "var", :null => false t.text "value" - t.integer "target_id", :null => false - t.string "target_type", :null => false - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.integer "target_id", null: false + t.string "target_type", null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false 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 => true do |t| t.string "destination" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false end create_table "suggested_answers", :force => true do |t| t.integer "question_id" t.integer "organisation_id" t.text "text" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false t.boolean "is_example" end - create_table "themes", :force => true do |t| + create_table "templates", force: :cascade do |t| t.string "title" t.text "description" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.boolean "published" + t.integer "organisation_id" + t.string "locale" + 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" + end + + create_table "themes", force: :cascade do |t| + t.string "title" + t.text "description" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false t.string "locale" end @@ -327,35 +477,12 @@ t.datetime "updated_at", :null => false end - create_table "user_role_types", :force => true do |t| - t.string "name" - t.text "description" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false - end - - create_table "user_statuses", :force => true do |t| - t.string "name" - t.text "description" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false - end - - create_table "user_types", :force => true do |t| - t.string "name" - t.text "description" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false - end - - create_table "users", :force => true do |t| + 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.integer "user_type_id" - t.integer "user_status_id" t.datetime "created_at" t.datetime "updated_at" t.string "encrypted_password", :default => "" @@ -380,17 +507,17 @@ t.integer "organisation_id" 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 => true do |t| + create_table "users_perms", id: false, force: :cascade do |t| t.integer "user_id" - t.integer "role_id" + t.integer "perm_id" end - add_index "users_roles", ["user_id", "role_id"], :name => "index_users_roles_on_user_id_and_role_id" + add_index "users_perms", ["user_id", "perm_id"], name: "index_users_perms_on_user_id_and_perm_id", using: :btree create_table "versions", :force => true do |t| t.string "title" @@ -398,10 +525,10 @@ t.boolean "published" t.integer "number" t.integer "phase_id" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false 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 end \ No newline at end of file diff --git a/db/seeds.rb b/db/seeds.rb index 91a4fde..8b1b243 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -126,7 +126,6 @@ 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", - domain: "example.regionalcurationcenter.org", region: 'UK', language: 'English(UK)' }, @@ -137,7 +136,6 @@ organisation_type: "Funder", description: "An example: Research funding agency", banner_text: "Example: Global Research Center", - domain: "example.globalresearchcenter.org", region: 'UK', language: 'English(UK)' }, @@ -148,14 +146,12 @@ organisation_type: "Funder", description: "An example: Regional funding agency for scientific research", banner_text: "Example: Regional Science Federation", - domain: "example.regionalsciencefederation.org", region: 'UK', language: 'English(UK)' }, 'Example Institution'=> { name: "Capital City College", abbreviation: "CapColl", - domain: "example.capitalcitycollege.edu", sort_name: "CapitalCityCollege", organisation_type: "Institution", description: "An example: Academic institution", @@ -170,7 +166,6 @@ organisation = Organisation.new organisation.name = details[:name] organisation.abbreviation = details[:abbreviation] - organisation.domain = details[:domain] 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 @@ -223,24 +218,6 @@ end end -user_role_types = { - 'admin' => { - name: 'admin' - }, - 'org_admin' => { - name: 'org_admin' - }, - 'user' => { - name: 'user' - } -} - -user_role_types.each do |urt, details| - if UserRoleType.where(name: details[:name]).empty? - UserRoleType.create(name: details[:name]) - end -end - users = { 'Super admin' => { email: "super_admin@example.com",