Browse Source

simplify profile info in user schema

Guénaël Muller 6 years ago
parent
commit
70ee0728fe

+ 1 - 1
tracim/models/context_models.py View File

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

+ 2 - 2
tracim/tests/functional/test_session.py View File

@@ -50,7 +50,7 @@ class TestLoginEndpoint(FunctionalTest):
50 50
         assert res.json_body['created']
51 51
         assert res.json_body['is_active']
52 52
         assert res.json_body['profile']
53
-        assert res.json_body['profile']['slug'] == 'administrators'
53
+        assert res.json_body['profile'] == 'administrators'
54 54
         assert res.json_body['caldav_url'] is None
55 55
         assert res.json_body['avatar_url'] is None
56 56
 
@@ -108,7 +108,7 @@ class TestWhoamiEndpoint(FunctionalTest):
108 108
         assert res.json_body['created']
109 109
         assert res.json_body['is_active']
110 110
         assert res.json_body['profile']
111
-        assert res.json_body['profile']['slug'] == 'administrators'
111
+        assert res.json_body['profile'] == 'administrators'
112 112
         assert res.json_body['caldav_url'] is None
113 113
         assert res.json_body['avatar_url'] is None
114 114
 

+ 1 - 1
tracim/tests/library/test_user_api.py View File

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

+ 4 - 14
tracim/views/core_api/schemas.py View File

@@ -16,17 +16,6 @@ from tracim.models.context_models import LoginCredentials
16 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 19
 class UserSchema(marshmallow.Schema):
31 20
 
32 21
     user_id = marshmallow.fields.Int(dump_only=True, example=3)
@@ -64,9 +53,10 @@ class UserSchema(marshmallow.Schema):
64 53
                     "If no avatar, then set it to null "
65 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 62
     class Meta: