psecio / gatekeeper

Gatekeeper: An Authentication & Authorization Library
367 stars 23 forks source link

Re-apply groups #57

Open Swader opened 8 years ago

Swader commented 8 years ago

In typical user management CRUD apps, it's a common case to have to remove users from a group or add them to them - it would be easier if we could do this like so:

$user->changeGroups($_POST['groups']);

Right now, we have to:

  1. Get group IDs from a form
  2. Compare with current group IDs on a user
  3. Revoke any that no longer appear in data from form
  4. Add any new ones that appear in data from form

This is, for obvious reasons, incredibly impractical.

I suggest implementing a new changeGroups method which would remove ALL groups from a user, and at the same time add those we're feeding it. The method should be wrapped in a transaction in order to be safe against failures and leaving a user without groups should something break mid-way.