Browse Source

Renaming + Comment + small refactor

Guénaël Muller 6 years ago
parent
commit
ca774f9e6a

+ 2 - 1
tracim/development.ini.base View File

246
 jitsi_meet.use_token = False
246
 jitsi_meet.use_token = False
247
 # If token mode is choosen, you need to provide a token generator.
247
 # If token mode is choosen, you need to provide a token generator.
248
 # "local" value mean that tracim himself will create token for jitsi-meet
248
 # "local" value mean that tracim himself will create token for jitsi-meet
249
+# Distant token generator are not yet implemented.
249
 jitsi_meet.token_generator = local
250
 jitsi_meet.token_generator = local
250
 # identifier share between jitsi_meet and local token_generator
251
 # identifier share between jitsi_meet and local token_generator
251
 jitsi_meet.token_generator.local.app_id = tracim
252
 jitsi_meet.token_generator.local.app_id = tracim
252
 # Secret share between jitsi-meet and local token_generator
253
 # Secret share between jitsi-meet and local token_generator
253
 jitsi_meet.token_generator.local.secret = my_secret
254
 jitsi_meet.token_generator.local.secret = my_secret
254
 # Algorithm used to sign JWT token
255
 # Algorithm used to sign JWT token
255
-jitsi_meet.token_generator.local.algo = HS256
256
+jitsi_meet.token_generator.local.algorithm = HS256
256
 # Duration of token validity in second. 5 minutes (300) is a good choice.
257
 # Duration of token validity in second. 5 minutes (300) is a good choice.
257
 jitsi_meet.token_generator.local.duration = 300
258
 jitsi_meet.token_generator.local.duration = 300
258
 
259
 

+ 2 - 2
tracim/tracim/config/app_cfg.py View File

460
         self.JITSI_MEET_TOKEN_GENERATOR_LOCAL_SECRET = tg.config.get(
460
         self.JITSI_MEET_TOKEN_GENERATOR_LOCAL_SECRET = tg.config.get(
461
             'jitsi_meet.token_generator.local.secret'
461
             'jitsi_meet.token_generator.local.secret'
462
         )
462
         )
463
-        self.JITSI_MEET_TOKEN_GENERATOR_LOCAL_ALG = tg.config.get(
464
-            'jitsi_meet.token_generator.local.alg',
463
+        self.JITSI_MEET_TOKEN_GENERATOR_LOCAL_ALGORITHM = tg.config.get(
464
+            'jitsi_meet.token_generator.local.algorithm',
465
             'HS256'
465
             'HS256'
466
         )
466
         )
467
         self.JITSI_MEET_TOKEN_GENERATOR_LOCAL_DURATION = int(tg.config.get(
467
         self.JITSI_MEET_TOKEN_GENERATOR_LOCAL_DURATION = int(tg.config.get(

+ 16 - 11
tracim/tracim/lib/jitsi_meet/room.py View File

16
             issuer: typing.Union[User, JitsiMeetUser, None]=None,
16
             issuer: typing.Union[User, JitsiMeetUser, None]=None,
17
     ) -> None:
17
     ) -> None:
18
         """
18
         """
19
+        This class set all to create a JitsiMeetRoom according
20
+        to current config.
19
         :param issuer: user who initiated Jitsi Meet talk
21
         :param issuer: user who initiated Jitsi Meet talk
20
         if None, default user is created. Can be both Tracim User or
22
         if None, default user is created. Can be both Tracim User or
21
         JitsiMeetUser.
23
         JitsiMeetUser.
26
         self._set_domain()
28
         self._set_domain()
27
         self._set_token_params()
29
         self._set_token_params()
28
         self._set_context(
30
         self._set_context(
29
-            receivers=receivers,
31
+            workspace=receivers,
30
             issuer=issuer,
32
             issuer=issuer,
31
         )
33
         )
32
         self.room = self._generate_room_name(receivers)
34
         self.room = self._generate_room_name(receivers)
45
         """
47
         """
46
         self.use_token = self.tracim_cfg.JITSI_MEET_USE_TOKEN
48
         self.use_token = self.tracim_cfg.JITSI_MEET_USE_TOKEN
47
         if self.use_token:
49
         if self.use_token:
48
-            if self.tracim_cfg.JITSI_MEET_TOKEN_GENERATOR == 'local':
49
-                self.token_app_id = self.tracim_cfg.JITSI_MEET_TOKEN_GENERATOR_LOCAL_APP_ID  # nopep8
50
-                self.token_secret = self.tracim_cfg.JITSI_MEET_TOKEN_GENERATOR_LOCAL_SECRET  # nopep8
51
-                self.token_alg = self.tracim_cfg.JITSI_MEET_TOKEN_GENERATOR_LOCAL_ALG   # nopep8
52
-                self.token_duration = self.tracim_cfg.JITSI_MEET_TOKEN_GENERATOR_LOCAL_DURATION  # nopep8
53
-            else:
50
+            if self.tracim_cfg.JITSI_MEET_TOKEN_GENERATOR != 'local':
54
                 raise JitsiMeetNoTokenGenerator
51
                 raise JitsiMeetNoTokenGenerator
55
 
52
 
53
+            self.token_app_id = self.tracim_cfg.JITSI_MEET_TOKEN_GENERATOR_LOCAL_APP_ID  # nopep8
54
+            self.token_secret = self.tracim_cfg.JITSI_MEET_TOKEN_GENERATOR_LOCAL_SECRET  # nopep8
55
+            self.token_alg = self.tracim_cfg.JITSI_MEET_TOKEN_GENERATOR_LOCAL_ALGORITHM   # nopep8
56
+            self.token_duration = self.tracim_cfg.JITSI_MEET_TOKEN_GENERATOR_LOCAL_DURATION  # nopep8
57
+
56
     def _set_context(
58
     def _set_context(
57
             self,
59
             self,
58
-            receivers: Workspace,
60
+            workspace: Workspace,
59
             issuer: typing.Union[User, JitsiMeetUser, None],
61
             issuer: typing.Union[User, JitsiMeetUser, None],
60
     ) -> None:
62
     ) -> None:
61
         """
63
         """
63
         :param issuer: user who initiated Jitsi Meet talk
65
         :param issuer: user who initiated Jitsi Meet talk
64
         if None, default user is created. Can be both Tracim User or
66
         if None, default user is created. Can be both Tracim User or
65
         JitsiMeetUser.
67
         JitsiMeetUser.
66
-        :param receivers: User or Room who can talk with sender. Now, only
68
+        :param workspace: User or Room who can talk with sender. Now, only
67
         Workspace are supported.
69
         Workspace are supported.
68
         :return: nothing.
70
         :return: nothing.
69
         """
71
         """
84
             )
86
             )
85
 
87
 
86
         # INFO - G.M - 13-02-2018 - Associate
88
         # INFO - G.M - 13-02-2018 - Associate
87
-        group = receivers.label
89
+        group = workspace.label
88
 
90
 
89
         self.context = JitsiMeetContext(
91
         self.context = JitsiMeetContext(
90
             user=user,
92
             user=user,
107
         # Jitsi-Meet doesn't like specials_characters
109
         # Jitsi-Meet doesn't like specials_characters
108
         return str_as_alpha_num_str(room)
110
         return str_as_alpha_num_str(room)
109
 
111
 
110
-    def generate_token(self) -> str:
112
+    def generate_jwt_token(self) -> str:
111
         """
113
         """
112
         Generate Jitsi-Meet related JWT token
114
         Generate Jitsi-Meet related JWT token
113
         :return: JWT token as str
115
         :return: JWT token as str
129
     def generate_url(self, token=None) -> str:
131
     def generate_url(self, token=None) -> str:
130
         """
132
         """
131
         Generate Jitsi-Meet url with or without token
133
         Generate Jitsi-Meet url with or without token
134
+        examples :
135
+         - https://myjitsiinstance/myroom
136
+         - https://mysecurejitsiinstance/myroom?jwt=[very_long_jwt_token]
132
         :return: url as string
137
         :return: url as string
133
         """
138
         """
134
         if token:
139
         if token:

+ 1 - 1
tracim/tracim/templates/videoconf/invite.mak View File

11
         <p>
11
         <p>
12
         ${_('To invite someone from outside of tracim into this conference, share this link. This link is available for 5 minutes.')}
12
         ${_('To invite someone from outside of tracim into this conference, share this link. This link is available for 5 minutes.')}
13
         </p>
13
         </p>
14
-        <textarea readonly=readonly wrap="off" style="width: 100%;">${jitsi_meet_room.generate_url(jitsi_meet_room.generate_token())}</textarea>
14
+        <textarea readonly=readonly wrap="off" style="width: 100%;">${jitsi_meet_room.generate_url(jitsi_meet_room.generate_jwt_token())}</textarea>
15
     </div>
15
     </div>
16
     <div class="modal-footer">
16
     <div class="modal-footer">
17
         <button type="button" class="btn btn-default" data-dismiss="modal">${_('Close')}</button>
17
         <button type="button" class="btn btn-default" data-dismiss="modal">${_('Close')}</button>

+ 1 - 1
tracim/tracim/templates/videoconf/jitsi_meet.mak View File

46
         // for another way to deal with auto-auth :
46
         // for another way to deal with auto-auth :
47
         // see this rejected PR : https://github.com/jitsi/jitsi-meet/pull/2109
47
         // see this rejected PR : https://github.com/jitsi/jitsi-meet/pull/2109
48
             %if jitsi_meet_room.use_token:
48
             %if jitsi_meet_room.use_token:
49
-                jwt: '${jitsi_meet_room.generate_token()}',
49
+                jwt: '${jitsi_meet_room.generate_jwt_token()}',
50
             %endif
50
             %endif
51
             roomName : '${jitsi_meet_room.room}',
51
             roomName : '${jitsi_meet_room.room}',
52
             parentNode: document.querySelector('#jitsi'),
52
             parentNode: document.querySelector('#jitsi'),

+ 4 - 4
tracim/tracim/tests/library/test_jitsi_meet_room.py View File

67
                 receivers=Workspace()
67
                 receivers=Workspace()
68
             )
68
             )
69
             jmr.use_token = False
69
             jmr.use_token = False
70
-            jmr.generate_token()
70
+            jmr.generate_jwt_token()
71
 
71
 
72
     def test_unit__set_context_return_always_jitsi_meet_user(self):
72
     def test_unit__set_context_return_always_jitsi_meet_user(self):
73
         with patch.object(JitsiMeetRoom,
73
         with patch.object(JitsiMeetRoom,
76
             jmr = JitsiMeetRoom(
76
             jmr = JitsiMeetRoom(
77
                 receivers=Workspace()
77
                 receivers=Workspace()
78
             )
78
             )
79
-            jmr._set_context(issuer=None, receivers=Workspace())
79
+            jmr._set_context(issuer=None, workspace=Workspace())
80
             assert jmr.context
80
             assert jmr.context
81
             assert hasattr(jmr.context, 'user')
81
             assert hasattr(jmr.context, 'user')
82
             assert isinstance(jmr.context.user, JitsiMeetUser)
82
             assert isinstance(jmr.context.user, JitsiMeetUser)
85
                 receivers=Workspace()
85
                 receivers=Workspace()
86
             )
86
             )
87
             jmr2._set_context(issuer=JitsiMeetUser(jitsi_meet_user_id='user'),
87
             jmr2._set_context(issuer=JitsiMeetUser(jitsi_meet_user_id='user'),
88
-                              receivers=Workspace())
88
+                              workspace=Workspace())
89
             assert jmr2.context
89
             assert jmr2.context
90
             assert hasattr(jmr2.context, 'user')
90
             assert hasattr(jmr2.context, 'user')
91
             assert isinstance(jmr2.context.user, JitsiMeetUser)
91
             assert isinstance(jmr2.context.user, JitsiMeetUser)
93
             jmr3 = JitsiMeetRoom(
93
             jmr3 = JitsiMeetRoom(
94
                 receivers=Workspace()
94
                 receivers=Workspace()
95
             )
95
             )
96
-            jmr3._set_context(issuer=User(), receivers=Workspace())
96
+            jmr3._set_context(issuer=User(), workspace=Workspace())
97
             assert jmr3.context
97
             assert jmr3.context
98
             assert hasattr(jmr3.context, 'user')
98
             assert hasattr(jmr3.context, 'user')
99
             assert isinstance(jmr3.context.user, JitsiMeetUser)
99
             assert isinstance(jmr3.context.user, JitsiMeetUser)