To track all user role changes in time for Label Studio Enterprise (LSE), you can use the Activity Log. Follow these steps:
- Access the Activity Log in LSE.
- Filter all API requests by the PATCH method and the Request URL
organizations/<organization-id>/memberships
. This will display all the requests where administrators have altered user roles. - Export this table to a CSV file for further analysis, which will include the timestamps of when the role changes occurred.
Remember that you must know the AWS account ID for the AWS account that you use to manage Label Studio Enterprise to perform these steps. By following this process, you can effectively track all user role changes in LSE over time.
OR you can use this script if you have LSE shell_plus access in the terminal:
import os
import django
import json
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "htx.settings.label_studio")
django.setup()
from users.models import User
from organizations.models import OrganizationMember
from activity_log.models import ActivityLog
from collections import defaultdict
if __name__ == '__main__':
organization = 123
users = list(OrganizationMember.objects.filter(organization=organization).values('user__email', 'user__id'))
users = {user['user__id']:user['user__email'] for user in users}
logs = list(ActivityLog.objects.filter(organization_id=organization, request_url__contains='771/memberships', request_method='PATCH').order_by('datetime'))
roles = defaultdict(list)
for log in logs:
j = json.loads(log.extra_data['BODY'])
roles[users.get(j['user_id'], j['user_id'])] += [{'role': j['role'], 'datetime': str(log.datetime)}]
print(json.dumps(roles, indent=2))
with open('user-roles.json', 'w') as f:
json.dump(roles, f, indent=2)
Output will look like:
{
"email1@example.com": [
{
"role": "AD",
"datetime": "2022-07-12 13:28:31.612237+00:00"
},
{
"role": "DI",
"datetime": "2022-09-19 20:33:29.809241+00:00"
}
],
"email2@example.com": [
{
"role": "AN",
"datetime": "2022-07-12 14:26:04.319126+00:00"
},
{
"role": "RE",
"datetime": "2022-07-22 13:54:10.954919+00:00"
},
{
"role": "DI",
"datetime": "2023-01-12 11:55:29.906135+00:00"
}
],
...