From 1a2c48ec5d2ae1502bc2c4b59b0d5e73fd5bc909 Mon Sep 17 00:00:00 2001 From: briri Date: Wed, 13 May 2020 11:59:18 -0700 Subject: [PATCH] fixed issue with being unable to grant user specific permission to change org affiliation --- app/controllers/org_admin/templates_controller.rb | 2 +- app/javascript/views/usage/index.js | 15 +++++++++------ app/models/user.rb | 4 ++-- app/policies/user_policy.rb | 2 +- app/views/org_admin/templates/index.html.erb | 4 ++-- yarn.lock | 2 +- 6 files changed, 16 insertions(+), 13 deletions(-) diff --git a/app/controllers/org_admin/templates_controller.rb b/app/controllers/org_admin/templates_controller.rb index 9a82c5000d..b645694737 100644 --- a/app/controllers/org_admin/templates_controller.rb +++ b/app/controllers/org_admin/templates_controller.rb @@ -41,7 +41,7 @@ def organisational .where(customization_of: nil, org_id: current_user.org.id) published = templates.select { |t| t.published? || t.draft? }.length - @orgs = current_user.can_super_admin? ? Org.all : nil + @orgs = current_user.can_change_org? ? Org.all : nil @title = if current_user.can_super_admin? _("%{org_name} Templates") % { org_name: current_user.org.name } else diff --git a/app/javascript/views/usage/index.js b/app/javascript/views/usage/index.js index 1877f905e7..b798de4621 100644 --- a/app/javascript/views/usage/index.js +++ b/app/javascript/views/usage/index.js @@ -14,12 +14,15 @@ $(() => { // attach listener to separator select menu // on change look for "stat" elements and chnage their query param - document.getElementById('csv-field-sep').addEventListener('click', (e) => { - const statElems = document.getElementsByClassName('stat'); - const newSep = 'sep='.concat(encodeURIComponent(e.target.value)); - const changeStatFn = changeStatFnGen(newSep); - Array.from(statElems).forEach(changeStatFn); - }); + const fieldSep = document.getElementById('csv-field-sep'); + if (fieldSep !== null) { + fieldSep.addEventListener('click', (e) => { + const statElems = document.getElementsByClassName('stat'); + const newSep = 'sep='.concat(encodeURIComponent(e.target.value)); + const changeStatFn = changeStatFnGen(newSep); + Array.from(statElems).forEach(changeStatFn); + }); + } initializeCharts(); diff --git a/app/models/user.rb b/app/models/user.rb index 2b4b7938bd..20bdc9d558 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -228,12 +228,12 @@ def identifier_for(scheme) user_identifiers.where(identifier_scheme: scheme).first end - # Checks if the user is a super admin. If the user has any privelege which requires + # Checks if the user is a super admin. If the user has ALL privelege which requires # them to see the super admin page then they are a super admin. # # Returns Boolean def can_super_admin? - self.can_add_orgs? || self.can_grant_api_to_orgs? || self.can_change_org? + can_add_orgs? && can_grant_api_to_orgs? && can_change_org? end # Checks if the user is an organisation admin if the user has any privlege which diff --git a/app/policies/user_policy.rb b/app/policies/user_policy.rb index a73db535b3..29b1772373 100644 --- a/app/policies/user_policy.rb +++ b/app/policies/user_policy.rb @@ -26,7 +26,7 @@ def admin_update_permissions? # Allows the user to swap their org affiliation on the fly def org_swap? - signed_in_user.can_super_admin? + signed_in_user.can_change_org? end def activate? diff --git a/app/views/org_admin/templates/index.html.erb b/app/views/org_admin/templates/index.html.erb index 8cddce371e..a1f002c761 100644 --- a/app/views/org_admin/templates/index.html.erb +++ b/app/views/org_admin/templates/index.html.erb @@ -4,7 +4,7 @@

<%= _('Templates') %>

- <% if current_user.can_super_admin? %> + <% if current_user.can_change_org? %>

<%= _('If you would like to modify one of the templates below, you must first change your organisation affiliation.') %> @@ -116,4 +116,4 @@ <%= _('Create a template') %>

- \ No newline at end of file + diff --git a/yarn.lock b/yarn.lock index 34b85a1cd9..87931bb22b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2853,7 +2853,7 @@ debug@2.6.9, debug@^2.2.0, debug@^2.3.3, debug@^2.6.8, debug@^2.6.9: dependencies: ms "2.0.0" -debug@3.2.6, debug@^3.0.0, debug@^3.1.0, debug@^3.1.1, debug@^3.2.5: +debug@3.2.6, debug@^3.0.0, debug@^3.1.0, debug@^3.1.1, debug@^3.2.5, debug@^3.2.6: version "3.2.6" resolved "https://registry.yarnpkg.com/debug/-/debug-3.2.6.tgz#e83d17de16d8a7efb7717edbe5fb10135eee629b" integrity sha512-mel+jf7nrtEl5Pn1Qx46zARXKDpBbvzezse7p7LqINmdoIk8PYP5SySaxEmYv6TZ0JyEKA1hsCId6DIhgITtWQ==