diff --git a/.travis.yml b/.travis.yml index 6b46349..453b68d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -14,4 +14,4 @@ - bundle exec rake db:schema:load RAILS_ENV=test script: - - bundle exec rake test test/functional/sections_controller_test.rb + - bundle exec rake test diff --git a/app/controllers/sections_controller.rb b/app/controllers/sections_controller.rb index 13ff18d..bb98094 100644 --- a/app/controllers/sections_controller.rb +++ b/app/controllers/sections_controller.rb @@ -21,10 +21,6 @@ #update a section of a template def admin_update @section = Section.includes(phase: :template).find(params[:id]) - -puts "CONTROLLER: #{current_user.inspect}" -puts "PERMS: #{current_user.perms.inspect}" unless current_user.nil? - authorize @section @section.description = params["section-desc-#{params[:id]}"] @phase = @section.phase diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 98b9c59..13f857c 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -18,7 +18,7 @@ @user = User.includes(:perms).find(params[:id]) authorize @user user_perms = current_user.perms - @perms = user_perms & [Perm::GRANT_PERMISSIONS, Perm::MODIFY_TEMPLATES, Perm::MODIFY_GUIDANCE, Perm::USE_API, Perm::CHANGE_ORG_DETAILS] + @perms = user_perms & [Perm.grant_permissions, Perm.modify_templates, Perm.modify_guidance, Perm.use_api, Perm.change_org_details] end ## @@ -34,14 +34,14 @@ if @user.perms.include? perm if ! perms.include? perm @user.perms.delete(perm) - if perm.id == Perm::USE_API.id + if perm.id == Perm.use_api.id @user.remove_token! end end else if perms.include? perm @user.perms << perm - if perm.name == Perm::USE_API.id + if perm.name == Perm.use_api.id @user.keep_or_generate_token! end end diff --git a/app/models/perm.rb b/app/models/perm.rb index e523ca7..2939a74 100644 --- a/app/models/perm.rb +++ b/app/models/perm.rb @@ -12,14 +12,21 @@ ## # Constant perms - ADD_ORGS = Perm.where(name: 'add_organisations').first.freeze - CHANGE_AFFILIATION = Perm.where(name: 'change_org_affiliation').first.freeze - GRANT_PERMISSIONS = Perm.where(name: 'grant_permissions').first.freeze + #ADD_ORGS = Perm.where(name: 'add_organisations').first.freeze + #CHANGE_AFFILIATION = Perm.where(name: 'change_org_affiliation').first.freeze + #GRANT_PERMISSIONS = Perm.where(name: 'grant_permissions').first.freeze #MODIFY_TEMPLATES = Perm.where(name: 'modify_templates').first.freeze - MODIFY_GUIDANCE = Perm.where(name: 'modify_guidance').first.freeze - USE_API = Perm.where(name: 'use_api').first.freeze - CHANGE_ORG_DETAILS = Perm.where(name: 'change_org_details').first.freeze - GRANT_API = Perm.where(name: 'grant_api_to_orgs').first.freeze + #MODIFY_GUIDANCE = Perm.where(name: 'modify_guidance').first.freeze + #USE_API = Perm.where(name: 'use_api').first.freeze + #CHANGE_ORG_DETAILS = Perm.where(name: 'change_org_details').first.freeze + #GRANT_API = Perm.where(name: 'grant_api_to_orgs').first.freeze - scope :MODIFY_TEMPLATES, -> {Perm.where(name: 'modify_templates').first} + scope :add_orgs, -> {Perm.find_by(name: 'add_organisations')} + scope :change_affiliation, -> {Perm.find_by(name: 'change_org_affiliation')} + scope :grant_permissions, -> {Perm.find_by(name: 'grant_permissions')} + scope :modify_templates, -> {Perm.find_by(name: 'modify_templates')} + scope :modify_guidance, -> {Perm.find_by(name: 'modify_guidance')} + scope :use_api, -> {Perm.find_by(name: 'use_api')} + scope :change_org_details, -> {Perm.find_by(name: 'change_org_details')} + scope :grant_api, -> {Perm.find_by(name: 'grant_api_to_orgs')} end diff --git a/app/models/user.rb b/app/models/user.rb index 062554a..b713bd2 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -163,7 +163,7 @@ # # @return [Boolean] true if the user can add new organisations def can_add_orgs? - perms.include? Perm::ADD_ORGS + perms.include? Perm.add_orgs end ## @@ -171,7 +171,7 @@ # # @return [Boolean] true if the user can change their organisation affiliations def can_change_org? - perms.include? Perm::CHANGE_AFFILIATION + perms.include? Perm.change_affiliation end ## @@ -179,7 +179,7 @@ # # @return [Boolean] true if the user can grant their permissions to others def can_grant_permissions? - perms.include? Perm::GRANT_PERMISSIONS + perms.include? Perm.grant_permissions end ## @@ -187,10 +187,7 @@ # # @return [Boolean] true if the user can modify organisation templates def can_modify_templates? -puts "USER: #{self.perms.select{|p| p.name == 'modify_templates'}}" -puts "CONSTANT: #{Perm.MODIFY_TEMPLATES}" -puts "PERMS: #{self.perms.inspect}" - self.perms.include? Perm.MODIFY_TEMPLATES + self.perms.include? Perm.modify_templates end ## @@ -198,7 +195,7 @@ # # @return [Boolean] true if the user can modify organistion guidance def can_modify_guidance? - perms.include? Perm::MODIFY_GUIDANCE + perms.include? Perm.modify_guidance end ## @@ -206,7 +203,7 @@ # # @return [Boolean] true if the user can use the api def can_use_api? - perms.include? Perm::USE_API + perms.include? Perm.use_api end ## @@ -214,7 +211,7 @@ # # @return [Boolean] true if the user can modify the org's details def can_modify_org_details? - perms.include? Perm::CHANGE_ORG_DETAILS + perms.include? Perm.change_org_details end @@ -223,7 +220,7 @@ # # @return [Boolean] true if the user can grant api permissions to organisations def can_grant_api_to_orgs? - perms.include? Perm::GRANT_API + perms.include? Perm.grant_api end ## diff --git a/app/policies/section_policy.rb b/app/policies/section_policy.rb index df552c9..6effdbe 100644 --- a/app/policies/section_policy.rb +++ b/app/policies/section_policy.rb @@ -18,8 +18,6 @@ end def admin_update? -puts "POLICY: #{user.inspect}" -puts "PERMS: #{user.perms.inspect}" unless user.nil? user.can_modify_templates? && (section.phase.template.org_id == user.org_id) end diff --git a/test/functional/sections_controller_test.rb b/test/functional/sections_controller_test.rb index 846cd31..eb9c9e4 100644 --- a/test/functional/sections_controller_test.rb +++ b/test/functional/sections_controller_test.rb @@ -70,9 +70,6 @@ sign_in @user -puts "TEST USER (#{@user.can_org_admin?}) - #{@user.inspect}" -puts "TEST PERMS: #{@user.perms.inspect}" - # Valid save put admin_update_section_path(@phase.sections.first), {section: params} assert_response :redirect