Browse Source

Better room naming : UUID + str convert method in utils

Guénaël Muller 6 years ago
parent
commit
e2a83bcbfe
2 changed files with 21 additions and 5 deletions
  1. 8 5
      tracim/tracim/controllers/jitsi_meet.py
  2. 13 0
      tracim/tracim/lib/utils.py

+ 8 - 5
tracim/tracim/controllers/jitsi_meet.py View File

@@ -6,7 +6,7 @@ from tg.predicates import not_anonymous
6 6
 from tracim.lib.predicates import current_user_is_reader
7 7
 from sqlalchemy.orm.exc import NoResultFound
8 8
 
9
-from unidecode import unidecode
9
+from tracim.lib.utils import str_as_alpha_num_str
10 10
 from tracim.lib.jitsi_meet.jitsi_meet import JitsiMeetRoom
11 11
 from tracim.lib.jitsi_meet.jitsi_meet import JitsiTokenConfig
12 12
 from tracim.config.app_cfg import CFG
@@ -41,12 +41,15 @@ class JitsiMeetController(TIMRestController):
41 41
         dictified_workspace = Context(CTX.WORKSPACE).toDict(workspace,
42 42
                                                             'workspace')
43 43
 
44
-        label = unidecode(workspace.label)
45
-        parsed_label = ''.join(e for e in label if e.isalnum())
46 44
         # TODO - G.M - 18-01-2017 -
47 45
         # allow to set specific room name from workspace object ?
48
-        room = "{id}{label}".format(id=workspace.workspace_id,
49
-                                    label=parsed_label)
46
+        room = "{uuid}{workspace_id}{workspace_label}".format(
47
+            uuid=cfg.TRACIM_INSTANCE_UUID,
48
+            workspace_id=workspace.workspace_id,
49
+            workspace_label=workspace.label)
50
+
51
+        # Jitsi-Meet doesn't like specials_characters
52
+        room = str_as_alpha_num_str(room)
50 53
 
51 54
         token = None
52 55
         if cfg.JITSI_MEET_USE_TOKEN:

+ 13 - 0
tracim/tracim/lib/utils.py View File

@@ -16,6 +16,7 @@ from tg.util import LazyString as BaseLazyString
16 16
 from tg.util import lazify
17 17
 from redis import Redis
18 18
 from rq import Queue
19
+from unidecode import unidecode
19 20
 
20 21
 from tracim.lib.base import logger
21 22
 from webob import Response
@@ -140,6 +141,18 @@ def str_as_bool(string: str) -> bool:
140 141
     return bool(string)
141 142
 
142 143
 
144
+def str_as_alpha_num_str(unicode_string: str) -> str:
145
+    """
146
+    convert unicode string to alpha_num-only string.
147
+    convert also accented character to ascii equivalent.
148
+    :param unicode_string:
149
+    :return:
150
+    """
151
+    ascii_string = unidecode(unicode_string)
152
+    alpha_num_string = ''.join(e for e in ascii_string if e.isalnum())
153
+    return alpha_num_string
154
+
155
+
143 156
 class LazyString(BaseLazyString):
144 157
     pass
145 158