Created
November 30, 2015 13:06
-
-
Save mrosenberg/7d37dbc248da59baac02 to your computer and use it in GitHub Desktop.
Remove an account from a Stormpath group knowing only the account and group's href
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function _removeAccountFromGroup(account, group) { | |
var href = new Buffer(group, 'base64').toString('utf8'); | |
function findByGroupId(membership, callback) { | |
return callback(membership.group.href === href); | |
} | |
return Promise.fromNode(function(callback) { | |
return account.getGroupMemberships(function(err, memberships) { | |
if(err) { | |
return callback(err); | |
} | |
return memberships.detect(findByGroupId, function(membership) { | |
return membership.delete(function(err) { | |
if(err) { | |
return callback(err); | |
} | |
return callback(); | |
}); | |
}); | |
}); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment