mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-03 01:41:05 -05:00
Only print user report when run directly as a script
This commit is contained in:
@@ -24,9 +24,15 @@ class RoleCollector:
|
|||||||
else:
|
else:
|
||||||
self._map[user.guid]["roles"].append(role)
|
self._map[user.guid]["roles"].append(role)
|
||||||
|
|
||||||
def iterator(self):
|
def print(self):
|
||||||
for key in self._map.keys():
|
for user_roles in self._map.values():
|
||||||
yield self._map[key]
|
user = user_roles['user']
|
||||||
|
print(f"{user.type}: {user.username} has roles:")
|
||||||
|
for role in user_roles['roles']:
|
||||||
|
if role.space:
|
||||||
|
print(f" {role.type} in {role.space.name}")
|
||||||
|
else:
|
||||||
|
print(f" {role.type}")
|
||||||
|
|
||||||
|
|
||||||
role_collector = RoleCollector()
|
role_collector = RoleCollector()
|
||||||
@@ -74,11 +80,5 @@ for role in map(Role, client.v3.roles.list(space_guids=space_guids, include="use
|
|||||||
role_collector.add(role)
|
role_collector.add(role)
|
||||||
|
|
||||||
|
|
||||||
for user_roles in role_collector.iterator():
|
if __name__ == '__main__':
|
||||||
user = user_roles['user']
|
role_collector.print()
|
||||||
print(f"{user.type}: {user.username} has roles:")
|
|
||||||
for role in user_roles['roles']:
|
|
||||||
if role.space:
|
|
||||||
print(f" {role.type} in {role.space.name}")
|
|
||||||
else:
|
|
||||||
print(f" {role.type}")
|
|
||||||
|
|||||||
Reference in New Issue
Block a user