|
@@ -1,6 +1,6 @@
|
1
|
1
|
from pyramid.config import Configurator
|
2
|
|
-from sqlalchemy.orm.exc import NoResultFound
|
3
|
2
|
|
|
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
|
6
|
from tracim.models.context_models import WorkspaceInContext
|
|
@@ -12,13 +12,13 @@ except ImportError:
|
12
|
12
|
|
13
|
13
|
from tracim import hapic, TracimRequest
|
14
|
14
|
|
15
|
|
-from tracim.exceptions import NotAuthenticated
|
16
|
|
-from tracim.exceptions import InsufficientUserProfile
|
17
|
|
-from tracim.exceptions import UserDoesNotExist
|
18
|
15
|
from tracim.lib.core.workspace import WorkspaceApi
|
19
|
16
|
from tracim.views.controllers import Controller
|
20
|
17
|
from tracim.views.core_api.schemas import UserIdPathSchema
|
|
18
|
+from tracim.views.core_api.schemas import ContentDigestSchema
|
|
19
|
+from tracim.views.core_api.schemas import ExtendedFilterQuerySchema
|
21
|
20
|
from tracim.views.core_api.schemas import WorkspaceDigestSchema
|
|
21
|
+from tracim.models.contents import ContentTypeLegacy as ContentType
|
22
|
22
|
|
23
|
23
|
USER_ENDPOINTS_TAG = 'Users'
|
24
|
24
|
|
|
@@ -46,12 +46,50 @@ class UserController(Controller):
|
46
|
46
|
for workspace in workspaces
|
47
|
47
|
]
|
48
|
48
|
|
|
49
|
+ @hapic.with_api_doc(tags=[USER_ENDPOINTS_TAG])
|
|
50
|
+ @require_same_user_or_profile(Group.TIM_ADMIN)
|
|
51
|
+ @hapic.input_path(UserIdPathSchema())
|
|
52
|
+ @hapic.input_query(ExtendedFilterQuerySchema())
|
|
53
|
+ @hapic.output_body(ContentDigestSchema(many=True))
|
|
54
|
+ def last_active_content(self, context, request: TracimRequest, hapic_data=None): # nopep8
|
|
55
|
+ """
|
|
56
|
+ Get last_active_content for user
|
|
57
|
+ """
|
|
58
|
+ app_config = request.registry.settings['CFG']
|
|
59
|
+ api = ContentApi(
|
|
60
|
+ current_user=request.current_user, # User
|
|
61
|
+ session=request.dbsession,
|
|
62
|
+ config=app_config,
|
|
63
|
+ )
|
|
64
|
+ wapi = WorkspaceApi(
|
|
65
|
+ current_user=request.current_user, # User
|
|
66
|
+ session=request.dbsession,
|
|
67
|
+ config=app_config,
|
|
68
|
+ )
|
|
69
|
+ workspace = None
|
|
70
|
+ if 'workspace_id' in hapic_data.body:
|
|
71
|
+ workspace = wapi.get_one(hapic_data.body.workspace_id)
|
|
72
|
+ last_actives = api.get_last_active(
|
|
73
|
+ parent_id=hapic_data.body.parent_id,
|
|
74
|
+ content_type=hapic_data.body.content_type,
|
|
75
|
+ workspace=workspace,
|
|
76
|
+ offset=None,
|
|
77
|
+ limit=None,
|
|
78
|
+ )
|
|
79
|
+ return [
|
|
80
|
+ api.get_content_in_context(content) for content in last_actives
|
|
81
|
+ ]
|
|
82
|
+
|
49
|
83
|
def bind(self, configurator: Configurator) -> None:
|
50
|
84
|
"""
|
51
|
85
|
Create all routes and views using pyramid configurator
|
52
|
86
|
for this controller
|
53
|
87
|
"""
|
54
|
88
|
|
55
|
|
- # Applications
|
|
89
|
+ # user worskpace
|
56
|
90
|
configurator.add_route('user_workspace', '/users/{user_id}/workspaces', request_method='GET') # nopep8
|
57
|
91
|
configurator.add_view(self.user_workspace, route_name='user_workspace')
|
|
92
|
+
|
|
93
|
+ # last active content for user
|
|
94
|
+ configurator.add_route('last_active_content', '/users/{user_id}/contents/actives', request_method='GET') # nopep8
|
|
95
|
+ configurator.add_view(self.last_active_content, route_name='last_active_content') # nopep8
|