浏览代码

remove uneeded id of profil/role + better schema with description/example

Guénaël Muller 6 年前
父节点
当前提交
16284fd784
共有 3 个文件被更改,包括 115 次插入37 次删除
  1. 0 2
      tracim/tests/functional/test_session.py
  2. 0 1
      tracim/tests/functional/test_workspaces.py
  3. 115 34
      tracim/views/core_api/schemas.py

+ 0 - 2
tracim/tests/functional/test_session.py 查看文件

52
         assert res.json_body['created']
52
         assert res.json_body['created']
53
         assert res.json_body['is_active']
53
         assert res.json_body['is_active']
54
         assert res.json_body['profile']
54
         assert res.json_body['profile']
55
-        assert isinstance(res.json_body['profile']['id'], int)
56
         assert res.json_body['profile']['slug'] == 'administrators'
55
         assert res.json_body['profile']['slug'] == 'administrators'
57
         assert res.json_body['caldav_url'] is None
56
         assert res.json_body['caldav_url'] is None
58
         assert res.json_body['avatar_url'] is None
57
         assert res.json_body['avatar_url'] is None
111
         assert res.json_body['created']
110
         assert res.json_body['created']
112
         assert res.json_body['is_active']
111
         assert res.json_body['is_active']
113
         assert res.json_body['profile']
112
         assert res.json_body['profile']
114
-        assert isinstance(res.json_body['profile']['id'], int)
115
         assert res.json_body['profile']['slug'] == 'administrators'
113
         assert res.json_body['profile']['slug'] == 'administrators'
116
         assert res.json_body['caldav_url'] is None
114
         assert res.json_body['caldav_url'] is None
117
         assert res.json_body['avatar_url'] is None
115
         assert res.json_body['avatar_url'] is None

+ 0 - 1
tracim/tests/functional/test_workspaces.py 查看文件

156
         assert len(res) == 2
156
         assert len(res) == 2
157
         user_role = res[0]
157
         user_role = res[0]
158
         assert user_role['role_slug'] == 'workspace_manager'
158
         assert user_role['role_slug'] == 'workspace_manager'
159
-        assert user_role['role_id'] == 8
160
         assert user_role['user_id'] == 1
159
         assert user_role['user_id'] == 1
161
         assert user_role['workspace_id'] == 1
160
         assert user_role['workspace_id'] == 1
162
         assert user_role['user']['display_name'] == 'Global manager'
161
         assert user_role['user']['display_name'] == 'Global manager'

+ 115 - 34
tracim/views/core_api/schemas.py 查看文件

9
 
9
 
10
 
10
 
11
 class ProfileSchema(marshmallow.Schema):
11
 class ProfileSchema(marshmallow.Schema):
12
-    id = marshmallow.fields.Int(dump_only=True, validate=OneOf(Profile._IDS))
13
-    slug = marshmallow.fields.String(attribute='name', validate=OneOf(Profile._NAME))
12
+    slug = marshmallow.fields.String(
13
+        attribute='name',
14
+        validate=OneOf(Profile._NAME),
15
+        example='managers',
16
+    )
17
+
18
+    class Meta:
19
+        description = 'User Profile, give user right on whole Tracim instance.'
14
 
20
 
15
 
21
 
16
 class UserSchema(marshmallow.Schema):
22
 class UserSchema(marshmallow.Schema):
17
 
23
 
18
-    user_id = marshmallow.fields.Int(dump_only=True)
19
-    email = marshmallow.fields.Email(required=True)
20
-    display_name = marshmallow.fields.String()
21
-    created = marshmallow.fields.DateTime(format='iso8601')
22
-    is_active = marshmallow.fields.Bool()
24
+    user_id = marshmallow.fields.Int(dump_only=True, example=3)
25
+    email = marshmallow.fields.Email(
26
+        required=True,
27
+        example='suri.cate@algoo.fr'
28
+    )
29
+    display_name = marshmallow.fields.String(
30
+        example='Suri Cate',
31
+    )
32
+    created = marshmallow.fields.DateTime(
33
+        format='iso8601',
34
+        description='User account creation date (iso8601 format).',
35
+    )
36
+    is_active = marshmallow.fields.Bool(
37
+        example=True,
38
+         # TODO - G.M - Explains this value.
39
+    )
23
     # TODO - G.M - 17-04-2018 - Restrict timezone values
40
     # TODO - G.M - 17-04-2018 - Restrict timezone values
24
-    timezone = marshmallow.fields.String()
41
+    timezone = marshmallow.fields.String(
42
+        example="Paris/Europe",
43
+    )
25
     # TODO - G.M - 17-04-2018 - check this, relative url allowed ?
44
     # TODO - G.M - 17-04-2018 - check this, relative url allowed ?
26
     caldav_url = marshmallow.fields.Url(
45
     caldav_url = marshmallow.fields.Url(
27
         allow_none=True,
46
         allow_none=True,
28
         relative=True,
47
         relative=True,
29
-        attribute='calendar_url'
48
+        attribute='calendar_url',
49
+        example="/api/v2/calendar/user/3.ics/",
50
+        description="The url for calendar CalDAV direct access",
51
+    )
52
+    avatar_url = marshmallow.fields.Url(
53
+        allow_none=True,
54
+        example="/api/v2/assets/avatars/suri-cate.jpg",
55
+        description="avatar_url is the url to the image file. "
56
+                    "If no avatar, then set it to null "
57
+                    "(and frontend will interpret this with a default avatar)",
30
     )
58
     )
31
-    avatar_url = marshmallow.fields.Url(allow_none=True)
32
     profile = marshmallow.fields.Nested(
59
     profile = marshmallow.fields.Nested(
33
         ProfileSchema,
60
         ProfileSchema,
34
         many=False,
61
         many=False,
35
     )
62
     )
36
 
63
 
64
+    class Meta:
65
+        description = 'User account of Tracim'
66
+
37
 
67
 
38
 class UserIdPathSchema(marshmallow.Schema):
68
 class UserIdPathSchema(marshmallow.Schema):
39
-    user_id = marshmallow.fields.Int()
69
+    user_id = marshmallow.fields.Int(example=3)
40
 
70
 
41
 
71
 
42
 class WorkspaceIdPathSchema(marshmallow.Schema):
72
 class WorkspaceIdPathSchema(marshmallow.Schema):
43
-    workspace_id = marshmallow.fields.Int()
73
+    workspace_id = marshmallow.fields.Int(example=4)
44
 
74
 
45
 
75
 
46
 class BasicAuthSchema(marshmallow.Schema):
76
 class BasicAuthSchema(marshmallow.Schema):
47
 
77
 
48
-    email = marshmallow.fields.Email(required=True)
49
-    password = marshmallow.fields.String(required=True, load_only=True)
78
+    email = marshmallow.fields.Email(
79
+        example='suri.cate@algoo.fr',
80
+        required=True
81
+    )
82
+    password = marshmallow.fields.String(
83
+        example='8QLa$<w',
84
+        required=True,
85
+        load_only=True,
86
+    )
87
+
88
+    class Meta:
89
+        description = 'Entry for HTTP Basic Auth'
50
 
90
 
51
     @post_load
91
     @post_load
52
     def make_login(self, data):
92
     def make_login(self, data):
58
 
98
 
59
 
99
 
60
 class NoContentSchema(marshmallow.Schema):
100
 class NoContentSchema(marshmallow.Schema):
101
+
102
+    class Meta:
103
+        description = 'Empty Schema'
61
     pass
104
     pass
62
 
105
 
63
 
106
 
64
 class WorkspaceMenuEntrySchema(marshmallow.Schema):
107
 class WorkspaceMenuEntrySchema(marshmallow.Schema):
65
-    slug = marshmallow.fields.String()
66
-    label = marshmallow.fields.String()
67
-    route = marshmallow.fields.String()
68
-    hexcolor = marshmallow.fields.String()
69
-    icon = marshmallow.fields.String()
108
+    slug = marshmallow.fields.String(example='markdown-pages')
109
+    label = marshmallow.fields.String(example='Markdown Documents')
110
+    route = marshmallow.fields.String(
111
+        example='/#/workspace/{workspace_id}/contents/?type=mardown-page',
112
+        description='the route is the frontend route. '
113
+                    'It may include workspace_id '
114
+                    'which must be replaced on backend size '
115
+                    '(the route must be ready-to-use)'
116
+    )
117
+    icon = marshmallow.fields.String(
118
+        example='file-text-o',
119
+        description='CSS class of the icon. Example: file-o for using Fontawesome file-text-o icon',  # nopep8
120
+    )
121
+    hexcolor = marshmallow.fields.String(
122
+        example='#F0F9DC',
123
+        description='Hexadecimal color of the entry.'
124
+    )
125
+
126
+    class Meta:
127
+        description = 'Entry element of a workspace menu'
70
 
128
 
71
 
129
 
72
 class WorkspaceSchema(marshmallow.Schema):
130
 class WorkspaceSchema(marshmallow.Schema):
73
-    id = marshmallow.fields.Int()
74
-    slug = marshmallow.fields.String()
75
-    label = marshmallow.fields.String()
76
-    description = marshmallow.fields.String()
131
+    id = marshmallow.fields.Int(example=4)
132
+    slug = marshmallow.fields.String(example='intranet')
133
+    label = marshmallow.fields.String(example='Intranet')
134
+    description = marshmallow.fields.String(example='All intranet data.')
77
     sidebar_entries = marshmallow.fields.Nested(
135
     sidebar_entries = marshmallow.fields.Nested(
78
         WorkspaceMenuEntrySchema,
136
         WorkspaceMenuEntrySchema,
79
         many=True,
137
         many=True,
80
     )
138
     )
81
 
139
 
140
+    class Meta:
141
+        description = 'Full workspace informations'
142
+
82
 
143
 
83
 class WorkspaceDigestSchema(marshmallow.Schema):
144
 class WorkspaceDigestSchema(marshmallow.Schema):
84
-    id = marshmallow.fields.Int()
85
-    label = marshmallow.fields.String()
145
+    id = marshmallow.fields.Int(example=4)
146
+    label = marshmallow.fields.String(example='Intranet')
86
     sidebar_entries = marshmallow.fields.Nested(
147
     sidebar_entries = marshmallow.fields.Nested(
87
         WorkspaceMenuEntrySchema,
148
         WorkspaceMenuEntrySchema,
88
         many=True,
149
         many=True,
89
     )
150
     )
90
 
151
 
152
+    class Meta:
153
+        description = 'Digest of workspace informations'
154
+
91
 
155
 
92
 class WorkspaceMemberSchema(marshmallow.Schema):
156
 class WorkspaceMemberSchema(marshmallow.Schema):
93
-    role_id = marshmallow.fields.Int(validate=OneOf(UserRoleInWorkspace.get_all_role_values()))  # nopep8
94
-    role_slug = marshmallow.fields.String(validate=OneOf(UserRoleInWorkspace.get_all_role_slug()))  # nopep8
95
-    user_id = marshmallow.fields.Int()
96
-    workspace_id = marshmallow.fields.Int()
157
+    role_slug = marshmallow.fields.String(
158
+        example='contributor',
159
+        validate=OneOf(UserRoleInWorkspace.get_all_role_slug())
160
+    )
161
+    user_id = marshmallow.fields.Int(example=3)
162
+    workspace_id = marshmallow.fields.Int(example=4)
97
     user = marshmallow.fields.Nested(
163
     user = marshmallow.fields.Nested(
98
         UserSchema(only=('display_name', 'avatar_url'))
164
         UserSchema(only=('display_name', 'avatar_url'))
99
     )
165
     )
100
 
166
 
167
+    class Meta:
168
+        description = 'Workspace Member information'
169
+
101
 
170
 
102
 class ApplicationConfigSchema(marshmallow.Schema):
171
 class ApplicationConfigSchema(marshmallow.Schema):
103
     pass
172
     pass
105
 
174
 
106
 
175
 
107
 class ApplicationSchema(marshmallow.Schema):
176
 class ApplicationSchema(marshmallow.Schema):
108
-    label = marshmallow.fields.String()
109
-    slug = marshmallow.fields.String()
110
-    icon = marshmallow.fields.String()
111
-    hexcolor = marshmallow.fields.String()
112
-    is_active = marshmallow.fields.Boolean()
177
+    label = marshmallow.fields.String(example='Calendar')
178
+    slug = marshmallow.fields.String(example='calendar')
179
+    icon = marshmallow.fields.String(
180
+        example='file-o',
181
+        description='CSS class of the icon. Example: file-o for using Fontawesome file-o icon',  # nopep8
182
+    )
183
+    hexcolor = marshmallow.fields.String(
184
+        example='#FF0000',
185
+        description='HTML encoded color associated to the application. Example:#FF0000 for red'  # nopep8
186
+    )
187
+    is_active = marshmallow.fields.Boolean(
188
+        example=True,
189
+        description='if true, the application is in use in the context',
190
+    )
113
     config = marshmallow.fields.Nested(
191
     config = marshmallow.fields.Nested(
114
         ApplicationConfigSchema,
192
         ApplicationConfigSchema,
115
     )
193
     )
194
+
195
+    class Meta:
196
+        description = 'Tracim Application informations'