Browse Source

add read_by_user in last active content endpoint

Guénaël Muller 6 years ago
parent
commit
8e5c454379

+ 1 - 1
tracim/lib/core/content.py View File

@@ -163,7 +163,7 @@ class ContentApi(object):
163 163
             self._show_temporary = previous_show_temporary
164 164
 
165 165
     def get_content_in_context(self, content: Content) -> ContentInContext:
166
-        return ContentInContext(content, self._session, self._config)
166
+        return ContentInContext(content, self._session, self._config, self._user)  # nopep8
167 167
 
168 168
     def get_revision_in_context(self, revision: ContentRevisionRO) -> RevisionInContext:  # nopep8
169 169
         # TODO - G.M - 2018-06-173 - create revision in context object

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

@@ -335,10 +335,11 @@ class ContentInContext(object):
335 335
     Interface to get Content data and Content data related to context.
336 336
     """
337 337
 
338
-    def __init__(self, content: Content, dbsession: Session, config: CFG):
338
+    def __init__(self, content: Content, dbsession: Session, config: CFG, user: User=None):  # nopep8
339 339
         self.content = content
340 340
         self.dbsession = dbsession
341 341
         self.config = config
342
+        self._user = user
342 343
 
343 344
     # Default
344 345
     @property
@@ -431,6 +432,11 @@ class ContentInContext(object):
431 432
     def slug(self):
432 433
         return slugify(self.content.label)
433 434
 
435
+    @property
436
+    def read_by_user(self):
437
+        assert self._user
438
+        return self.content.has_new_information_for(self._user)
439
+
434 440
 
435 441
 class RevisionInContext(object):
436 442
     """

+ 2 - 0
tracim/views/core_api/schemas.py View File

@@ -458,6 +458,8 @@ class ContentDigestSchema(marshmallow.Schema):
458 458
     )
459 459
 
460 460
 
461
+class UserContentDigestSchema(ContentDigestSchema):
462
+    read_by_user = marshmallow.fields.Bool(example=False, default=False)
461 463
 #####
462 464
 # Content
463 465
 #####

+ 4 - 3
tracim/views/core_api/user_controller.py View File

@@ -15,7 +15,7 @@ from tracim import hapic, TracimRequest
15 15
 from tracim.lib.core.workspace import WorkspaceApi
16 16
 from tracim.views.controllers import Controller
17 17
 from tracim.views.core_api.schemas import UserIdPathSchema
18
-from tracim.views.core_api.schemas import ContentDigestSchema
18
+from tracim.views.core_api.schemas import UserContentDigestSchema
19 19
 from tracim.views.core_api.schemas import ExtendedFilterQuerySchema
20 20
 from tracim.views.core_api.schemas import WorkspaceDigestSchema
21 21
 from tracim.models.contents import ContentTypeLegacy as ContentType
@@ -50,7 +50,7 @@ class UserController(Controller):
50 50
     @require_same_user_or_profile(Group.TIM_ADMIN)
51 51
     @hapic.input_path(UserIdPathSchema())
52 52
     @hapic.input_query(ExtendedFilterQuerySchema())
53
-    @hapic.output_body(ContentDigestSchema(many=True))
53
+    @hapic.output_body(UserContentDigestSchema(many=True))
54 54
     def last_active_content(self, context, request: TracimRequest, hapic_data=None):  # nopep8
55 55
         """
56 56
         Get last_active_content for user
@@ -81,7 +81,8 @@ class UserController(Controller):
81 81
             limit=content_filter.limit or None,
82 82
         )
83 83
         return [
84
-            api.get_content_in_context(content) for content in last_actives
84
+            api.get_content_in_context(content)
85
+            for content in last_actives
85 86
         ]
86 87
 
87 88
     def bind(self, configurator: Configurator) -> None: