I have three different models as User
, PermissionSet
and Permission
. These models represent their SQL tables respectively.
User
has a many-to-one association PermissionSet
, a user may have one PermissionSet
or none. PermissionSet
s would be owned by none or many User
s.
PermissionSet
has many-to-many association with Permission
s. A Permission
could be owned by multiple PermissionSet
s or none, where PermissionSet
s may own multiple Permission
s or none at all.
So I created four tables: users
, permission_sets
, permissions
and a junction table, permission_sets_permissions
.
I need to persist the changes made in a User
's PermissionSet
. This is handled by a model called PermissionSetGrant
, which has its own table, permission_set_grants
.
What is the best way to alter the Permission
s of a PermissionSet
with a RESTful API, based on HTTP and JSON?
For example, is it a good way to modify a PermissionSet
with such request:
PUT /api/v1/permission_sets/7
// Payload
{
"permission_set": {
// Assume these properties of the entity aren't changed
"name": "default",
"description": "Default permission set.",
// Here we're changing the permissions
"permission_ids": [
24,
27,
35
]
}
}
-> 200 OK
or add permissions with an extra REST path instead?
POST /api/v1/permission_sets/7/permissions
// Payload
{
"permission": 24
}
-> 201 CREATED
and when we need to delete that permission
DELETE /api/v1/permission_sets/7/permissions/24
-> 203 ACCEPTED
I would also add that the request is idempotent and deterministic from the client's aspect. The number of permissions is 100, at least. Hence, batch operations will be performed in second approach.