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..d34dad3f63 100644 --- a/app/scripts/services/membership/roleBindings.js +++ b/app/scripts/services/membership/roleBindings.js @@ -87,20 +87,27 @@ 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}); + var toMatch = { name: subjectName }; + if(namespace) { + toMatch.namespace = namespace; + } + + binding.subjects = _.reject(binding.subjects, toMatch); + 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 @@