Przeglądaj źródła

simplify profile info in user schema

Guénaël Muller 6 lat temu
rodzic
commit
70ee0728fe

+ 1 - 1
tracim/models/context_models.py Wyświetl plik

112
 
112
 
113
     @property
113
     @property
114
     def profile(self) -> Profile:
114
     def profile(self) -> Profile:
115
-        return self.user.profile
115
+        return self.user.profile.name
116
 
116
 
117
     # Context related
117
     # Context related
118
 
118
 

+ 2 - 2
tracim/tests/functional/test_session.py Wyświetl plik

50
         assert res.json_body['created']
50
         assert res.json_body['created']
51
         assert res.json_body['is_active']
51
         assert res.json_body['is_active']
52
         assert res.json_body['profile']
52
         assert res.json_body['profile']
53
-        assert res.json_body['profile']['slug'] == 'administrators'
53
+        assert res.json_body['profile'] == 'administrators'
54
         assert res.json_body['caldav_url'] is None
54
         assert res.json_body['caldav_url'] is None
55
         assert res.json_body['avatar_url'] is None
55
         assert res.json_body['avatar_url'] is None
56
 
56
 
108
         assert res.json_body['created']
108
         assert res.json_body['created']
109
         assert res.json_body['is_active']
109
         assert res.json_body['is_active']
110
         assert res.json_body['profile']
110
         assert res.json_body['profile']
111
-        assert res.json_body['profile']['slug'] == 'administrators'
111
+        assert res.json_body['profile'] == 'administrators'
112
         assert res.json_body['caldav_url'] is None
112
         assert res.json_body['caldav_url'] is None
113
         assert res.json_body['avatar_url'] is None
113
         assert res.json_body['avatar_url'] is None
114
 
114
 

+ 1 - 1
tracim/tests/library/test_user_api.py Wyświetl plik

131
         new_user = api.get_user_with_context(user)
131
         new_user = api.get_user_with_context(user)
132
         assert isinstance(new_user, UserInContext)
132
         assert isinstance(new_user, UserInContext)
133
         assert new_user.user == user
133
         assert new_user.user == user
134
-        assert new_user.profile.name == 'nobody'
134
+        assert new_user.profile == 'nobody'
135
         assert new_user.user_id == user.user_id
135
         assert new_user.user_id == user.user_id
136
         assert new_user.email == 'admin@tracim.tracim'
136
         assert new_user.email == 'admin@tracim.tracim'
137
         assert new_user.display_name == 'Admin'
137
         assert new_user.display_name == 'Admin'

+ 4 - 14
tracim/views/core_api/schemas.py Wyświetl plik

16
 from tracim.models.data import UserRoleInWorkspace
16
 from tracim.models.data import UserRoleInWorkspace
17
 
17
 
18
 
18
 
19
-class ProfileSchema(marshmallow.Schema):
20
-    slug = marshmallow.fields.String(
21
-        attribute='name',
22
-        validate=OneOf(Profile._NAME),
23
-        example='managers',
24
-    )
25
-
26
-    class Meta:
27
-        description = 'User Profile, give user right on whole Tracim instance.'
28
-
29
-
30
 class UserSchema(marshmallow.Schema):
19
 class UserSchema(marshmallow.Schema):
31
 
20
 
32
     user_id = marshmallow.fields.Int(dump_only=True, example=3)
21
     user_id = marshmallow.fields.Int(dump_only=True, example=3)
64
                     "If no avatar, then set it to null "
53
                     "If no avatar, then set it to null "
65
                     "(and frontend will interpret this with a default avatar)",
54
                     "(and frontend will interpret this with a default avatar)",
66
     )
55
     )
67
-    profile = marshmallow.fields.Nested(
68
-        ProfileSchema,
69
-        many=False,
56
+    profile = marshmallow.fields.String(
57
+        attribute='profile',
58
+        validate=OneOf(Profile._NAME),
59
+        example='managers',
70
     )
60
     )
71
 
61
 
72
     class Meta:
62
     class Meta: