user_groups()
Returns all groups the given user belongs to.
1. Signature
-
Sync
-
Async
ecm.security.user_groups(user_guid: str) -> list[ECMGroup]
await ecm.security.user_groups(user_guid: str) -> list[ECMGroup]
2. Parameters
| Parameter | Default | Description |
|---|---|---|
|
— |
GUID of the user whose group memberships should be returned. |
3. Return value
List of ECMGroup instances. Empty list when the user is not a member of any group.
For ECMGroup fields — see groups().
4. Examples
4.1. Retrieve groups of a user
-
Sync
-
Async
user = ecm.security.user("john")
if user:
groups = ecm.security.user_groups(user.guid)
for group in groups:
print(group.name)
user = await ecm.security.user("john")
if user:
groups = await ecm.security.user_groups(user.guid)
for group in groups:
print(group.name)
4.2. Check if a user is a member of a specific group
-
Sync
-
Async
user = ecm.security.user("john")
if user:
groups = ecm.security.user_groups(user.guid)
is_admin = any(g.name == "Administrators" for g in groups)
print(f"john is admin: {is_admin}")
user = await ecm.security.user("john")
if user:
groups = await ecm.security.user_groups(user.guid)
is_admin = any(g.name == "Administrators" for g in groups)
print(f"john is admin: {is_admin}")
5. See also
-
users() — All users including group list (
extended_info=True) -
groups() — All groups on the server
-
group_members() — Members of a group