Browse Source

follow specification and disable unworking functions

Guénaël Muller 6 years ago
parent
commit
2c1920fd0a
2 changed files with 66 additions and 63 deletions
  1. 15 16
      tracim/views/core_api/schemas.py
  2. 51 47
      tracim/views/core_api/user_controller.py

+ 15 - 16
tracim/views/core_api/schemas.py View File

@@ -195,7 +195,7 @@ class FilterContentQuerySchema(marshmallow.Schema):
195 195
         return ContentFilter(**data)
196 196
 
197 197
 
198
-class PaginationSchema(marshmallow.Schema):
198
+class ActiveContentFilterQuerySchema(marshmallow.Schema):
199 199
     limit = marshmallow.fields.Int(
200 200
         example=2,
201 201
         default=0,
@@ -203,23 +203,18 @@ class PaginationSchema(marshmallow.Schema):
203 203
                     'the first limit elem (according to offset)',
204 204
         validate=Range(min=0, error="Value must be positive or 0"),
205 205
     )
206
-    offset = marshmallow.fields.Int(
207
-        example=5,
208
-        default=0,
209
-        description='if 0 or not set, do not set offset, else set offset for'
210
-                    'query',
211
-        validate=Range(min=0, error="Value must be positive or 0"),
206
+    before_datetime = marshmallow.fields.DateTime(
207
+        format=DATETIME_FORMAT,
208
+        description='return only content lastly updated before this date',
212 209
     )
213 210
 
214 211
 
215
-class ExtendedFilterQuerySchema(FilterContentQuerySchema, PaginationSchema):
216
-    workspace_id = marshmallow.fields.Int(
217
-        example=2,
218
-        default=0,
219
-        description='allow to filter items in a workspace.'
220
-                    ' If not set,'
221
-                    'then return contents from all known workspace',
222
-        validate=Range(min=0, error="Value must be positive or 0"),
212
+class ContentIdsQuerySchema(marshmallow.Schema):
213
+    contents_ids = marshmallow.fields.List(
214
+        marshmallow.fields.Int(
215
+            example=6,
216
+            validate=Range(min=1, error="Value must be greater than 0"),
217
+        )
223 218
     )
224 219
 
225 220
 ###
@@ -479,7 +474,11 @@ class ContentDigestSchema(marshmallow.Schema):
479 474
     )
480 475
 
481 476
 
482
-class UserContentDigestSchema(ContentDigestSchema):
477
+class ReadStatusSchema(marshmallow.Schema):
478
+    content_id = marshmallow.fields.Int(
479
+        example=6,
480
+        validate=Range(min=1, error="Value must be greater than 0"),
481
+    )
483 482
     read_by_user = marshmallow.fields.Bool(example=False, default=False)
484 483
 #####
485 484
 # Content

+ 51 - 47
tracim/views/core_api/user_controller.py View File

@@ -13,12 +13,13 @@ from tracim import hapic, TracimRequest
13 13
 
14 14
 from tracim.lib.core.workspace import WorkspaceApi
15 15
 from tracim.views.controllers import Controller
16
-from tracim.views.core_api.schemas import UserIdPathSchema
16
+from tracim.views.core_api.schemas import UserIdPathSchema, ReadStatusSchema, \
17
+    ContentIdsQuerySchema
17 18
 from tracim.views.core_api.schemas import NoContentSchema
18 19
 from tracim.views.core_api.schemas import UserWorkspaceIdPathSchema
19 20
 from tracim.views.core_api.schemas import UserWorkspaceAndContentIdPathSchema
20
-from tracim.views.core_api.schemas import UserContentDigestSchema
21
-from tracim.views.core_api.schemas import ExtendedFilterQuerySchema
21
+from tracim.views.core_api.schemas import ContentDigestSchema
22
+from tracim.views.core_api.schemas import ActiveContentFilterQuerySchema
22 23
 from tracim.views.core_api.schemas import WorkspaceDigestSchema
23 24
 from tracim.models.contents import ContentTypeLegacy as ContentType
24 25
 
@@ -51,57 +52,60 @@ class UserController(Controller):
51 52
     @hapic.with_api_doc(tags=[USER_ENDPOINTS_TAG])
52 53
     @require_same_user_or_profile(Group.TIM_ADMIN)
53 54
     @hapic.input_path(UserIdPathSchema())
54
-    @hapic.input_query(ExtendedFilterQuerySchema())
55
-    @hapic.output_body(UserContentDigestSchema(many=True))
55
+    @hapic.input_query(ActiveContentFilterQuerySchema())
56
+    @hapic.output_body(ContentDigestSchema(many=True))
56 57
     def last_active_content(self, context, request: TracimRequest, hapic_data=None):  # nopep8
57 58
         """
58 59
         Get last_active_content for user
59 60
         """
60
-        app_config = request.registry.settings['CFG']
61
-        content_filter = hapic_data.query
62
-        api = ContentApi(
63
-            current_user=request.candidate_user,  # User
64
-            session=request.dbsession,
65
-            config=app_config,
66
-            show_archived=content_filter.show_archived,
67
-            show_deleted=content_filter.show_deleted,
68
-            show_active=content_filter.show_active,
69
-        )
70
-        wapi = WorkspaceApi(
71
-            current_user=request.candidate_user,  # User
72
-            session=request.dbsession,
73
-            config=app_config,
74
-        )
75
-        workspace = None
76
-        if content_filter.workspace_id:
77
-            workspace = wapi.get_one(content_filter.workspace_id)
78
-        last_actives = api.get_last_active(
79
-            parent_id=content_filter.parent_id,
80
-            content_type=content_filter.content_type or ContentType.Any,
81
-            workspace=workspace,
82
-            offset=content_filter.offset or None,
83
-            limit=content_filter.limit or None,
84
-        )
85
-        return [
86
-            api.get_content_in_context(content)
87
-            for content in last_actives
88
-        ]
61
+        raise NotImplemented()
62
+        # app_config = request.registry.settings['CFG']
63
+        # content_filter = hapic_data.query
64
+        # api = ContentApi(
65
+        #     current_user=request.candidate_user,  # User
66
+        #     session=request.dbsession,
67
+        #     config=app_config,
68
+        #     show_archived=content_filter.show_archived,
69
+        #     show_deleted=content_filter.show_deleted,
70
+        #     show_active=content_filter.show_active,
71
+        # )
72
+        # wapi = WorkspaceApi(
73
+        #     current_user=request.candidate_user,  # User
74
+        #     session=request.dbsession,
75
+        #     config=app_config,
76
+        # )
77
+        # workspace = None
78
+        # if content_filter.workspace_id:
79
+        #     workspace = wapi.get_one(content_filter.workspace_id)
80
+        # last_actives = api.get_last_active(
81
+        #     parent_id=content_filter.parent_id,
82
+        #     content_type=content_filter.content_type or ContentType.Any,
83
+        #     workspace=workspace,
84
+        #     offset=content_filter.offset or None,
85
+        #     limit=content_filter.limit or None,
86
+        # )
87
+        # return [
88
+        #     api.get_content_in_context(content)
89
+        #     for content in last_actives
90
+        # ]
89 91
 
90 92
     @hapic.with_api_doc(tags=[USER_ENDPOINTS_TAG])
91 93
     @require_same_user_or_profile(Group.TIM_ADMIN)
92 94
     @hapic.input_path(UserWorkspaceAndContentIdPathSchema())
93
-    @hapic.output_body(UserContentDigestSchema())  # nopep8
94
-    def user_content(self, context, request: TracimRequest, hapic_data=None):  # nopep8
95
+    @hapic.input_query(ContentIdsQuerySchema())
96
+    @hapic.output_body(ReadStatusSchema(many=True))  # nopep8
97
+    def contents_read_status(self, context, request: TracimRequest, hapic_data=None):  # nopep8
95 98
         """
96
-        set user_read status of content to unread
99
+        get user_read status of contents
97 100
         """
98
-        app_config = request.registry.settings['CFG']
99
-        api = ContentApi(
100
-            current_user=request.candidate_user,
101
-            session=request.dbsession,
102
-            config=app_config,
103
-        )
104
-        return api.get_content_in_context(request.current_content)
101
+        raise NotImplemented()
102
+        # app_config = request.registry.settings['CFG']
103
+        # api = ContentApi(
104
+        #     current_user=request.candidate_user,
105
+        #     session=request.dbsession,
106
+        #     config=app_config,
107
+        # )
108
+        # return api.get_content_in_context(request.current_content)
105 109
 
106 110
     @hapic.with_api_doc(tags=[USER_ENDPOINTS_TAG])
107 111
     @require_same_user_or_profile(Group.TIM_ADMIN)
@@ -165,10 +169,10 @@ class UserController(Controller):
165 169
         configurator.add_view(self.user_workspace, route_name='user_workspace')
166 170
 
167 171
         # user content
168
-        configurator.add_route('user_content', '/users/{user_id}/workspaces/{workspace_id}/contents/{content_id}', request_method='GET')  # nopep8
169
-        configurator.add_view(self.user_content, route_name='user_content')
172
+        configurator.add_route('contents_read_status', '/users/{user_id}/workspaces/{workspace_id}/contents/read_status', request_method='GET')  # nopep8
173
+        configurator.add_view(self.contents_read_status, route_name='contents_read_status')  # nopep8
170 174
         # last active content for user
171
-        configurator.add_route('last_active_content', '/users/{user_id}/contents/actives', request_method='GET')  # nopep8
175
+        configurator.add_route('last_active_content', '/users/{user_id}/workspaces/{workspace_id}/contents/recently_active', request_method='GET')  # nopep8
172 176
         configurator.add_view(self.last_active_content, route_name='last_active_content')  # nopep8
173 177
 
174 178
         # set content as read/unread