MCPcopy Index your code
hub / github.com/1Panel-dev/MaxKB / UserProfileSerializer

Class UserProfileSerializer

apps/users/serializers/user.py:117–151  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

115
116
117class UserProfileSerializer(serializers.Serializer):
118 @staticmethod
119 def profile(user: User, auth: Auth):
120 """
121 获取用户详情
122 @param user: 用户对象
123 @param auth: 认证对象
124 @return:
125 """
126 workspace_list = get_workspace_list_by_user(user.id)
127 user_role_relation_model = DatabaseModelManage.get_model("workspace_user_role_mapping")
128 role_name = [user.role]
129 if user_role_relation_model:
130 user_role_relations = (
131 user_role_relation_model.objects
132 .filter(user_id=user.id)
133 .select_related('role')
134 .distinct('role_id')
135 )
136 role_name = [relation.role.role_name for relation in user_role_relations]
137
138 return {
139 'id': user.id,
140 'username': user.username,
141 'nick_name': user.nick_name,
142 'email': user.email,
143 'source': user.source,
144 'role': auth.role_list,
145 'permissions': auth.permission_list,
146 'is_edit_password': password_verify(CONFIG.get('DEFAULT_PASSWORD', 'MaxKB@123..'),
147 user.password) if user.source == 'LOCAL' else False,
148 'language': user.language,
149 'workspace_list': workspace_list,
150 'role_name': role_name
151 }
152
153
154class UserInstanceSerializer(serializers.ModelSerializer):

Callers 3

getMethod · 0.90
getMethod · 0.90
getMethod · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected