-
Notifications
You must be signed in to change notification settings - Fork 286
/
scan_tenant_user.py
33 lines (28 loc) · 1.06 KB
/
scan_tenant_user.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import os
import django
# 导入settings
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "arkid.settings")
# 安装django
django.setup()
from arkid.core.models import User, Tenant, UserPermissionResult
# tenants = Tenant.valid_objects.all()
users = User.valid_objects.all()
# print('total:'+str(len(tenants)))
# for tenant in tenants:
# print('-----------------begin--------------')
# print('tenant name:'+tenant.name)
# for user in users:
# is_admin = tenant.has_admin_perm(user)
# if is_admin and UserPermissionResult.valid_objects.filter(tenant=tenant, app=None, user=user).exists():
# # 重复添加不会有问题,只会保留一个
# print('add admin in tenant users:'+user.username)
# tenant.users.add(user)
# tenant.save()
# print('-----------------end--------------')
# 如果有用户没在tenant.users里手动加进去
print('total:'+str(len(users)))
for index, user in enumerate(users):
print('index:'+str(index))
tenant = user.tenant
tenant.users.add(user)
tenant.save()