def get_perms(self): self.user_perms = [] admin_roles = user_services.list_roles(self.user.enterprise_id, self.user.user_id) self.user_perms = list( perms.list_enterprise_perm_codes_by_roles(admin_roles)) if self.is_team_owner: team_perms = list( PermsInfo.objects.filter(kind="team").values_list("code", flat=True)) self.user_perms.extend(team_perms) self.user_perms.append(200000) else: team_roles = RoleInfo.objects.filter(kind="team", kind_id=self.tenant.tenant_id) if team_roles: role_ids = team_roles.values_list("ID", flat=True) team_user_roles = UserRole.objects.filter( user_id=self.user.user_id, role_id__in=role_ids) if team_user_roles: team_user_role_ids = team_user_roles.values_list("role_id", flat=True) team_role_perms = RolePerms.objects.filter( role_id__in=team_user_role_ids) if team_role_perms: self.user_perms.extend( list( team_role_perms.values_list("perm_code", flat=True))) self.user_perms = list(set(self.user_perms))
def get(self, request, *args, **kwargs): """ 查询我的详情 --- """ code = 200 user = self.user tenants = team_services.get_current_user_tenants(user_id=user.user_id) user_detail = dict() user_detail["user_id"] = user.user_id user_detail["user_name"] = user.nick_name user_detail["email"] = user.email user_detail["enterprise_id"] = user.enterprise_id user_detail["phone"] = user.phone user_detail["git_user_id"] = user.git_user_id user_detail["is_sys_admin"] = user.is_sys_admin enterprise = enterprise_services.get_enterprise_by_enterprise_id(user.enterprise_id) user_detail["is_enterprise_active"] = enterprise.is_active user_detail["is_enterprise_admin"] = self.is_enterprise_admin # enterprise roles user_detail["roles"] = user_services.list_roles(user.enterprise_id, user.user_id) # enterprise permissions user_detail["permissions"] = list_enterprise_perms_by_roles(user_detail["roles"]) tenant_list = list() for tenant in tenants: tenant_info = dict() is_team_owner = False team_region_list = region_services.get_region_list_by_team_name(team_name=tenant.tenant_name) tenant_info["team_id"] = tenant.ID tenant_info["team_name"] = tenant.tenant_name tenant_info["team_alias"] = tenant.tenant_alias tenant_info["limit_memory"] = tenant.limit_memory tenant_info["pay_level"] = tenant.pay_level tenant_info["region"] = team_region_list tenant_info["creater"] = tenant.creater tenant_info["create_time"] = tenant.create_time if tenant.creater == user.user_id: is_team_owner = True role_list = user_kind_role_service.get_user_roles(kind="team", kind_id=tenant.tenant_id, user=user) tenant_info["role_name_list"] = role_list["roles"] perms = user_kind_perm_service.get_user_perms( kind="team", kind_id=tenant.tenant_id, user=user, is_owner=is_team_owner, is_ent_admin=self.is_enterprise_admin) tenant_info["tenant_actions"] = perms["permissions"] tenant_info["is_team_owner"] = is_team_owner tenant_list.append(tenant_info) user_detail["teams"] = tenant_list oauth_services = oauth_user_repo.get_user_oauth_services_info( eid=request.user.enterprise_id, user_id=request.user.user_id) user_detail["oauth_services"] = oauth_services result = general_message(code, "Obtain my details to be successful.", "获取我的详情成功", bean=user_detail) return Response(result, status=code)
def get_perms(self): self.user_perms = [] admin_roles = user_services.list_roles(self.user.enterprise_id, self.user.user_id) self.user_perms = list(perms.list_enterprise_perm_codes_by_roles(admin_roles)) roles = RoleInfo.objects.filter(kind="enterprise", kind_id=self.user.enterprise_id) if roles: role_ids = roles.values_list("ID", flat=True) user_roles = UserRole.objects.filter(user_id=self.user.user_id, role_id__in=role_ids) if user_roles: user_role_ids = user_roles.values_list("role_id", flat=True) role_perms = RolePerms.objects.filter(role_id__in=user_role_ids) if role_perms: self.user_perms = role_perms.values_list("perm_code", flat=True) self.user_perms = list(set(self.user_perms))
def get_perms(self): self.user_perms = [] admin_roles = user_services.list_roles(self.user.enterprise_id, self.user.user_id) self.user_perms = list(perms.list_enterprise_perm_codes_by_roles(admin_roles))