Browse Source

jitsiMeet videoconf related to workspace

Guénaël Muller 6 years ago
parent
commit
0a3ca98786

+ 67 - 0
tracim/tracim/controllers/jitsi_meet.py View File

1
+import tg
2
+from tg import abort
3
+from tg import expose
4
+from tg import tmpl_context
5
+from tg.predicates import not_anonymous
6
+from tracim.lib.predicates import current_user_is_reader
7
+from sqlalchemy.orm.exc import NoResultFound
8
+
9
+from unidecode import unidecode
10
+from tracim.lib.jitsi_meet.jitsi_meet import JitsiMeetRoom
11
+from tracim.lib.jitsi_meet.jitsi_meet import JitsiTokenConfig
12
+from tracim.config.app_cfg import CFG
13
+
14
+from tracim.model.serializers import Context, CTX, DictLikeClass
15
+from tracim.controllers import TIMRestController, TIMRestPathContextSetup
16
+
17
+class JitsiMeetController(TIMRestController):
18
+
19
+    allow_only = not_anonymous()
20
+
21
+    def _before(self, *args, **kw):
22
+        TIMRestPathContextSetup.current_user()
23
+        try:
24
+            TIMRestPathContextSetup.current_workspace()
25
+        except NoResultFound:
26
+            abort(404)
27
+
28
+    @tg.require(current_user_is_reader())
29
+    @expose('tracim.templates.videoconf')
30
+    def get(self):
31
+        cfg = CFG.get_instance()
32
+        if not cfg.JITSI_MEET_ACTIVATED:
33
+            abort(404)
34
+        user = tmpl_context.current_user
35
+        workspace = tmpl_context.workspace
36
+        current_user_content = Context(CTX.CURRENT_USER).toDict(user)
37
+        fake_api = Context(CTX.CURRENT_USER).toDict(
38
+            {'current_user': current_user_content,
39
+             'workspace': workspace,
40
+             }
41
+        )
42
+        label = unidecode(workspace.label)
43
+        parsed_label = ''.join(e for e in label if e.isalnum())
44
+        # TODO - G.M - 18-01-2017 -
45
+        # allow to set specific room name from workspace object ?
46
+        room = "{id}{label}".format(id=workspace.workspace_id,
47
+                                    label=parsed_label)
48
+
49
+        token = None
50
+        if cfg.JITSI_MEET_USE_TOKEN:
51
+            if cfg.JITSI_MEET_TOKEN_GENERATOR == 'local':
52
+                token = JitsiTokenConfig(
53
+                    app_id=cfg.JITSI_MEET_TOKEN_GENERATOR_LOCAL_APP_ID,
54
+                    secret=cfg.JITSI_MEET_TOKEN_GENERATOR_LOCAL_SECRET,
55
+                    alg=cfg.JITSI_MEET_TOKEN_GENERATOR_LOCAL_ALG,
56
+                    duration=cfg.JITSI_MEET_TOKEN_GENERATOR_LOCAL_DURATION,
57
+                )
58
+            else:
59
+                abort(400)
60
+
61
+        jitsi_meet_room = JitsiMeetRoom(
62
+            room=room,
63
+            domain=cfg.JITSI_MEET_DOMAIN,
64
+            token_config=token)
65
+
66
+        return DictLikeClass(fake_api=fake_api,
67
+                             jitsi_meet_room=jitsi_meet_room)

+ 0 - 38
tracim/tracim/controllers/root.py View File

8
 from tg import require
8
 from tg import require
9
 from tg import tmpl_context
9
 from tg import tmpl_context
10
 from tg import url
10
 from tg import url
11
-from tg import abort
12
 from tg.i18n import ugettext as _
11
 from tg.i18n import ugettext as _
13
 
12
 
14
 from tracim.controllers import StandardController
13
 from tracim.controllers import StandardController
33
 from tracim.model.serializers import Context
32
 from tracim.model.serializers import Context
34
 from tracim.model.serializers import CTX
33
 from tracim.model.serializers import CTX
35
 from tracim.model.serializers import DictLikeClass
34
 from tracim.model.serializers import DictLikeClass
36
-from tracim.lib.jitsi_meet.jitsi_meet import JitsiMeetRoom
37
-from tracim.lib.jitsi_meet.jitsi_meet import JitsiTokenConfig
38
-from tracim.config.app_cfg import CFG
39
 
35
 
40
 class RootController(StandardController):
36
 class RootController(StandardController):
41
     """
37
     """
181
         search_results.keywords = keyword_list
177
         search_results.keywords = keyword_list
182
 
178
 
183
         return DictLikeClass(fake_api=fake_api, search=search_results)
179
         return DictLikeClass(fake_api=fake_api, search=search_results)
184
-
185
-    @require(predicates.not_anonymous())
186
-    @expose('tracim.templates.videoconf')
187
-    def videoconf(self):
188
-        cfg = CFG.get_instance()
189
-        if not cfg.JITSI_MEET_ACTIVATED:
190
-            abort(404)
191
-        user = tmpl_context.current_user
192
-        current_user_content = Context(CTX.CURRENT_USER).toDict(user)
193
-        fake_api = Context(CTX.CURRENT_USER).toDict(
194
-            {'current_user': current_user_content}
195
-        )
196
-
197
-        room = 'test'
198
-
199
-        token = None
200
-        if cfg.JITSI_MEET_USE_TOKEN:
201
-            if cfg.JITSI_MEET_TOKEN_GENERATOR == 'local':
202
-                token = JitsiTokenConfig(
203
-                    app_id=cfg.JITSI_MEET_TOKEN_GENERATOR_LOCAL_APP_ID,
204
-                    secret=cfg.JITSI_MEET_TOKEN_GENERATOR_LOCAL_SECRET,
205
-                    alg=cfg.JITSI_MEET_TOKEN_GENERATOR_LOCAL_ALG,
206
-                    duration=cfg.JITSI_MEET_TOKEN_GENERATOR_LOCAL_DURATION,
207
-                )
208
-            else:
209
-                abort(400)
210
-
211
-        jitsi_meet_room = JitsiMeetRoom(
212
-            room=room,
213
-            domain=cfg.JITSI_MEET_DOMAIN,
214
-            token_config=token)
215
-
216
-        return DictLikeClass(fake_api=fake_api,
217
-                             jitsi_meet_room=jitsi_meet_room)

+ 2 - 0
tracim/tracim/controllers/workspace.py View File

9
 
9
 
10
 from tracim.controllers import TIMRestController
10
 from tracim.controllers import TIMRestController
11
 from tracim.controllers.content import UserWorkspaceFolderRestController
11
 from tracim.controllers.content import UserWorkspaceFolderRestController
12
+from tracim.controllers.jitsi_meet import JitsiMeetController
12
 
13
 
13
 from tracim.lib.helpers import convert_id_into_instances
14
 from tracim.lib.helpers import convert_id_into_instances
14
 from tracim.lib.content import ContentApi
15
 from tracim.lib.content import ContentApi
28
     allow_only = not_anonymous()
29
     allow_only = not_anonymous()
29
 
30
 
30
     folders = UserWorkspaceFolderRestController()
31
     folders = UserWorkspaceFolderRestController()
32
+    videoconf = JitsiMeetController()
31
 
33
 
32
     @property
34
     @property
33
     def _base_url(self):
35
     def _base_url(self):