MCPcopy Index your code
hub / github.com/apache/casbin / HasRoleForUser

Method HasRoleForUser

rbac_api.go:49–63  ·  view source on GitHub ↗

HasRoleForUser determines whether a user has a role.

(name string, role string, domain ...string)

Source from the content-addressed store, hash-verified

47
48// HasRoleForUser determines whether a user has a role.
49func (e *Enforcer) HasRoleForUser(name string, role string, domain ...string) (bool, error) {
50 roles, err := e.GetRolesForUser(name, domain...)
51 if err != nil {
52 return false, err
53 }
54 hasRole := false
55 for _, r := range roles {
56 if r == role {
57 hasRole = true
58 break
59 }
60 }
61
62 return hasRole, nil
63}
64
65// AddRoleForUser adds a role for a user.
66// Returns false if the user already has the role (aka not affected).

Callers

nothing calls this directly

Calls 1

GetRolesForUserMethod · 0.95

Tested by

no test coverage detected