Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 🎸 处理授权管理列表用户 #1406

Merged
merged 1 commit into from
Nov 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions api/v1/views/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,18 @@ def user_list(request, tenant_id: str, query_data: UserListQueryIn=Query(...)):
# @paginate(CustomPagination)
def user_list_no_super(request, tenant_id: str):
from arkid.core.perm.permission_data import PermissionData
super_user_id = User.valid_objects.order_by('created').first().id
pd = PermissionData()
# super_user_id = User.valid_objects.order_by('created').first().id
tenant = request.tenant
users = tenant.users.filter(is_del=False).exclude(id=super_user_id)
user_managers = pd.get_tenant_managers(tenant)
exclude_ids = []
for user_manager in user_managers:
exclude_ids.append(user_manager.id)
users = tenant.users.filter(is_del=False)
if exclude_ids:
users = users.exclude(id__in=exclude_ids)
# 如果当前登录的用户不是管理员,需要根据用户所拥有的分组进行区分
login_user = request.user
pd = PermissionData()
users = pd.get_manage_all_user(login_user, tenant, users)
return {"data": list(users.all())}

Expand Down
21 changes: 21 additions & 0 deletions arkid/core/perm/permission_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -2545,6 +2545,27 @@ def has_admin_perm(self, tenant, user):
return True
return False

def get_tenant_managers(self, tenant):
'''
取得当前租户所有的管理员
'''
systempermission = SystemPermission.valid_objects.filter(tenant=tenant, code=tenant.admin_perm_code, is_system=True).first()
userpermissionresults = UserPermissionResult.valid_objects.filter(
app=None,
tenant=tenant,
)
compress = Compress()
users = []
for userpermissionresult in userpermissionresults:
permission_result = compress.decrypt(userpermissionresult.result)
permission_result_arr = list(permission_result)
if len(permission_result_arr) > systempermission.sort_id:
check_result = int(permission_result_arr[systempermission.sort_id])
if check_result == 1 and userpermissionresult.user not in users:
users.append(userpermissionresult.user)
return users


def create_tenant_admin_permission(self, tenant):
'''
创建租户管理员权限
Expand Down