Kaynağa Gözat

somes simples fixs: doc, one import per line, exception_name, ...

Guénaël Muller 6 yıl önce
ebeveyn
işleme
1d428e83d3

+ 2 - 2
tracim/exceptions.py Dosyayı Görüntüle

117
     pass
117
     pass
118
 
118
 
119
 
119
 
120
-class NotSameWorkspace(TracimException):
121
-    pass
120
+class WorkspacesDoNotMatch(TracimException):
121
+    pass

+ 2 - 2
tracim/lib/core/content.py Dosyayı Görüntüle

25
 from tracim.lib.utils.utils import cmp_to_key
25
 from tracim.lib.utils.utils import cmp_to_key
26
 from tracim.lib.core.notifications import NotifierFactory
26
 from tracim.lib.core.notifications import NotifierFactory
27
 from tracim.exceptions import SameValueError
27
 from tracim.exceptions import SameValueError
28
-from tracim.exceptions import NotSameWorkspace
28
+from tracim.exceptions import WorkspacesDoNotMatch
29
 from tracim.lib.utils.utils import current_date_for_filename
29
 from tracim.lib.utils.utils import current_date_for_filename
30
 from tracim.models.revision_protection import new_revision
30
 from tracim.models.revision_protection import new_revision
31
 from tracim.models.auth import User
31
 from tracim.models.auth import User
878
             item.workspace = new_workspace
878
             item.workspace = new_workspace
879
             if new_parent and \
879
             if new_parent and \
880
                     new_parent.workspace_id != new_workspace.workspace_id:
880
                     new_parent.workspace_id != new_workspace.workspace_id:
881
-                raise NotSameWorkspace(
881
+                raise WorkspacesDoNotMatch(
882
                     'new parent workspace and new workspace should be the same.'
882
                     'new parent workspace and new workspace should be the same.'
883
                 )
883
                 )
884
         else:
884
         else:

+ 2 - 3
tracim/lib/utils/authorization.py Dosyayı Görüntüle

8
 except ImportError:  # python3.4
8
 except ImportError:  # python3.4
9
     JSONDecodeError = ValueError
9
     JSONDecodeError = ValueError
10
 
10
 
11
-from tracim.exceptions import InsufficientUserWorkspaceRole, \
12
-    InsufficientUserProfile, WorkspaceNotFoundInTracimRequest
13
-
11
+from tracim.exceptions import InsufficientUserWorkspaceRole
12
+from tracim.exceptions import InsufficientUserProfile
14
 if TYPE_CHECKING:
13
 if TYPE_CHECKING:
15
     from tracim import TracimRequest
14
     from tracim import TracimRequest
16
 ###
15
 ###

+ 5 - 6
tracim/lib/utils/request.py Dosyayı Görüntüle

2
 from pyramid.request import Request
2
 from pyramid.request import Request
3
 from sqlalchemy.orm.exc import NoResultFound
3
 from sqlalchemy.orm.exc import NoResultFound
4
 
4
 
5
-from tracim.exceptions import NotAuthenticated, WorkspaceNotFoundInTracimRequest
5
+from tracim.exceptions import NotAuthenticated
6
+from tracim.exceptions import WorkspaceNotFoundInTracimRequest
6
 from tracim.exceptions import UserNotFoundInTracimRequest
7
 from tracim.exceptions import UserNotFoundInTracimRequest
7
 from tracim.exceptions import UserDoesNotExist
8
 from tracim.exceptions import UserDoesNotExist
8
 from tracim.exceptions import WorkspaceNotFound
9
 from tracim.exceptions import WorkspaceNotFound
59
         :return: Workspace of the request
60
         :return: Workspace of the request
60
         """
61
         """
61
         if self._current_workspace is None:
62
         if self._current_workspace is None:
62
-            self.current_workspace = self._get_current_workspace(self.current_user, self)
63
+            self._current_workspace = self._get_current_workspace(self.current_user, self)
63
         return self._current_workspace
64
         return self._current_workspace
64
 
65
 
65
     @current_workspace.setter
66
     @current_workspace.setter
108
     @property
109
     @property
109
     def candidate_workspace(self) -> Workspace:
110
     def candidate_workspace(self) -> Workspace:
110
         """
111
         """
111
-        Get user from headers/body request. This user is not
112
-        the one found by authentication mecanism. This user
113
-        can help user to know about who one page is about in
114
-        a similar way as current_workspace.
112
+        Get workspace from headers/body request. This workspace is not
113
+        the one found from path. Its the one from json body.
115
         """
114
         """
116
         if self._candidate_workspace is None:
115
         if self._candidate_workspace is None:
117
             self._candidate_workspace = self._get_candidate_workspace(
116
             self._candidate_workspace = self._get_candidate_workspace(

+ 0 - 341
tracim/lib/utils/ttest Dosyayı Görüntüle

1
-
2
-definitions:
3
-  CommentSchema:
4
-    properties:
5
-      content_id:
6
-        example: 6
7
-        format: int32
8
-        type: integer
9
-      parent_id:
10
-        example: 34
11
-        format: int32
12
-        type: integer
13
-        x-nullable: true
14
-      content:
15
-        type: string
16
-        example: "Coucou !"
17
-      author:
18
-        $ref: '#/definitions/UserDigestSchema'
19
-  UserDigestSchema:
20
-    properties:
21
-      user_id:
22
-        example: 3
23
-        format: int32
24
-        readOnly: true
25
-        type: integer
26
-      avatar_url:
27
-        description: avatar_url is the url to the image file. If no avatar, then set
28
-          it to null (and frontend will interpret this with a default avatar)
29
-        example: /api/v2/assets/avatars/suri-cate.jpg
30
-        format: url
31
-        type: string
32
-        x-nullable: true
33
-      public_name:
34
-        example: Suri Cate
35
-        type: string
36
-  HtmlPageContentSchema:
37
-    properties:
38
-      content_type:
39
-        enum:
40
-        - thread
41
-        - file
42
-        - markdownpage
43
-        - page
44
-        - folder
45
-        example: htmlpage
46
-        type: string
47
-      content_id:
48
-        example: 6
49
-        format: int32
50
-        type: integer
51
-      is_archived:
52
-        example: false
53
-        type: boolean
54
-      is_deleted:
55
-        example: false
56
-        type: boolean
57
-      label:
58
-        example: Intervention Report 12
59
-        type: string
60
-      parent_id:
61
-        example: 34
62
-        format: int32
63
-        type: integer
64
-        x-nullable: true
65
-      show_in_ui:
66
-        description: if false, then do not show content in the treeview. This may
67
-          his maybe used for specific contents or for sub-contents. Default is True.
68
-          In first version of the API, this field is always True
69
-        example: true
70
-        type: boolean
71
-      slug:
72
-        example: intervention-report-12
73
-        type: string
74
-      status_slug:
75
-        description: this slug is found in content_type available statuses
76
-        enum:
77
-        - open
78
-        - closed-validated
79
-        - closed-unvalidated
80
-        - closed-deprecated
81
-        example: closed-deprecated
82
-        type: string
83
-      sub_content_types:
84
-        description: list of content types allowed as sub contents. This field is
85
-          required for folder contents, set it to empty list in other cases
86
-        items:
87
-          type: string
88
-        type: array
89
-      workspace_id:
90
-        example: 19
91
-        format: int32
92
-        type: integer
93
-      current_revision_id:
94
-        type: integer
95
-        example: 74
96
-      created:
97
-        format: date-time
98
-        type: string
99
-      author:
100
-        $ref: '#/definitions/UserDigestSchema'
101
-      modified:
102
-        format: date-time
103
-        type: string
104
-      last_modifier:
105
-        $ref: '#/definitions/UserDigestSchema'
106
-      content:
107
-        example: '<p> Coucou </p>'
108
-        type: string
109
-    type: object
110
-  HtmlPageRevisionSchema:
111
-    properties:
112
-      content_type:
113
-        enum:
114
-        - thread
115
-        - file
116
-        - markdownpage
117
-        - page
118
-        - folder
119
-        example: htmlpage
120
-        type: string
121
-      content_id:
122
-        example: 6
123
-        format: int32
124
-        type: integer
125
-      is_archived:
126
-        example: false
127
-        type: boolean
128
-      is_deleted:
129
-        example: false
130
-        type: boolean
131
-      label:
132
-        example: Intervention Report 12
133
-        type: string
134
-      parent_id:
135
-        example: 34
136
-        format: int32
137
-        type: integer
138
-        x-nullable: true
139
-      show_in_ui:
140
-        description: if false, then do not show content in the treeview. This may
141
-          his maybe used for specific contents or for sub-contents. Default is True.
142
-          In first version of the API, this field is always True
143
-        example: true
144
-        type: boolean
145
-      slug:
146
-        example: intervention-report-12
147
-        type: string
148
-      status_slug:
149
-        description: this slug is found in content_type available statuses
150
-        enum:
151
-        - open
152
-        - closed-validated
153
-        - closed-unvalidated
154
-        - closed-deprecated
155
-        example: closed-deprecated
156
-        type: string
157
-      sub_content_types:
158
-        description: list of content types allowed as sub contents. This field is
159
-          required for folder contents, set it to empty list in other cases
160
-        items:
161
-          type: string
162
-        type: array
163
-      workspace_id:
164
-        example: 19
165
-        format: int32
166
-        type: integer
167
-      revision_id:
168
-        type: integer
169
-        example: 74
170
-      created:
171
-        format: date-time
172
-        type: string
173
-      author:
174
-        $ref: '#/definitions/UserDigestSchema'
175
-      content:
176
-        example: '<p> Coucou </p>'
177
-        type: string
178
-    type: object
179
-  HtmlPageRevisionListSchema:
180
-    properties:
181
-      revisions:
182
-        type: array
183
-        items:
184
-          $ref: '#/definitions/HtmlPageRevisionSchema'
185
-      revision_nb:
186
-        type: integer
187
-        example: 40
188
-  HtmlPageModifySchema:
189
-    type: object
190
-    properties:
191
-      label:
192
-        example: "My Page"
193
-        type: string
194
-      content:
195
-        example: '<p> Coucou </p>'
196
-        type: string
197
-  ContentSetStatusSchema:
198
-    type: object
199
-    properties:
200
-      status:
201
-        example: "open-workinprogress"
202
-        type: string
203
-  NoContentSchema:
204
-    type: object
205
-info:
206
-  description: API of Tracim v2
207
-  title: Tracim v2 API
208
-  version: 1.0.0
209
-parameters: {}
210
-paths:
211
-  "/api/v2/workspaces/{workspace_id}/htmlpages/{htmlpage_id}":
212
-    get:
213
-      description: "get htmlpage content"
214
-      parameters:
215
-        - name: "workspace_id"
216
-          in: path
217
-          required: true
218
-          type: integer
219
-          description: id of the current workspace.
220
-        - name: "htmlpage_id"
221
-          in: path
222
-          required: true
223
-          type: integer
224
-          description: content id of htmlpage.
225
-      responses:
226
-        '200':
227
-          description: "nominal case"
228
-          schema:
229
-              $ref: '#/definitions/HtmlPageContentSchema'
230
-    put:
231
-      description: "modify htmlpage label or/and content"
232
-      parameters:
233
-        - in: body
234
-          name: "body"
235
-          schema:
236
-            $ref: '#/definitions/HtmlPageModifySchema'
237
-        - name: "workspace_id"
238
-          in: path
239
-          required: true
240
-          type: integer
241
-          description: id of the current workspace.
242
-        - name: "htmlpage_id"
243
-          in: path
244
-          required: true
245
-          type: integer
246
-          description: content id of htmlpage.
247
-      responses:
248
-        '200':
249
-          description: "nominal case"
250
-          schema:
251
-            $ref: '#/definitions/HtmlPageContentSchema'
252
-  "/api/v2/workspaces/{workspace_id}/htmlpages/{htmlpage_id}/revisions":
253
-    get:
254
-      description: "gets all htmlpages revisions (sorted by"
255
-      parameters:
256
-        - name: "workspace_id"
257
-          in: path
258
-          required: true
259
-          type: integer
260
-          description: id of the current workspace.
261
-        - name: "htmlpage_id"
262
-          in: path
263
-          required: true
264
-          type: integer
265
-          description: content id of htmlpage.
266
-      responses:
267
-        '200':
268
-          description: "nominal case"
269
-          schema:
270
-            $ref: '#/definitions/HtmlPageRevisionListSchema'
271
-  "/api/v2/workspaces/{workspace_id}/htmlpages/{htmlpage_id}/status":
272
-    put:
273
-      description: "set htmlpage content status"
274
-      parameters:
275
-        - in: body
276
-          name: "body"
277
-          schema:
278
-            $ref: '#/definitions/ContentSetStatusSchema'
279
-        - name: "workspace_id"
280
-          in: path
281
-          required: true
282
-          type: integer
283
-          description: id of the current workspace.
284
-        - name: "htmlpage_id"
285
-          in: path
286
-          required: true
287
-          type: integer
288
-          description: content id of htmlpage.
289
-      responses:
290
-        '200':
291
-          description: "nominal case"
292
-          schema:
293
-            $ref: '#/definitions/NoContentSchema'
294
-  "/api/v2/workspaces/{workspace_id}/contents/{content_id}/comments":
295
-    get:
296
-      description: "get all comments related to a content"
297
-      parameters:
298
-        - name: "workspace_id"
299
-          in: path
300
-          required: true
301
-          type: integer
302
-          description: id of the current workspace.
303
-        - name: "content_id"
304
-          in: path
305
-          required: true
306
-          type: integer
307
-          description: content id.
308
-      responses:
309
-        '200':
310
-          description: "nominal case"
311
-          schema:
312
-            type: array
313
-            items:
314
-              $ref: '#/definitions/CommentSchema'
315
-
316
-  "/api/v2/workspaces/{workspace_id}/contents/{content_id}/comments/{comments_id}":
317
-    delete:
318
-      description: "delete one comment"
319
-      parameters:
320
-        - name: "workspace_id"
321
-          in: path
322
-          required: true
323
-          type: integer
324
-          description: id of the current workspace.
325
-        - name: "content_id"
326
-          in: path
327
-          required: true
328
-          type: integer
329
-          description: content id.
330
-        - name: "comments_id"
331
-          in: path
332
-          required: true
333
-          type: integer
334
-          description: id of a comment related to content content_id.
335
-      responses:
336
-        '204':
337
-          description: "nominal case"
338
-          schema:
339
-            $ref: '#/definitions/NoContentSchema'
340
-swagger: '2.0'
341
-tags: []

+ 2 - 2
tracim/views/core_api/workspace_controller.py Dosyayı Görüntüle

19
 from tracim.models.context_models import ContentInContext
19
 from tracim.models.context_models import ContentInContext
20
 from tracim.exceptions import NotAuthenticated, InsufficientUserWorkspaceRole
20
 from tracim.exceptions import NotAuthenticated, InsufficientUserWorkspaceRole
21
 from tracim.exceptions import WorkspaceNotFoundInTracimRequest
21
 from tracim.exceptions import WorkspaceNotFoundInTracimRequest
22
-from tracim.exceptions import NotSameWorkspace
22
+from tracim.exceptions import WorkspacesDoNotMatch
23
 from tracim.exceptions import InsufficientUserProfile
23
 from tracim.exceptions import InsufficientUserProfile
24
 from tracim.exceptions import WorkspaceNotFound
24
 from tracim.exceptions import WorkspaceNotFound
25
 from tracim.views.controllers import Controller
25
 from tracim.views.controllers import Controller
163
     @hapic.handle_exception(InsufficientUserProfile, HTTPStatus.FORBIDDEN)
163
     @hapic.handle_exception(InsufficientUserProfile, HTTPStatus.FORBIDDEN)
164
     @hapic.handle_exception(WorkspaceNotFound, HTTPStatus.FORBIDDEN)
164
     @hapic.handle_exception(WorkspaceNotFound, HTTPStatus.FORBIDDEN)
165
     @hapic.handle_exception(InsufficientUserWorkspaceRole, HTTPStatus.FORBIDDEN)
165
     @hapic.handle_exception(InsufficientUserWorkspaceRole, HTTPStatus.FORBIDDEN)
166
-    @hapic.handle_exception(NotSameWorkspace, HTTPStatus.BAD_REQUEST)
166
+    @hapic.handle_exception(WorkspacesDoNotMatch, HTTPStatus.BAD_REQUEST)
167
     @require_workspace_role(UserRoleInWorkspace.CONTRIBUTOR)
167
     @require_workspace_role(UserRoleInWorkspace.CONTRIBUTOR)
168
     @require_candidate_workspace_role(UserRoleInWorkspace.CONTRIBUTOR)
168
     @require_candidate_workspace_role(UserRoleInWorkspace.CONTRIBUTOR)
169
     @hapic.input_path(WorkspaceAndContentIdPathSchema())
169
     @hapic.input_path(WorkspaceAndContentIdPathSchema())