diff --git a/app/models/user.rb b/app/models/user.rb index 8929649..099e682 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -173,6 +173,60 @@ end ## + # checks if the user can add new organisations + # + # @return [Boolean] true if the user can add new organisations + def can_add_orgs? + add_orgs = roles.find_by(name: constant("add_organisations")) + return !add_orgs.nil? + end + + ## + # checks if the user can change their organisation affiliations + # + # @return [Boolean] true if the user can change their organisation affiliations + def can_change_org? + change_org = roles.find_by(name: constant("change_org_affiliation")) + return !change_org.nil? + end + + ## + # checks if the user can grant their permissions to others + # + # @return [Boolean] true if the user can grant their permissions to others + def can_grant_permissions? + grant_perms = roles.find_by(name: constant("grant_permissions")) + return !grant_perms.nil? + end + + ## + # checks if the user can modify organisation templates + # + # @return [Boolean] true if the user can modify organisation templates + def can_modify_templates? + modify_temp = roles.find_by(name: constant("modify_templates")) + return !modify_temp.nil? + end + + ## + # checks if the user can modify organisation guidance + # + # @return [Boolean] true if the user can modify organistion guidance + def can_modify_guidance? + modify_guidance = roles.find_by(name: constant("modify_guidance")) + return !modify_guidance.nil? + end + + ## + # checks if the user can use the api + # + # @return [Boolean] true if the user can use the api + def can_use_api? + use_api = roles.find_by(name: constant("use_api")) + return !use_api.nil? + end + + ## # checks what type the user's organisation is # # @return [String] the organisation type diff --git a/config/initializers/locale.rb b/config/initializers/locale.rb index 261f930..220f920 100644 --- a/config/initializers/locale.rb +++ b/config/initializers/locale.rb @@ -19,4 +19,4 @@ # set fallback locale config.i18n.fallbacks = true end -end \ No newline at end of file +end diff --git a/config/locales/en-UK.yml b/config/locales/en-UK.yml index c3c1b1b..b5acf40 100644 --- a/config/locales/en-UK.yml +++ b/config/locales/en-UK.yml @@ -949,6 +949,12 @@ super_admin: 'admin' organisational_admin: 'org_admin' user: 'user' + add_organisations: 'add_organisations' + change_org_affiliation: 'change_org_affiliation' + grant_permissions: 'grant_permissions' + modify_templates: 'modify_templates' + modify_guidance: 'modify_guidance' + use_api: 'use_api' api_endpoint_types: guidances: 'guidances' plans: 'plans' diff --git a/db/seeds.rb b/db/seeds.rb index 8cde5a0..051acbc 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -28,12 +28,14 @@ } languages.each do |l, details| - language = Language.new - language.abbreviation = details[:abbreviation] - language.description = details[:description] - language.name = details[:name] - language.default_language = details[:default_language] - language.save! + 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 = { @@ -55,11 +57,13 @@ } regions.each do |l, details| - region = Region.new - region.abbreviation = details[:abbreviation] - region.description = details[:description] - region.name = details[:name] - region.save! + 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 = { @@ -74,10 +78,12 @@ } region_groups.each do |l, details| - 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! + 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 organisation_types = { @@ -176,6 +182,24 @@ }, 'user' => { name: "user" + }, + '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' } } @@ -214,7 +238,7 @@ password_confirmation: "password123", organisation: "RCC", language: 'English(UK)', - roles: ['admin','org_admin'], + roles: ['admin','org_admin','add_organisations','change_org_affiliation','grant_permissions','modify_templates','modify_guidance','use_api'], accept_terms: true, confirmed_at: Time.zone.now }, @@ -271,7 +295,6 @@ usr.roles << Role.find_by_name(role) end usr.accept_terms = details[:accept_terms] - usr.save! end end @@ -723,10 +746,12 @@ } token_permission_types.each do |title,settings| - token_permission_type = TokenPermissionType.new - token_permission_type.token_type = title - token_permission_type.text_desription = settings[:description] - token_permission_type.save! + 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