Selaa lähdekoodia

Small controller for reply by mail event

Guénaël Muller 8 vuotta sitten
vanhempi
commit
b209c37ffe
2 muutettua tiedostoa jossa 31 lisäystä ja 1 poistoa
  1. 29 0
      tracim/tracim/controllers/events.py
  2. 2 1
      tracim/tracim/controllers/root.py

+ 29 - 0
tracim/tracim/controllers/events.py Näytä tiedosto

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 Näytä tiedosto

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