def get(self, request, team_name, *args, **kwargs): """ 获取团队详情 --- parameters: - name: team_name description: team name required: true type: string paramType: path """ try: tenant = team_services.get_tenant_by_tenant_name(team_name) if not tenant: return Response(general_message(404, "team not exist", "团队{0}不存在".format(team_name)), status=404) user_team_perm = team_services.get_user_perms_in_permtenant(self.user.user_id, team_name) tenant_info = dict() team_region_list = region_services.get_region_list_by_team_name(request=request, team_name=team_name) p = PermActions() 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 not user_team_perm: if not self.user.is_sys_admin and team_name != "grdemo": return Response(general_message(403, "you right to see this team", "您无权查看此团队"), 403) else: perms_list = team_services.get_user_perm_identitys_in_permtenant(user_id=self.user.user_id, tenant_name=tenant.tenant_name) role_name_list = team_services.get_user_perm_role_in_permtenant(user_id=self.user.user_id, tenant_name=tenant.tenant_name) role_perms_tuple = team_services.get_user_perm_in_tenant(user_id=self.user.user_id, tenant_name=tenant.tenant_name) tenant_actions = () tenant_info["identity"] = perms_list + role_name_list if perms_list: final_identity = get_highest_identity(perms_list) perms = p.keys('tenant_{0}_actions'.format(final_identity)) tenant_actions += perms tenant_actions += role_perms_tuple tenant_info["tenant_actions"] = tuple(set(tenant_actions)) return Response(general_message(200, "success", "查询成功", bean=tenant_info), status=200) except Exception as e: logger.exception(e) result = error_message(e.message) return Response(result, status=result["code"])
def get(self, request, *args, **kwargs): """ 查询我的详情 --- """ try: p = PermActions() code = 200 user = self.user user.actions = UserActions() 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 tenant_list = list() for tenant in tenants: tenant_info = dict() team_region_list = region_services.get_region_list_by_team_name( request=request, 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 perms_list = team_services.get_user_perm_identitys_in_permtenant( user_id=user.user_id, tenant_name=tenant.tenant_name) final_identity = perms.get_highest_identity(perms_list) tenant_info["identity"] = final_identity tenant_actions = p.keys( 'tenant_{0}_actions'.format(final_identity)) user.actions.set_actions('tenant', tenant_actions) tenant_info["tenant_actions"] = user.actions.tenant_actions tenant_list.append(tenant_info) user_detail["teams"] = tenant_list result = general_message(code, "Obtain my details to be successful.", "获取我的详情成功", bean=user_detail) except Exception as e: code = 500 logger.exception(e) result = error_message(e.message) return Response(result, status=code)
def get(self, request, *args, **kwargs): """ 查询我的详情 --- """ try: p = PermActions() code = 200 user = self.user user.actions = UserActions() 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 is_user_enter_amdin = user_services.is_user_admin_in_current_enterprise( self.user, user.enterprise_id) user_detail["is_user_enter_amdin"] = is_user_enter_amdin tenant_list = list() for tenant in tenants: tenant_info = dict() team_region_list = region_services.get_region_list_by_team_name( request=request, 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 perms_list = team_services.get_user_perm_identitys_in_permtenant( user_id=user.user_id, tenant_name=tenant.tenant_name) perms_role_id_list = team_services.get_user_perm_role_id_in_permtenant( user_id=user.user_id, tenant_name=tenant.tenant_name) perms_tuple = () if perms_list: final_identity = perms.get_highest_identity(perms_list) tenant_actions = p.keys( 'tenant_{0}_actions'.format(final_identity)) perms_tuple += tenant_actions else: final_identity = [] role_name_list = [ role_repo.get_role_name_by_role_id(role_id=role_id) for role_id in perms_role_id_list ] for role_id in perms_role_id_list: tenant_actions = role_perm_repo.get_perm_by_role_id( role_id=role_id) perms_tuple += tenant_actions if final_identity: tenant_info["role_name_list"] = [final_identity ] + role_name_list else: tenant_info["role_name_list"] = role_name_list user.actions.set_actions('tenant', tuple(set(perms_tuple))) tenant_info["tenant_actions"] = user.actions.tenant_actions tenant_list.append(tenant_info) user_detail["teams"] = tenant_list result = general_message(code, "Obtain my details to be successful.", "获取我的详情成功", bean=user_detail) except Exception as e: code = 500 logger.exception(e) result = error_message(e.message) return Response(result, status=code)