Skip to content
24 changes: 7 additions & 17 deletions app/admin/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
filter :firstname
filter :surname
filter :email
filter :organisations
filter :other_organisation
filter :organisation
filter :created_at
filter :updated_at

Expand All @@ -31,14 +30,10 @@
link_to user.surname, [:admin, user]
end
column I18n.t('admin.last_logged_in'), :last_sign_in_at
column I18n.t('admin.org_title'), :sortable => 'organisations.name' do |org_title|

column I18n.t('admin.org_title'), :sortable => 'organisation.name' do |org_title|
if !org_title.organisation.nil? then
if org_title.other_organisation.nil? || org_title.other_organisation == "" then
link_to org_title.organisation.name, [:admin, org_title.organisation]
else
I18n.t('helpers.org_type.org_name') + ' - ' + org_title.other_organisation

end
link_to org_title.organisation.name, [:admin, org_title.organisation]
end
end

Expand Down Expand Up @@ -89,9 +84,9 @@
f.input :orcid_id
f.input :api_token
# f.input :shibboleth_id
f.input :organisation_id ,:label => I18n.t('admin.org_title'),
:as => :select,
:collection => Organisation.order('name').map{|orgp|[orgp.name, orgp.id]}
f.input :organisation_id, :label => I18n.t('admin.org_title'),
: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,
Expand All @@ -104,8 +99,6 @@
:multiple => true,
:include_blank => I18n.t('helpers.none'),
:collection => Role.order('name').map{|ro| [ro.name, ro.id]}

f.input :api_token
end

f.actions
Expand All @@ -114,9 +107,6 @@


controller do
def scoped_collection
resource_class.includes(:organisations) # prevents N+1 queries to your database
end

def permitted_params
params.permit!
Expand Down
54 changes: 0 additions & 54 deletions app/admin/user_org_role.rb

This file was deleted.

2 changes: 1 addition & 1 deletion app/assets/javascripts/projects.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ $( document ).ready(function() {

// ----------------------------------------------------------
$("#project_funder_name").change(function(){
$("#confirm-funder").text($(this).val());
$("#confirm-funder").text($("#project_funder_id :selected").text());
});

// ----------------------------------------------------------
Expand Down
8 changes: 5 additions & 3 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -245,16 +245,18 @@ def self.update_user_permissions
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)
elsif user.roles.include? 'org_admin'
user.save!
end
if 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)
# save the user
user.save!
end
# save the user
user.save!
end
end
end
2 changes: 1 addition & 1 deletion app/views/layouts/_dmponline_navigation.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
<% else %>
<li>
<% end %>
<%= link_to t("helpers.create_plan_label"), "/projects/new"%>
<%= link_to t("helpers.create_plan_label"), new_project_path %>
</li>

<% else %>
Expand Down
135 changes: 135 additions & 0 deletions lib/tasks/migrate.rake
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,139 @@ namespace :migrate do
User.update_user_permissions
end

desc "perform entire data migration"
task setup: :environment do
Rake::Task['db:drop'].execute
Rake::Task['db:create'].execute
Rake::Task['db:schema:load'].execute
Rake::Task['db:data:load'].execute
Rake::Task['db:migrate'].execute
Rake::Task['migrate:seed'].execute
Rake::Task['migrate:permissions'].execute
end

desc "seed database with default values for new data structures"
task seed: :environment do
# seed roles to database
roles = {
'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

# seed token permission types to database
token_permission_types = {
'guidances' => {
description: "allows a user access to the guidances api endpoint"
},
'plans' => {
description: "allows a user access to the plans api endpoint"
},
'templates' => {
description: "allows a user access to the templates api endpoint"
},
'statistics' => {
description: "allows a user access to the statistics api endpoint"
}
}
token_permission_types.each do |title,settings|
if TokenPermissionType.where(token_type: title).empty?
token_permission_type = TokenPermissionType.new
token_permission_type.token_type = title
token_permission_type.text_desription = settings[:description]
token_permission_type.save!
end
end

# seed languages to database
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',
default_language: false
},
'DE' => {
abbreviation: 'de',
description: '',
name: 'de',
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

# seed regions to database
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

end
end