|
@@ -3,7 +3,6 @@ from pyramid.config import Configurator
|
3
|
3
|
from tracim.lib.core.content import ContentApi
|
4
|
4
|
from tracim.lib.utils.authorization import require_same_user_or_profile
|
5
|
5
|
from tracim.models import Group
|
6
|
|
-from tracim.models.context_models import WorkspaceInContext
|
7
|
6
|
|
8
|
7
|
try:
|
9
|
8
|
from http import HTTPStatus
|
|
@@ -15,6 +14,9 @@ from tracim import hapic, TracimRequest
|
15
|
14
|
from tracim.lib.core.workspace import WorkspaceApi
|
16
|
15
|
from tracim.views.controllers import Controller
|
17
|
16
|
from tracim.views.core_api.schemas import UserIdPathSchema
|
|
17
|
+from tracim.views.core_api.schemas import NoContentSchema
|
|
18
|
+from tracim.views.core_api.schemas import UserWorkspaceIdPathSchema
|
|
19
|
+from tracim.views.core_api.schemas import UserWorkspaceAndContentIdPathSchema
|
18
|
20
|
from tracim.views.core_api.schemas import UserContentDigestSchema
|
19
|
21
|
from tracim.views.core_api.schemas import ExtendedFilterQuerySchema
|
20
|
22
|
from tracim.views.core_api.schemas import WorkspaceDigestSchema
|
|
@@ -35,7 +37,7 @@ class UserController(Controller):
|
35
|
37
|
"""
|
36
|
38
|
app_config = request.registry.settings['CFG']
|
37
|
39
|
wapi = WorkspaceApi(
|
38
|
|
- current_user=request.current_user,
|
|
40
|
+ current_user=request.candidate_user,
|
39
|
41
|
session=request.dbsession,
|
40
|
42
|
config=app_config,
|
41
|
43
|
)
|
|
@@ -58,7 +60,7 @@ class UserController(Controller):
|
58
|
60
|
app_config = request.registry.settings['CFG']
|
59
|
61
|
content_filter = hapic_data.query
|
60
|
62
|
api = ContentApi(
|
61
|
|
- current_user=request.current_user,
|
|
63
|
+ current_user=request.candidate_user,
|
62
|
64
|
session=request.dbsession,
|
63
|
65
|
config=app_config,
|
64
|
66
|
show_archived=content_filter.show_archived,
|
|
@@ -66,7 +68,7 @@ class UserController(Controller):
|
66
|
68
|
show_active=content_filter.show_active,
|
67
|
69
|
)
|
68
|
70
|
wapi = WorkspaceApi(
|
69
|
|
- current_user=request.current_user,
|
|
71
|
+ current_user=request.candidate_user,
|
70
|
72
|
session=request.dbsession,
|
71
|
73
|
config=app_config,
|
72
|
74
|
)
|
|
@@ -85,6 +87,57 @@ class UserController(Controller):
|
85
|
87
|
for content in last_actives
|
86
|
88
|
]
|
87
|
89
|
|
|
90
|
+ @hapic.with_api_doc(tags=[USER_ENDPOINTS_TAG])
|
|
91
|
+ @require_same_user_or_profile(Group.TIM_ADMIN)
|
|
92
|
+ @hapic.input_path(UserWorkspaceAndContentIdPathSchema())
|
|
93
|
+ @hapic.output_body(NoContentSchema(), default_http_code=HTTPStatus.NO_CONTENT)
|
|
94
|
+ def set_content_as_read(self, context, request: TracimRequest, hapic_data=None):
|
|
95
|
+ """
|
|
96
|
+ set user_read status of content to read
|
|
97
|
+ """
|
|
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
|
+ api.mark_read(request.current_content, do_flush=True)
|
|
105
|
+ return
|
|
106
|
+
|
|
107
|
+ @hapic.with_api_doc(tags=[USER_ENDPOINTS_TAG])
|
|
108
|
+ @require_same_user_or_profile(Group.TIM_ADMIN)
|
|
109
|
+ @hapic.input_path(UserWorkspaceAndContentIdPathSchema())
|
|
110
|
+ @hapic.output_body(NoContentSchema(), default_http_code=HTTPStatus.NO_CONTENT)
|
|
111
|
+ def set_content_as_unread(self, context, request: TracimRequest, hapic_data=None):
|
|
112
|
+ """
|
|
113
|
+ set user_read status of content to unread
|
|
114
|
+ """
|
|
115
|
+ app_config = request.registry.settings['CFG']
|
|
116
|
+ api = ContentApi(
|
|
117
|
+ current_user=request.candidate_user,
|
|
118
|
+ session=request.dbsession,
|
|
119
|
+ config=app_config,
|
|
120
|
+ )
|
|
121
|
+ api.mark_unread(request.current_content, do_flush=True)
|
|
122
|
+ return
|
|
123
|
+
|
|
124
|
+ @hapic.with_api_doc(tags=[USER_ENDPOINTS_TAG])
|
|
125
|
+ @require_same_user_or_profile(Group.TIM_ADMIN)
|
|
126
|
+ @hapic.input_path(UserWorkspaceIdPathSchema())
|
|
127
|
+ @hapic.output_body(NoContentSchema(), default_http_code=HTTPStatus.NO_CONTENT)
|
|
128
|
+ def set_workspace_as_read(self, context, request: TracimRequest, hapic_data=None):
|
|
129
|
+ """
|
|
130
|
+ set user_read status of all content of workspace to read
|
|
131
|
+ """
|
|
132
|
+ app_config = request.registry.settings['CFG']
|
|
133
|
+ api = ContentApi(
|
|
134
|
+ current_user=request.candidate_user,
|
|
135
|
+ session=request.dbsession,
|
|
136
|
+ config=app_config,
|
|
137
|
+ )
|
|
138
|
+ api.mark_read__workspace(request.current_workspace)
|
|
139
|
+ return
|
|
140
|
+
|
88
|
141
|
def bind(self, configurator: Configurator) -> None:
|
89
|
142
|
"""
|
90
|
143
|
Create all routes and views using pyramid configurator
|
|
@@ -98,3 +151,13 @@ class UserController(Controller):
|
98
|
151
|
|
99
|
152
|
configurator.add_route('last_active_content', '/users/{user_id}/contents/actives', request_method='GET')
|
100
|
153
|
configurator.add_view(self.last_active_content, route_name='last_active_content')
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+ configurator.add_route('read_content', '/users/{user_id}/workspaces/{workspace_id}/contents/{content_id}/read', request_method='PUT')
|
|
157
|
+ configurator.add_view(self.set_content_as_read, route_name='read_content')
|
|
158
|
+ configurator.add_route('unread_content', '/users/{user_id}/workspaces/{workspace_id}/contents/{content_id}/unread', request_method='PUT')
|
|
159
|
+ configurator.add_view(self.set_content_as_unread, route_name='unread_content')
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+ configurator.add_route('read_workspace', '/users/{user_id}/workspaces/{workspace_id}/read', request_method='PUT')
|
|
163
|
+ configurator.add_view(self.set_workspace_as_read, route_name='read_workspace')
|