diff --git a/Gemfile b/Gemfile index 51f6d66..4d72799 100644 --- a/Gemfile +++ b/Gemfile @@ -15,6 +15,7 @@ # ------------------------------------------------ # DATABASE/SERVER +gem 'pg' gem 'mysql2', '~> 0.3.18' # ------------------------------------------------ @@ -74,6 +75,7 @@ gem 'feedjira' gem 'caracal' # WORD DOC EXPORTING gem 'caracal-rails' +gem 'yaml_db', :git => 'https://github.com/vyruss/yaml_db.git' # ------------------------------------------------ # INTERNATIONALIZATION @@ -121,4 +123,5 @@ # gem 'exception_notification' # UNUSED BUT COULD BE USEFUL FOR ERROR MSG BEING SENT TO ADMINS FROM PROD SYS # gem 'email_validator' # UNUSED ACTIVERECORD VALIDATOR # gem 'validate_url' # UNUSED ACTIVERECORD VALIDATOR -# gem 'turbolinks' # IS NOW A CORE PART OF RAILS >= 4.0 \ No newline at end of file +# gem 'turbolinks' # IS NOW A CORE PART OF RAILS >= 4.0 + diff --git a/Gemfile.lock b/Gemfile.lock index 45586fc..c2837f9 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -213,6 +213,7 @@ omniauth-shibboleth (1.2.1) omniauth (>= 1.0.0) orm_adapter (0.5.0) + pg (0.19.0) pkg-config (1.1.7) polyamorous (1.3.1) activerecord (>= 3.0) @@ -313,6 +314,9 @@ wkhtmltopdf-binary (0.12.3) xpath (2.0.0) nokogiri (~> 1.3) + yaml_db (0.4.2) + rails (>= 3.0, < 5.1) + rake (>= 0.8.7) yard (0.9.5) PLATFORMS @@ -344,6 +348,7 @@ mysql2 (~> 0.3.18) omniauth omniauth-shibboleth + pg protected_attributes pundit rack-test @@ -363,6 +368,7 @@ web-console (~> 2.0) wicked_pdf wkhtmltopdf-binary + yaml_db yard RUBY VERSION diff --git a/README.md b/README.md index 13ddc72..597ae17 100644 --- a/README.md +++ b/README.md @@ -1,14 +1,13 @@ ## DMP Roadmap -DMP Roadmap is a Data Management Planning tool. It allows users to create data management plans for the projects using funder specific templates and institutional guidance. Once a plan has been completed it can be downloaded and inserted into your grant proposals. +DMP Roadmap is a Data Management Planning tool. Management and development of DMP Roadmap is jointly provided by the Digital Curation Centre (DCC), http://www.dcc.ac.uk/, and the University of California Curation Center (UC3), http://www.cdlib.org/services/uc3/ -Management and development of the DMP Roadmap is jointly provided by the Digital Curation Centre (DCC), http://www.dcc.ac.uk/, and the University of California Curation Center (UC3), http://www.cdlib.org/services/uc3/ +The tool has four main functions: -The tool has four main functions -1. To help create and maintain different versions of Data Management Plans; -2. To provide useful guidance on data management issues and how to meet research funders' requirements; -3. To export attractive and useful plans in a variety of formats; -4. To allow collaborative work when creating Data Management Plans. +1. To help create and maintain different versions of Data Management Plans; +2. To provide useful guidance on data management issues and how to meet research funders' requirements; +3. To export attractive and useful plans in a variety of formats; +4. To allow collaborative work when creating Data Management Plans. #### Current Release v.0.1.0 @@ -26,7 +25,6 @@ Further details on how to install MySQL and create your first user and database. Be sure to follow the instructions for your particular environment. * Install: http://dev.mysql.com/downloads/mysql/ -* * Create a user: http://dev.mysql.com/doc/refman/5.7/en/create-user.html * Create the database: http://dev.mysql.com/doc/refman/5.7/en/creating-database.html @@ -91,13 +89,13 @@ > > bundle install #### Support -Issues should be reported here on Github https://github.com/DMPRoadmap/roadmap/issues +Issues should be reported here on [Github Issues](https://github.com/DMPRoadmap/roadmap/issues) Please be advised though that we can only provide limited support for your local installations. #### Become a contributor Fork this repository and make your modifications in a new branch. Then create a pull request to our 'development' branch. We will reject any pull request made against the 'master' branch. Once your pull request has been submitted the team will review your request and accept it if appropriate. -Join the email listserv at roadmap-l (at) listserv.ucop (dot) edu. +Join the developer email listserv at www.jiscmail.ac.uk/DMPONLINE-DEV #### License -The DMP Roadmap project uses to the MIT License. +The DMP Roadmap project uses the MIT License. diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index f01d810..e5b9bed 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -249,7 +249,7 @@ #subset guidance that belong to the institution unless institution.nil? then authorize Project - optional_gg = GuidanceGroup.where("optional_subset = ? && organisation_id = ?", true, institution.id) + optional_gg = GuidanceGroup.where("optional_subset = ? AND organisation_id = ?", true, institution.id) optional_gg.each do|optional| guidance_groups[optional.id] = optional.name end @@ -272,7 +272,7 @@ #If template belongs to a funder and that funder has subset guidance display then. if !template.nil? && template.organisation.organisation_type.name == constant("organisation_types.funder") then - optional_gg = GuidanceGroup.where("optional_subset = ? && organisation_id = ?", true, template.organisation_id) + optional_gg = GuidanceGroup.where("optional_subset = ? AND organisation_id = ?", true, template.organisation_id) optional_gg.each do|optional| guidance_groups[optional.id] = optional.name end @@ -335,7 +335,7 @@ guidance_groups = [] #subset guidance that belong to an institution - optional_gg = GuidanceGroup.where("optional_subset = ? && organisation_id IS NOT NULL", true) + optional_gg = GuidanceGroup.where("optional_subset = ? AND organisation_id IS NOT NULL", true) optional_gg.each do|optional| guidance_groups << optional.id @@ -347,7 +347,7 @@ end # If template belongs to a funder and is an optional_subset - optional_gg = GuidanceGroup.where("optional_subset = ? && organisation_id IN (?)", true, orgs_of_type(constant("organisation_types.funder"))) + optional_gg = GuidanceGroup.where("optional_subset = ? AND organisation_id IN (?)", true, orgs_of_type(constant("organisation_types.funder"))) optional_gg.each do|optional| guidance_groups << optional.id end diff --git a/app/controllers/token_permission_types_controller.rb b/app/controllers/token_permission_types_controller.rb index 5d5c3fc..3500374 100644 --- a/app/controllers/token_permission_types_controller.rb +++ b/app/controllers/token_permission_types_controller.rb @@ -2,6 +2,7 @@ def index authorize TokenPermissionType @user = current_user + @token_types = @user.organisation.token_permission_types respond_to do |format| format.html end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 4d6bd4f..52f9558 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -4,7 +4,7 @@ def admin_index authorize User - @users = User.where(organisation: current_user.organisation).includes(:project_groups) + @users = current_user.organisation.users.includes(:project_groups) respond_to do |format| format.html # index.html.erb diff --git a/app/models/organisation.rb b/app/models/organisation.rb index d073907..fada6d0 100644 --- a/app/models/organisation.rb +++ b/app/models/organisation.rb @@ -8,6 +8,7 @@ has_many :guidance_groups has_many :dmptemplates has_many :sections + has_many :user_org_roles has_many :users has_many :option_warnings has_many :suggested_answers @@ -167,7 +168,7 @@ # # @return [Array] published dmptemplates def published_templates - return dmptemplates.where("published = ?", 1) + return dmptemplates.where("published = ?", true) end def check_api_credentials diff --git a/app/models/user.rb b/app/models/user.rb index d3bec38..484f41b 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -13,7 +13,6 @@ has_many :answers has_many :user_org_roles has_many :project_groups, :dependent => :destroy - #has_many :organisations , through: :user_org_roles has_many :user_role_types, through: :user_org_roles has_one :language @@ -78,85 +77,24 @@ # @param new_organisation_id [Integer] the id for an organisation # @return [String] the empty string as a causality of setting api_token def organisation_id=(new_organisation_id) - # DEPRICATED STRUCTURE ONLY USED HERE -# if !self.user_org_roles.pluck(:organisation_id).include?(new_organisation_id.to_i) then - # if the user has more than one role -# if self.user_org_roles.count != 1 then -# new_user_org_role = UserOrgRole.new -# new_user_org_role.organisation_id = new_organisation_id -# new_user_org_role.user_role_type = UserRoleType.find_by(name: constant("user_role_types.user")); -# self.user_org_roles << new_user_org_role - # if the user has roles other than one(0/2/3?) -# else - # set role to first role -# user_org_role = self.user_org_roles.first - # change org_id to new org_id -# user_org_role.organisation_id = new_organisation_id - # save modified role -# user_org_role.save - # if the user is not part of the new organisation -# if !self.user_org_roles.pluck(:organisation_id).include?(new_organisation_id.to_i) then -# unless self.can_change_org? - # rip all permissions from user -# self.roles.delete_all -# self.save! -# end -# end -# end -# end - - self.organisation = Organisation.find(new_organisation_id) - - # rip api_token from user + unless self.can_change_org? || new_organisation_id.nil? || self.organisation.nil? + # rip all permissions from the user + self.roles.delete_all + end + # set the user's new organisation + super(new_organisation_id) + self.save! + # rip api permissions from the user self.remove_token! end ## - # returns the first organisation id of the user or nil - # - # @return [Integer, nil] the id of the user's organisation - def organisation_id -# if self.organisations.count > 0 then -# return self.organisations.first.id -# else -# return nil -# end - (self.organisation.nil? ? nil : self.organisation.id) - end - - ## - # returns the organisation of the user or nil - # - # @return [Organisation, nil] the organisation of the user -# def organisation -# if self.organisations.count > 0 then -# return self.organisations.first -# else -# return nil -# end -# end - - ## - # returns the last organisation in the list of organisations - # possibly depricated as the user only has one organisation in the current schema - # - # @return [Organisation, nil] the organisation for the user - def current_organisation -# if self.organisations.count > 0 then -# return self.organisations.last -# else -# return nil -# end - self.organisation - end - - ## # sets a new organisation for the user # # @param new_organisation [Organisation] the new organisation for the user -# def organisation=(new_organisation) -# organisation_id = organisation.id -# end + def organisation=(new_organisation) + organisation_id = new_organisation.id unless new_organisation.nil? + end ## # checks if the user is a super admin @@ -300,33 +238,23 @@ modify_guidance = Role.find_by(name: 'modify_guidance') change_org_details = Role.find_by(name: 'change_org_details') User.includes(:roles).all.each do |user| - roles = user.roles - roles.each do |role| - if role.blank? - elsif role.name == 'admin' - #add admin roles - user.roles << add_orgs unless user.can_add_orgs? - user.roles << change_org_affiliation unless user.can_change_org? - user.roles << grant_api_to_orgs unless user.can_grant_api_to_orgs? - user.roles << grant_permissions unless user.can_grant_permissions? - elsif role.name == 'org_admin' - #add org-admin roles - user.roles << grant_permissions unless user.can_grant_permissions? - user.roles << modify_templates unless user.can_modify_templates? - user.roles << modify_guidance unless user.can_modify_guidance? - user.roles << change_org_details unless user.can_modify_org_details? - end - end - #rip roles from user - if user.roles.include?(admin) + if user.roles.include? admin + #add admin roles + user.roles << add_orgs unless user.roles.include? add_orgs + user.roles << change_org_affiliation unless user.roles.include? change_org_affiliation + user.roles << grant_api_to_orgs unless user.roles.include? grant_api_to_orgs + user.roles << grant_permissions unless user.roles.include? grant_permissions user.roles.delete(admin) - end - if user.roles.include?(org_admin) + elsif user.roles.include? 'org_admin' + #add org-admin roles + user.roles << grant_permissions unless user.roles.include? grant_permissions + user.roles << modify_templates unless user.roles.include? modify_templates + user.roles << modify_guidance unless user.roles.include? modify_guidance + user.roles << change_org_details unless user.roles.include? change_org_details user.roles.delete(org_admin) end - # save the user - user.save! + # save the user + user.save! end end - end diff --git a/app/views/devise/registrations/edit.html.erb b/app/views/devise/registrations/edit.html.erb index 7357115..5ff15d9 100644 --- a/app/views/devise/registrations/edit.html.erb +++ b/app/views/devise/registrations/edit.html.erb @@ -42,7 +42,7 @@ { :class => "typeahead org_sign_up" }) %> <% other_organisations = Array.new %> - <% Organisation.where("parent_id IS ? AND is_other = ?", nil, 1).each do |org| %> + <% Organisation.where("parent_id IS ? AND is_other = ?", nil, true).each do |org| %> <% other_organisations << org.id %> <% end %> "> diff --git a/app/views/plans/_answer_form.html.erb b/app/views/plans/_answer_form.html.erb index 57198f7..5f262ba 100644 --- a/app/views/plans/_answer_form.html.erb +++ b/app/views/plans/_answer_form.html.erb @@ -165,10 +165,11 @@
- <% @comments = Comment.where("question_id = ? && plan_id = ?", question.id, answer.plan_id ) %> + <% @comments = Comment.where("question_id = ? AND plan_id = ?", question.id, answer.plan_id ) %> <%= hidden_field_tag :question_id, question.id, :class => "question_id" %> + <% @question_guidances = @plan.guidance_for_question(question) %>
    - <% if (!question.guidance.nil? && question.guidance != "") || @plan.guidance_for_question(question).count > 0 then %> + <% if (!question.guidance.nil? && question.guidance != "") || @question_guidances.count > 0 then %> <% css_style_comment_div = "display: none;"%> <% css_style_guidance_div = ""%> @@ -224,7 +225,7 @@
<% end %> - <% @plan.guidance_for_question(question).each_pair do |group,themes| %> + <% @question_guidances.each_pair do |group,themes| %> <% themes.each_pair do |theme,guidances| %> <% guidances.each do |guidance| %>
diff --git a/app/views/plans/_comments.html.erb b/app/views/plans/_comments.html.erb index 9fd8d19..dc21608 100644 --- a/app/views/plans/_comments.html.erb +++ b/app/views/plans/_comments.html.erb @@ -3,7 +3,7 @@ -<% @comments = Comment.where("question_id = ? && plan_id = ?", questionId, plan_id) %> +<% @comments = Comment.where("question_id = ? AND plan_id = ?", questionId, plan_id) %> <%= hidden_field_tag :question_id, questionId, :class => "question_id" %> <% if @comments.count > 0 then%> diff --git a/app/views/shared/_register_form.html.erb b/app/views/shared/_register_form.html.erb index 11100ad..b026327 100644 --- a/app/views/shared/_register_form.html.erb +++ b/app/views/shared/_register_form.html.erb @@ -25,7 +25,7 @@ <% other_organisations = Array.new %> - <% Organisation.where("parent_id IS ? AND is_other = ?", nil, 1).each do |org| %> + <% Organisation.where("parent_id IS ? AND is_other = ?", nil, true).each do |org| %> <% other_organisations << org.id %> <% end %>