Browse Source

Small controller for reply by mail event

Guénaël Muller 6 years ago
parent
commit
b209c37ffe
2 changed files with 31 additions and 1 deletions
  1. 29 0
      tracim/tracim/controllers/events.py
  2. 2 1
      tracim/tracim/controllers/root.py

+ 29 - 0
tracim/tracim/controllers/events.py View File

@@ -0,0 +1,29 @@
1
+import tg
2
+from tg import request
3
+from tg import RestController
4
+from tracim.lib.content import ContentApi
5
+from tracim.lib.user import UserApi
6
+from tracim.model.data import ContentType
7
+
8
+VALID_TOKEN_VALUE="djkflhqsfhyqsdb fq"
9
+
10
+class EventsRestController(RestController):
11
+
12
+
13
+    @tg.expose('json')
14
+    def post(self):
15
+        json = request.json_body
16
+        if 'token' in json and json['token'] == VALID_TOKEN_VALUE:
17
+            ## TODO check json content
18
+            uapi = UserApi(None)
19
+            ## TODO support Empty result error
20
+            user = uapi.get_one_by_email(json['user_mail'])
21
+            api = ContentApi(user)
22
+
23
+            thread = api.get_one(json['content_id'],content_type=ContentType.Any)
24
+            ## TODO Check type ? Commebt Not allowed for Folder
25
+            api.create_comment(thread.workspace, thread, json['payload']['content'], True)
26
+        else:
27
+            return {'status': 'error',
28
+                    'error': 'invalid token'}
29
+        return json

+ 2 - 1
tracim/tracim/controllers/root.py View File

@@ -22,6 +22,7 @@ from tracim.controllers.help import HelpController
22 22
 from tracim.controllers.previews import PreviewsController
23 23
 from tracim.controllers.user import UserRestController
24 24
 from tracim.controllers.workspace import UserWorkspaceRestController
25
+from tracim.controllers.events import EventsRestController
25 26
 from tracim.lib import CST
26 27
 from tracim.lib.base import logger
27 28
 from tracim.lib.content import ContentApi
@@ -61,7 +62,7 @@ class RootController(StandardController):
61 62
     previews = PreviewsController()
62 63
 
63 64
     content = ContentController()
64
-
65
+    events = EventsRestController()
65 66
     # api
66 67
     api = APIController()
67 68