Browse Source

typing and comments

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

+ 18 - 4
tracim/tracim/controllers/jitsi_meet.py View File

19
 
19
 
20
     allow_only = not_anonymous()
20
     allow_only = not_anonymous()
21
 
21
 
22
-    def _before(self, *args, **kw):
22
+    def _before(self, *args, **kw) -> None:
23
         TIMRestPathContextSetup.current_user()
23
         TIMRestPathContextSetup.current_user()
24
         try:
24
         try:
25
             TIMRestPathContextSetup.current_workspace()
25
             TIMRestPathContextSetup.current_workspace()
28
 
28
 
29
     @tg.require(current_user_is_reader())
29
     @tg.require(current_user_is_reader())
30
     @expose('tracim.templates.videoconf.jitsi_meet')
30
     @expose('tracim.templates.videoconf.jitsi_meet')
31
-    def get(self):
31
+    def get(self) -> DictLikeClass:
32
+        """
33
+        Jitsi-Meet Room page
34
+        """
32
         user = tmpl_context.current_user
35
         user = tmpl_context.current_user
33
         return self._jitsi_room(jitsi_user=user)
36
         return self._jitsi_room(jitsi_user=user)
34
 
37
 
35
     @tg.require(current_user_is_reader())
38
     @tg.require(current_user_is_reader())
36
     @expose('tracim.templates.videoconf.invite')
39
     @expose('tracim.templates.videoconf.invite')
37
-    def invite(self):
40
+    def invite(self) -> DictLikeClass:
41
+        """
42
+        Modal windows : Invitation to Jitsi-Meet room
43
+        """
44
+        # TODO - G.M - 14-02-2017 - Allow to invite not Anonymous user ?
45
+        # Jitsi-Meet allow to set user info through token
46
+        # invite already "named" user should be possible
38
         return self._jitsi_room()
47
         return self._jitsi_room()
39
 
48
 
40
     @classmethod
49
     @classmethod
41
     def _jitsi_room(
50
     def _jitsi_room(
42
             cls,
51
             cls,
43
             jitsi_user: typing.Union[JitsiMeetUser, User, None]=None,
52
             jitsi_user: typing.Union[JitsiMeetUser, User, None]=None,
44
-    ):
53
+    )-> DictLikeClass:
54
+        """
55
+        Get all infos to generate DictLikeClass usable for JitsiMeetRoom
56
+        Templates.
57
+        :param jitsi_user: User who access to room
58
+        """
45
         cfg = CFG.get_instance()
59
         cfg = CFG.get_instance()
46
         if not cfg.JITSI_MEET_ACTIVATED:
60
         if not cfg.JITSI_MEET_ACTIVATED:
47
             abort(404)
61
             abort(404)

+ 43 - 15
tracim/tracim/lib/jitsi_meet/room.py View File

9
 import uuid
9
 import uuid
10
 
10
 
11
 
11
 
12
-class JitsiMeetNoTokenGenerator(Exception):
13
-    pass
14
-
15
-
16
-class JitsiMeetTokenNotActivated(Exception):
17
-    pass
18
-
19
-
20
 class JitsiMeetRoom(object):
12
 class JitsiMeetRoom(object):
21
     def __init__(
13
     def __init__(
22
             self,
14
             self,
38
         )
30
         )
39
         self.room = self._generate_room_name(receivers)
31
         self.room = self._generate_room_name(receivers)
40
 
32
 
41
-    def _set_domain(self):
33
+    def _set_domain(self) -> None:
34
+        """
35
+        Set domain according to config
36
+        :return:
37
+        """
42
         cfg = CFG.get_instance()
38
         cfg = CFG.get_instance()
43
         self.domain = cfg.JITSI_MEET_DOMAIN
39
         self.domain = cfg.JITSI_MEET_DOMAIN
44
 
40
 
45
-    def _set_token_params(self):
41
+    def _set_token_params(self) -> None:
42
+        """
43
+        Set params related to token according to config.
44
+        :return: nothing
45
+        """
46
         cfg = CFG.get_instance()
46
         cfg = CFG.get_instance()
47
         self.use_token = cfg.JITSI_MEET_USE_TOKEN
47
         self.use_token = cfg.JITSI_MEET_USE_TOKEN
48
         if self.use_token:
48
         if self.use_token:
58
             self,
58
             self,
59
             receivers: Workspace,
59
             receivers: Workspace,
60
             issuer: typing.Union[User, JitsiMeetUser, None],
60
             issuer: typing.Union[User, JitsiMeetUser, None],
61
-    ):
61
+    ) -> None:
62
+        """
63
+        Set context of JWT token for Jitsi Meet
64
+        :param issuer: user who initiated Jitsi Meet talk
65
+        if None, default user is created. Can be both Tracim User or
66
+        JitsiMeetUser.
67
+        :param receivers: User or Room who can talk with sender. Now, only
68
+        Workspace are supported.
69
+        :return: nothing.
70
+        """
62
 
71
 
63
-        # User
72
+        # INFO - G.M - 13-02-2018 - Convert all issuers values as JitsiMeetUser
64
         if isinstance(issuer, JitsiMeetUser):
73
         if isinstance(issuer, JitsiMeetUser):
65
             user = issuer
74
             user = issuer
66
         elif isinstance(issuer, User):
75
         elif isinstance(issuer, User):
71
             )
80
             )
72
         else:
81
         else:
73
             user = JitsiMeetUser(
82
             user = JitsiMeetUser(
83
+                # INFO - G.M - 13-02-2018 - create unique id for anonymous user
74
                 jitsi_meet_user_id=str(uuid.uuid4()),
84
                 jitsi_meet_user_id=str(uuid.uuid4()),
75
             )
85
             )
76
 
86
 
77
-        # Group
87
+        # INFO - G.M - 13-02-2018 - Associate
78
         group = receivers.label
88
         group = receivers.label
79
 
89
 
80
         self.context = JitsiMeetContext(
90
         self.context = JitsiMeetContext(
83
         )
93
         )
84
 
94
 
85
     @classmethod
95
     @classmethod
86
-    def _generate_room_name(cls, workspace: Workspace):
96
+    def _generate_room_name(cls, workspace: Workspace) -> str:
97
+        """
98
+        Generate Jitsi-Meet room name related to workspace
99
+        that should be unique, always the same for same workspace in same Tracim
100
+        instance but should also no contains any special characters
101
+        :param workspace: Tracim Workspace
102
+        :return: room name as str.
103
+        """
87
         cfg = CFG.get_instance()
104
         cfg = CFG.get_instance()
88
         room = "{uuid}{workspace_id}{workspace_label}".format(
105
         room = "{uuid}{workspace_id}{workspace_label}".format(
89
             uuid=cfg.TRACIM_INSTANCE_UUID,
106
             uuid=cfg.TRACIM_INSTANCE_UUID,
94
         return str_as_alpha_num_str(room)
111
         return str_as_alpha_num_str(room)
95
 
112
 
96
     def generate_token(self) -> str:
113
     def generate_token(self) -> str:
114
+        """
115
+        Generate Jitsi-Meet related JWT token
116
+        :return: JWT token as str
117
+        """
97
         if not self.use_token:
118
         if not self.use_token:
98
             raise JitsiMeetTokenNotActivated
119
             raise JitsiMeetTokenNotActivated
99
 
120
 
110
 
131
 
111
     def generate_url(self, token=None) -> str:
132
     def generate_url(self, token=None) -> str:
112
         """
133
         """
113
-        Generate url with or without token
134
+        Generate Jitsi-Meet url with or without token
114
         :return: url as string
135
         :return: url as string
115
         """
136
         """
116
         if token:
137
         if token:
122
                                  self.room,
143
                                  self.room,
123
                                  )
144
                                  )
124
         return "https://{}".format(url)
145
         return "https://{}".format(url)
146
+
147
+class JitsiMeetNoTokenGenerator(Exception):
148
+    pass
149
+
150
+
151
+class JitsiMeetTokenNotActivated(Exception):
152
+    pass

+ 23 - 8
tracim/tracim/lib/jitsi_meet/token.py View File

2
 import typing
2
 import typing
3
 import jwt
3
 import jwt
4
 
4
 
5
+# Jitsi Meet Token
6
+# Data model and methods to convert dict as JWT token
7
+# see https://github.com/jitsi/lib-jitsi-meet/blob/52eb3decf6542413c739ce2209456fac728a89d5/doc/tokens.md  # nopep8
8
+
5
 
9
 
6
 class JitsiMeetUser(object):
10
 class JitsiMeetUser(object):
7
 
11
 
11
             name: typing.Optional[str] = None,
15
             name: typing.Optional[str] = None,
12
             email: typing.Optional[str] = None,
16
             email: typing.Optional[str] = None,
13
             avatar_url: typing.Optional[str] = None,
17
             avatar_url: typing.Optional[str] = None,
14
-    ):
18
+    ) -> None:
15
         """
19
         """
16
-
20
+        User data for Jitsi-Meet token
17
         :param avatar_url: url for user avatar_url
21
         :param avatar_url: url for user avatar_url
18
         :param name: display name of user
22
         :param name: display name of user
19
         :param email: email of user
23
         :param email: email of user
25
         self.jitsi_meet_user_id = jitsi_meet_user_id
29
         self.jitsi_meet_user_id = jitsi_meet_user_id
26
 
30
 
27
     def as_dict(self) -> dict:
31
     def as_dict(self) -> dict:
32
+        """
33
+        Generate dict for JWT token
34
+        :return: user as dict
35
+        """
28
         data = {
36
         data = {
29
             'id': self.jitsi_meet_user_id,
37
             'id': self.jitsi_meet_user_id,
30
         }
38
         }
44
             user: typing.Optional[JitsiMeetUser]=None,
52
             user: typing.Optional[JitsiMeetUser]=None,
45
             callee: typing.Optional[JitsiMeetUser]=None,
53
             callee: typing.Optional[JitsiMeetUser]=None,
46
             group: str="default",
54
             group: str="default",
47
-    ):
55
+    ) -> None:
48
         """
56
         """
49
-        Context as in JitsiToken Payload
50
-        see https://github.com/jitsi/lib-jitsi-meet/blob/52eb3decf6542413c739ce2209456fac728a89d5/doc/tokens.md  # nopep8
57
+        context as in Jitsi-Meet Token
51
         :param user: Current user
58
         :param user: Current user
52
         :param callee: User Who respond in 1-to-1 conf
59
         :param callee: User Who respond in 1-to-1 conf
53
         :param group: Used only for stats
60
         :param group: Used only for stats
57
         self.group = group
64
         self.group = group
58
 
65
 
59
     def as_dict(self) -> dict:
66
     def as_dict(self) -> dict:
67
+        """
68
+        Generate dict for JWT token
69
+        :return: context as dict
70
+        """
60
         data = {}
71
         data = {}
61
         if self.callee:
72
         if self.callee:
62
             data['callee'] = self.callee.as_dict()
73
             data['callee'] = self.callee.as_dict()
78
             alg: str,
89
             alg: str,
79
             duration: int,
90
             duration: int,
80
             context: typing.Optional[JitsiMeetContext] = None,
91
             context: typing.Optional[JitsiMeetContext] = None,
81
-    )-> None:
92
+    ) -> None:
82
         """
93
         """
83
-        JWT token generator for JitsiMeet,
94
+        JWT token generator for Jitsi-Meet,
84
         :param app_id: application identifier
95
         :param app_id: application identifier
85
         :param secret: secret share between token generator and XMPP server
96
         :param secret: secret share between token generator and XMPP server
86
         :param alg: algorithm used
97
         :param alg: algorithm used
87
         :param duration: duration of token
98
         :param duration: duration of token
88
-        :param domain: jitsi-meet domain
99
+        :param domain: Jitsi-Meet domain
89
         :param room: room name
100
         :param room: room name
90
         """
101
         """
91
         self.room = room
102
         self.room = room
97
         self.context = context
108
         self.context = context
98
 
109
 
99
     def generate(self) -> str:
110
     def generate(self) -> str:
111
+        """
112
+        Generate JWT token
113
+        :return: JWT token as str
114
+        """
100
         now = datetime.datetime.utcnow()
115
         now = datetime.datetime.utcnow()
101
         exp = now+datetime.timedelta(seconds=self.duration)
116
         exp = now+datetime.timedelta(seconds=self.duration)
102
         data = {
117
         data = {