From 95a6c6b67ec8b65b3539a2fa512806ddb73696f0 Mon Sep 17 00:00:00 2001 From: benjaminapetersen Date: Tue, 31 Oct 2017 11:27:08 -0400 Subject: [PATCH] Fix bugzilla 15077030 where deleting a rolebinding for a serviceaccount can delete additional rolebindings for serviceaccounts from another namespace --- app/scripts/controllers/membership.js | 5 ++-- .../services/membership/roleBindings.js | 16 +++++++++---- app/views/membership.html | 2 +- dist/scripts/scripts.js | 23 ++++++++++--------- dist/scripts/templates.js | 2 +- 5 files changed, 28 insertions(+), 20 deletions(-) diff --git a/app/scripts/controllers/membership.js b/app/scripts/controllers/membership.js index d21e9fed35..6ea6114b2c 100644 --- a/app/scripts/controllers/membership.js +++ b/app/scripts/controllers/membership.js @@ -274,7 +274,8 @@ angular project: project, subjectKinds: subjectKinds, canUpdateRolebindings: canI('rolebindings', 'update', projectName), - confirmRemove: function(subjectName, kindName, roleName) { + confirmRemove: function(subjectName, kindName, roleName, namespace) { + var redirectToProjectList = null; var modalScope = createModalScope(subjectName, kindName, roleName, $scope.user.metadata.name); if(_.isEqual(subjectName, $scope.user.metadata.name)) { @@ -294,7 +295,7 @@ angular }) .result.then(function() { RoleBindingsService - .removeSubject(subjectName, roleName, $scope.roleBindings, requestContext) + .removeSubject(subjectName, roleName, namespace, $scope.roleBindings, requestContext) .then(function(updateRolebinding) { if(redirectToProjectList) { $location.url("./"); diff --git a/app/scripts/services/membership/roleBindings.js b/app/scripts/services/membership/roleBindings.js index 28bdd2e417..a26bd494f5 100644 --- a/app/scripts/services/membership/roleBindings.js +++ b/app/scripts/services/membership/roleBindings.js @@ -87,20 +87,26 @@ angular }; // has to handle multiple bindings or multiple reference to a subject within a single binding - var removeSubject = function(subjectName, role, roleBindings, context) { - var matches = _.filter(roleBindings, {roleRef: {name: role}}); + var removeSubject = function(subjectName, role, namespace, roleBindings, context) { + var matchingBindings = _.filter(roleBindings, {roleRef: {name: role}}); + return $q.all( - _.map(matches, function(binding) { + _.map(matchingBindings, function(binding) { var tpl = bindingTPL(); binding = _.extend(tpl, binding); cleanBinding(binding); - binding.subjects = _.reject(binding.subjects, {name: subjectName}); + + binding.subjects = _.reject(binding.subjects, { + name: subjectName, + namespace: namespace + }); + return binding.subjects.length ? DataService.update('rolebindings', binding.metadata.name, binding, context) : DataService.delete('rolebindings', binding.metadata.name, context) // For a delete, resp is simply a 201 or less useful object. // Instead, this intercepts the response & returns the binding object - // with the empty .subjects[] list. + // with the empty .subjects[] list. .then(function() { return binding; }); diff --git a/app/views/membership.html b/app/views/membership.html index da29e1475c..d47a31fbb2 100644 --- a/app/views/membership.html +++ b/app/views/membership.html @@ -113,7 +113,7 @@

key="role.metadata.name" key-help="roleHelp(role)" show-action="mode.edit" - action="confirmRemove(subject.name, subjectKind.name, role.metadata.name)" + action="confirmRemove(subject.name, subjectKind.name, role.metadata.name, subject.namespace)" action-title="Remove role {{role.metadata.name}} from {{subject.name}}">
\n" + "
\n" + "
\n" + - "\n" + + "\n" + "
\n" + "
\n" + "
\n" +