From d1658214a440e1f6f9e5906dbb8a050cd8364a6a Mon Sep 17 00:00:00 2001 From: Eric Pugh Date: Sat, 18 Jan 2025 08:34:53 -0500 Subject: [PATCH] Remove permissions architecture in favour of roles (#1185) Thank you Pundit and the rich permissions structures you provided, we appreciate your service from when fine grained permissions were needed. --- Gemfile | 1 - Gemfile.lock | 3 - .../components/archive_case/_modal.html | 9 +- .../archive_case_modal_instance_controller.js | 13 +- .../archive_search_endpoint/_modal.html | 16 -- ...arch_endpoint_modal_instance_controller.js | 12 - .../case_listing/case_listing_controller.js | 18 +- .../clone_case/clone_case_controller.js | 49 ++-- .../clone_scorer/clone_scorer_controller.js | 8 - .../components/delete_case/_modal.html | 3 +- .../delete_case_modal_instance_controller.js | 8 - .../components/delete_scorer/_modal.html | 3 +- ...delete_scorer_modal_instance_controller.js | 10 - .../edit_scorer/edit_scorer_controller.js | 4 +- .../components/judgements/_modal.html | 5 +- .../judgements_modal_instance_controller.js | 9 - .../components/new_case/_denied_modal.html | 23 -- ...nied_new_case_modal_instance_controller.js | 21 -- .../new_scorer/new_scorer_controller.js | 8 - .../new_team/new_team_controller.js | 8 - .../components/remove_member/_modal.html | 7 +- ...remove_member_modal_instance_controller.js | 8 - .../components/remove_scorer/_modal.html | 8 +- ...remove_scorer_modal_instance_controller.js | 8 - .../components/share_case/_modal.html | 11 +- .../share_case_modal_instance_controller.js | 10 - .../components/share_scorer/_modal.html | 12 +- .../share_scorer_modal_instance_controller.js | 10 - app/assets/javascripts/controllers/case.js | 30 +-- app/assets/javascripts/services/userSvc.js | 2 +- app/controllers/api/api_controller.rb | 1 - .../api/v1/current_user_controller.rb | 1 - app/controllers/api/v1/scorers_controller.rb | 7 +- app/models/concerns/permissible.rb | 245 ------------------ app/models/permission.rb | 30 --- app/models/user.rb | 4 - app/policies/application_policy.rb | 55 ---- app/policies/case_policy.rb | 52 ---- app/policies/query_policy.rb | 44 ---- app/policies/scorer_policy.rb | 48 ---- app/policies/snapshot_policy.rb | 44 ---- app/policies/team_policy.rb | 44 ---- app/policies/try_policy.rb | 44 ---- app/policies/user_policy.rb | 52 ---- app/services/permissions_evaluator.rb | 42 --- .../api/v1/current_user/show.json.jbuilder | 1 - app/views/api/v1/users/_user.json.jbuilder | 1 + .../20250118025829_drop_permissions_table.rb | 5 + db/schema.rb | 12 +- docs/app_structure.md | 19 -- .../api/v1/current_user_controller_test.rb | 37 +-- .../api/v1/scorers_controller_test.rb | 16 ++ test/models/permission_test.rb | 66 ----- test/services/permissions_evaluator_test.rb | 48 ---- 54 files changed, 76 insertions(+), 1179 deletions(-) delete mode 100644 app/assets/javascripts/components/new_case/_denied_modal.html delete mode 100644 app/assets/javascripts/components/new_case/denied_new_case_modal_instance_controller.js delete mode 100644 app/models/concerns/permissible.rb delete mode 100644 app/models/permission.rb delete mode 100644 app/policies/application_policy.rb delete mode 100644 app/policies/case_policy.rb delete mode 100644 app/policies/query_policy.rb delete mode 100644 app/policies/scorer_policy.rb delete mode 100644 app/policies/snapshot_policy.rb delete mode 100644 app/policies/team_policy.rb delete mode 100644 app/policies/try_policy.rb delete mode 100644 app/policies/user_policy.rb delete mode 100644 app/services/permissions_evaluator.rb create mode 100644 db/migrate/20250118025829_drop_permissions_table.rb delete mode 100644 test/models/permission_test.rb delete mode 100644 test/services/permissions_evaluator_test.rb diff --git a/Gemfile b/Gemfile index bd596d75c..9e19475ea 100644 --- a/Gemfile +++ b/Gemfile @@ -41,7 +41,6 @@ gem 'omniauth-rails_csrf_protection' gem 'postmark-rails' gem 'prophet-rb', '~> 0.5.3' gem 'puma' -gem 'pundit' gem 'rails', '8.0.1' gem 'rails-html-sanitizer' gem 'rack-cors', '~> 2.0' diff --git a/Gemfile.lock b/Gemfile.lock index e04a11fc9..170220776 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -362,8 +362,6 @@ GEM public_suffix (6.0.1) puma (6.5.0) nio4r (~> 2.0) - pundit (2.4.0) - activesupport (>= 3.0.0) raabro (1.4.0) racc (1.8.1) rack (3.1.8) @@ -591,7 +589,6 @@ DEPENDENCIES postmark-rails prophet-rb (~> 0.5.3) puma - pundit rack-cors (~> 2.0) rails (= 8.0.1) rails-controller-testing diff --git a/app/assets/javascripts/components/archive_case/_modal.html b/app/assets/javascripts/components/archive_case/_modal.html index 0457d65aa..a9b344a39 100644 --- a/app/assets/javascripts/components/archive_case/_modal.html +++ b/app/assets/javascripts/components/archive_case/_modal.html @@ -3,14 +3,9 @@ diff --git a/app/assets/javascripts/components/archive_case/archive_case_modal_instance_controller.js b/app/assets/javascripts/components/archive_case/archive_case_modal_instance_controller.js index 1ec9fddf6..629c1cef3 100644 --- a/app/assets/javascripts/components/archive_case/archive_case_modal_instance_controller.js +++ b/app/assets/javascripts/components/archive_case/archive_case_modal_instance_controller.js @@ -8,18 +8,7 @@ angular.module('QuepidApp') function ($rootScope, $uibModalInstance, theCase) { var ctrl = this; - ctrl.theCase = theCase; - ctrl.canDelete = false; - - $rootScope.$watch('currentUser', function() { - if ( $rootScope.currentUser ) { - ctrl.canDelete = $rootScope.currentUser.permissions.case.delete; - } - }); - - ctrl.isOwnerOfCase = function() { - return ($rootScope.currentUser.id === ctrl.theCase.ownerId); - }; + ctrl.theCase = theCase; ctrl.ok = function () { $uibModalInstance.close(true); diff --git a/app/assets/javascripts/components/archive_search_endpoint/_modal.html b/app/assets/javascripts/components/archive_search_endpoint/_modal.html index a0666b10e..e69de29bb 100644 --- a/app/assets/javascripts/components/archive_search_endpoint/_modal.html +++ b/app/assets/javascripts/components/archive_search_endpoint/_modal.html @@ -1,16 +0,0 @@ - - - diff --git a/app/assets/javascripts/components/archive_search_endpoint/archive_search_endpoint_modal_instance_controller.js b/app/assets/javascripts/components/archive_search_endpoint/archive_search_endpoint_modal_instance_controller.js index a4d17f4d3..5b77dd77f 100644 --- a/app/assets/javascripts/components/archive_search_endpoint/archive_search_endpoint_modal_instance_controller.js +++ b/app/assets/javascripts/components/archive_search_endpoint/archive_search_endpoint_modal_instance_controller.js @@ -9,18 +9,6 @@ angular.module('QuepidApp') var ctrl = this; ctrl.theSearchEndpoint = theSearchEndpoint; - //ctrl.canDelete = false; - ctrl.canDelete = true; // hard code that anyone can delete ;-( - - //$rootScope.$watch('currentUser', function() { - // if ( $rootScope.currentUser ) { - // ctrl.canDelete = $rootScope.currentUser.permissions.search_endpoint.delete; - // } - //}); - - ctrl.isOwnerOfSearchEndpoint = function() { - return ($rootScope.currentUser.id === ctrl.theSearchEndpoint.ownerId); - }; ctrl.ok = function () { $uibModalInstance.close(true); diff --git a/app/assets/javascripts/components/case_listing/case_listing_controller.js b/app/assets/javascripts/components/case_listing/case_listing_controller.js index 9e414949d..5e397ec78 100644 --- a/app/assets/javascripts/components/case_listing/case_listing_controller.js +++ b/app/assets/javascripts/components/case_listing/case_listing_controller.js @@ -7,14 +7,12 @@ angular.module('QuepidApp') '$rootScope', '$scope', '$location', - 'flash', 'caseTryNavSvc', 'caseSvc', function ( $rootScope, $scope, $location, - flash, caseTryNavSvc, caseSvc ) { @@ -25,7 +23,6 @@ angular.module('QuepidApp') ctrl.clickToEdit.oldVal = ctrl.thisCase.caseName.slice(0); ctrl.clickToEdit.currVal = ctrl.thisCase.caseName.slice(0); ctrl.clickToEdit.clicked = false; - ctrl.canUpdate = false; // Functions ctrl.cancel = cancel; @@ -39,19 +36,8 @@ angular.module('QuepidApp') $location.path(path); } - $rootScope.$watch('currentUser', function() { - if ( $rootScope.currentUser ) { - ctrl.canUpdate = $rootScope.currentUser.permissions.case.update; - } - }); - - function rename() { - if (ctrl.canUpdate) { - ctrl.clickToEdit.clicked = true; - } - else { - flash.error = 'You do not have update permissions for cases.'; - } + function rename() { + ctrl.clickToEdit.clicked = true; } function cancel() { diff --git a/app/assets/javascripts/components/clone_case/clone_case_controller.js b/app/assets/javascripts/components/clone_case/clone_case_controller.js index 032df3918..cc8a2fc55 100644 --- a/app/assets/javascripts/components/clone_case/clone_case_controller.js +++ b/app/assets/javascripts/components/clone_case/clone_case_controller.js @@ -37,39 +37,26 @@ angular.module('QuepidApp') }); } - function prompt() { - if ( !$rootScope.currentUser.permissions.case.create ) { - var deniedModalInstance = $uibModal.open({ - templateUrl: 'new_case/_denied_modal.html', - controller: 'DeniedNewCaseModalInstanceCtrl', - controllerAs: 'ctrl' - }); - - deniedModalInstance.result.then( - function() { }, - function() { } - ); - } else { - var modalInstance = $uibModal.open({ - templateUrl: 'clone_case/_modal.html', - controller: 'CloneCaseModalInstanceCtrl', - controllerAs: 'ctrl', - resolve: { - theCase: function() { - return ctrl.acase; - } + function prompt() { + var modalInstance = $uibModal.open({ + templateUrl: 'clone_case/_modal.html', + controller: 'CloneCaseModalInstanceCtrl', + controllerAs: 'ctrl', + resolve: { + theCase: function() { + return ctrl.acase; } - }); + } + }); - modalInstance.result.then( - function (options) { - ctrl.cloneCase(options); - }, - function() { - $log.info('INFO: Modal dismissed'); - } - ); - } + modalInstance.result.then( + function (options) { + ctrl.cloneCase(options); + }, + function() { + $log.info('INFO: Modal dismissed'); + } + ); } } ]); diff --git a/app/assets/javascripts/components/clone_scorer/clone_scorer_controller.js b/app/assets/javascripts/components/clone_scorer/clone_scorer_controller.js index 0b16c38c0..e7a3edb2b 100644 --- a/app/assets/javascripts/components/clone_scorer/clone_scorer_controller.js +++ b/app/assets/javascripts/components/clone_scorer/clone_scorer_controller.js @@ -21,14 +21,6 @@ angular.module('QuepidApp') var ctrl = this; ctrl.buttonText = $scope.buttonText; - ctrl.cannotCreate = true; - - $rootScope.$watch('currentUser', function() { - if ( $rootScope.currentUser ) { - ctrl.cannotCreate = !$rootScope.currentUser.permissions.team.create; - } - }); - // Functions ctrl.cloneScorer = cloneScorer; diff --git a/app/assets/javascripts/components/delete_case/_modal.html b/app/assets/javascripts/components/delete_case/_modal.html index e7ff76ead..7709ef28e 100644 --- a/app/assets/javascripts/components/delete_case/_modal.html +++ b/app/assets/javascripts/components/delete_case/_modal.html @@ -3,8 +3,7 @@ - -