Skip to content

Commit

Permalink
fix(rbac_api.go): DeleteUser should remove Policies and Grouping Poli…
Browse files Browse the repository at this point in the history
…cies

Previously it just removed Grouping policies. Now it shares same implementation as DeleteRole
casbin/node-casbin#118
  • Loading branch information
Sefriol committed Feb 20, 2020
1 parent c677db1 commit f33647d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
10 changes: 9 additions & 1 deletion rbac_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,18 @@ func (e *Enforcer) DeleteRolesForUser(user string) (bool, error) {
// DeleteUser deletes a user.
// Returns false if the user does not exist (aka not affected).
func (e *Enforcer) DeleteUser(user string) (bool, error) {
return e.RemoveFilteredGroupingPolicy(0, user)
var err error
res1, err := e.RemoveFilteredGroupingPolicy(0, user)
if err != nil {
return res1, err
}

res2, err := e.RemoveFilteredPolicy(0, user)
return res1 || res2, err
}

// DeleteRole deletes a role.
// Returns false if the role does not exist (aka not affected).
func (e *Enforcer) DeleteRole(role string) (bool, error) {
var err error
res1, err := e.RemoveFilteredGroupingPolicy(1, role)
Expand Down
4 changes: 2 additions & 2 deletions rbac_api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func TestRoleAPI(t *testing.T) {

e.AddRoleForUser("alice", "data2_admin")

testEnforce(t, e, "alice", "data1", "read", true)
testEnforce(t, e, "alice", "data1", "read", false)
testEnforce(t, e, "alice", "data1", "write", false)
testEnforce(t, e, "alice", "data2", "read", true)
testEnforce(t, e, "alice", "data2", "write", true)
Expand All @@ -115,7 +115,7 @@ func TestRoleAPI(t *testing.T) {

e.DeleteRole("data2_admin")

testEnforce(t, e, "alice", "data1", "read", true)
testEnforce(t, e, "alice", "data1", "read", false)
testEnforce(t, e, "alice", "data1", "write", false)
testEnforce(t, e, "alice", "data2", "read", false)
testEnforce(t, e, "alice", "data2", "write", false)
Expand Down

0 comments on commit f33647d

Please sign in to comment.