Browse Source

reenable endpoints for last_active and read_status

Guénaël Muller 5 years ago
parent
commit
81c0636f39

+ 14 - 0
tracim/lib/core/content.py View File

@@ -813,6 +813,7 @@ class ContentApi(object):
813 813
             workspace: Workspace=None,
814 814
             limit: typing.Optional[int]=None,
815 815
             before_datetime: typing.Optional[datetime.datetime]= None,
816
+            content_ids: typing.Optional[typing.List[int]] = None,
816 817
     ) -> typing.List[Content]:
817 818
         """
818 819
         get contents list sorted by last update
@@ -820,12 +821,25 @@ class ContentApi(object):
820 821
         :param workspace: Workspace to check
821 822
         :param limit: maximum number of elements to return
822 823
         :param before_datetime: date from where we check older content.
824
+        :param content_ids: restrict selection to some content ids and
825
+        related Comments
823 826
         :return: list of content
824 827
         """
825 828
 
826 829
         resultset = self._get_all_query(
827 830
             workspace=workspace,
828 831
         )
832
+        if content_ids:
833
+            resultset.filter(
834
+                or_(
835
+                    Content.content_id.in_(content_ids),
836
+                    and_(
837
+                        Content.parent_id.in_(content_ids),
838
+                        Content.type == ContentType.Comment
839
+                    )
840
+                )
841
+            )
842
+
829 843
         resultset = resultset.order_by(desc(Content.updated))
830 844
 
831 845
         active_contents = []

+ 18 - 0
tracim/models/context_models.py View File

@@ -102,6 +102,24 @@ class ContentFilter(object):
102 102
         self.content_type = content_type
103 103
 
104 104
 
105
+class ActiveContentFilter(object):
106
+    def __init__(
107
+            self,
108
+            limit: int = None,
109
+            before_datetime: datetime = None,
110
+    ):
111
+        self.limit = limit
112
+        self.before_datetime = before_datetime
113
+
114
+
115
+class ContentIdsQuery(object):
116
+    def __init__(
117
+            self,
118
+            contents_ids: typing.List[int] = None,
119
+    ):
120
+        self.contents_ids = contents_ids
121
+
122
+
105 123
 class ContentCreation(object):
106 124
     """
107 125
     Content creation model

+ 8 - 1
tracim/views/core_api/schemas.py View File

@@ -10,7 +10,8 @@ from tracim.models.contents import GlobalStatus
10 10
 from tracim.models.contents import open_status
11 11
 from tracim.models.contents import ContentTypeLegacy as ContentType
12 12
 from tracim.models.contents import ContentStatusLegacy as ContentStatus
13
-from tracim.models.context_models import ContentCreation
13
+from tracim.models.context_models import ContentCreation, ActiveContentFilter, \
14
+    ContentIdsQuery
14 15
 from tracim.models.context_models import UserWorkspacePath
15 16
 from tracim.models.context_models import UserWorkspaceAndContentPath
16 17
 from tracim.models.context_models import CommentCreation
@@ -207,6 +208,9 @@ class ActiveContentFilterQuerySchema(marshmallow.Schema):
207 208
         format=DATETIME_FORMAT,
208 209
         description='return only content lastly updated before this date',
209 210
     )
211
+    @post_load
212
+    def make_content_filter(self, data):
213
+        return ActiveContentFilter(**data)
210 214
 
211 215
 
212 216
 class ContentIdsQuerySchema(marshmallow.Schema):
@@ -216,6 +220,9 @@ class ContentIdsQuerySchema(marshmallow.Schema):
216 220
             validate=Range(min=1, error="Value must be greater than 0"),
217 221
         )
218 222
     )
223
+    @post_load
224
+    def make_contents_ids(self, data):
225
+        return ContentIdsQuery(**data)
219 226
 
220 227
 ###
221 228
 

+ 52 - 40
tracim/views/core_api/user_controller.py View File

@@ -51,61 +51,73 @@ class UserController(Controller):
51 51
 
52 52
     @hapic.with_api_doc(tags=[USER_ENDPOINTS_TAG])
53 53
     @require_same_user_or_profile(Group.TIM_ADMIN)
54
-    @hapic.input_path(UserIdPathSchema())
54
+    @hapic.input_path(UserWorkspaceIdPathSchema())
55 55
     @hapic.input_query(ActiveContentFilterQuerySchema())
56 56
     @hapic.output_body(ContentDigestSchema(many=True))
57 57
     def last_active_content(self, context, request: TracimRequest, hapic_data=None):  # nopep8
58 58
         """
59 59
         Get last_active_content for user
60 60
         """
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
-        # ]
61
+        app_config = request.registry.settings['CFG']
62
+        content_filter = hapic_data.query
63
+        api = ContentApi(
64
+            current_user=request.candidate_user,  # User
65
+            session=request.dbsession,
66
+            config=app_config,
67
+        )
68
+        wapi = WorkspaceApi(
69
+            current_user=request.candidate_user,  # User
70
+            session=request.dbsession,
71
+            config=app_config,
72
+        )
73
+        workspace = None
74
+        if hapic_data.path.workspace_id:
75
+            workspace = wapi.get_one(hapic_data.path.workspace_id)
76
+        last_actives = api.get_last_active(
77
+            workspace=workspace,
78
+            limit=content_filter.limit or None,
79
+            before_datetime=content_filter.before_datetime or None,
80
+        )
81
+        return [
82
+            api.get_content_in_context(content)
83
+            for content in last_actives
84
+        ]
91 85
 
92 86
     @hapic.with_api_doc(tags=[USER_ENDPOINTS_TAG])
93 87
     @require_same_user_or_profile(Group.TIM_ADMIN)
94
-    @hapic.input_path(UserWorkspaceAndContentIdPathSchema())
88
+    @hapic.input_path(UserWorkspaceIdPathSchema())
95 89
     @hapic.input_query(ContentIdsQuerySchema())
96 90
     @hapic.output_body(ReadStatusSchema(many=True))  # nopep8
97 91
     def contents_read_status(self, context, request: TracimRequest, hapic_data=None):  # nopep8
98 92
         """
99 93
         get user_read status of contents
100 94
         """
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)
95
+        app_config = request.registry.settings['CFG']
96
+        content_filter = hapic_data.query
97
+        api = ContentApi(
98
+            current_user=request.candidate_user,  # User
99
+            session=request.dbsession,
100
+            config=app_config,
101
+        )
102
+        wapi = WorkspaceApi(
103
+            current_user=request.candidate_user,  # User
104
+            session=request.dbsession,
105
+            config=app_config,
106
+        )
107
+        workspace = None
108
+        if hapic_data.path.workspace_id:
109
+            workspace = wapi.get_one(hapic_data.path.workspace_id)
110
+        last_actives = api.get_last_active(
111
+            workspace=workspace,
112
+            limit=None,
113
+            before_datetime=None,
114
+            content_ids=hapic_data.query.contents_ids or None
115
+        )
116
+        return [
117
+            api.get_content_in_context(content)
118
+            for content in last_actives
119
+        ]
120
+
109 121
 
110 122
     @hapic.with_api_doc(tags=[USER_ENDPOINTS_TAG])
111 123
     @require_same_user_or_profile(Group.TIM_ADMIN)