Explorar el Código

typing and comments

Guénaël Muller hace 6 años
padre
commit
bb5d7dc561

+ 18 - 4
tracim/tracim/controllers/jitsi_meet.py Ver fichero

@@ -19,7 +19,7 @@ class JitsiMeetController(TIMRestController):
19 19
 
20 20
     allow_only = not_anonymous()
21 21
 
22
-    def _before(self, *args, **kw):
22
+    def _before(self, *args, **kw) -> None:
23 23
         TIMRestPathContextSetup.current_user()
24 24
         try:
25 25
             TIMRestPathContextSetup.current_workspace()
@@ -28,20 +28,34 @@ class JitsiMeetController(TIMRestController):
28 28
 
29 29
     @tg.require(current_user_is_reader())
30 30
     @expose('tracim.templates.videoconf.jitsi_meet')
31
-    def get(self):
31
+    def get(self) -> DictLikeClass:
32
+        """
33
+        Jitsi-Meet Room page
34
+        """
32 35
         user = tmpl_context.current_user
33 36
         return self._jitsi_room(jitsi_user=user)
34 37
 
35 38
     @tg.require(current_user_is_reader())
36 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 47
         return self._jitsi_room()
39 48
 
40 49
     @classmethod
41 50
     def _jitsi_room(
42 51
             cls,
43 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 59
         cfg = CFG.get_instance()
46 60
         if not cfg.JITSI_MEET_ACTIVATED:
47 61
             abort(404)

+ 43 - 15
tracim/tracim/lib/jitsi_meet/room.py Ver fichero

@@ -9,14 +9,6 @@ from tracim.model.data import User
9 9
 import uuid
10 10
 
11 11
 
12
-class JitsiMeetNoTokenGenerator(Exception):
13
-    pass
14
-
15
-
16
-class JitsiMeetTokenNotActivated(Exception):
17
-    pass
18
-
19
-
20 12
 class JitsiMeetRoom(object):
21 13
     def __init__(
22 14
             self,
@@ -38,11 +30,19 @@ class JitsiMeetRoom(object):
38 30
         )
39 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 38
         cfg = CFG.get_instance()
43 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 46
         cfg = CFG.get_instance()
47 47
         self.use_token = cfg.JITSI_MEET_USE_TOKEN
48 48
         if self.use_token:
@@ -58,9 +58,18 @@ class JitsiMeetRoom(object):
58 58
             self,
59 59
             receivers: Workspace,
60 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 73
         if isinstance(issuer, JitsiMeetUser):
65 74
             user = issuer
66 75
         elif isinstance(issuer, User):
@@ -71,10 +80,11 @@ class JitsiMeetRoom(object):
71 80
             )
72 81
         else:
73 82
             user = JitsiMeetUser(
83
+                # INFO - G.M - 13-02-2018 - create unique id for anonymous user
74 84
                 jitsi_meet_user_id=str(uuid.uuid4()),
75 85
             )
76 86
 
77
-        # Group
87
+        # INFO - G.M - 13-02-2018 - Associate
78 88
         group = receivers.label
79 89
 
80 90
         self.context = JitsiMeetContext(
@@ -83,7 +93,14 @@ class JitsiMeetRoom(object):
83 93
         )
84 94
 
85 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 104
         cfg = CFG.get_instance()
88 105
         room = "{uuid}{workspace_id}{workspace_label}".format(
89 106
             uuid=cfg.TRACIM_INSTANCE_UUID,
@@ -94,6 +111,10 @@ class JitsiMeetRoom(object):
94 111
         return str_as_alpha_num_str(room)
95 112
 
96 113
     def generate_token(self) -> str:
114
+        """
115
+        Generate Jitsi-Meet related JWT token
116
+        :return: JWT token as str
117
+        """
97 118
         if not self.use_token:
98 119
             raise JitsiMeetTokenNotActivated
99 120
 
@@ -110,7 +131,7 @@ class JitsiMeetRoom(object):
110 131
 
111 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 135
         :return: url as string
115 136
         """
116 137
         if token:
@@ -122,3 +143,10 @@ class JitsiMeetRoom(object):
122 143
                                  self.room,
123 144
                                  )
124 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 Ver fichero

@@ -2,6 +2,10 @@ import datetime
2 2
 import typing
3 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 10
 class JitsiMeetUser(object):
7 11
 
@@ -11,9 +15,9 @@ class JitsiMeetUser(object):
11 15
             name: typing.Optional[str] = None,
12 16
             email: typing.Optional[str] = None,
13 17
             avatar_url: typing.Optional[str] = None,
14
-    ):
18
+    ) -> None:
15 19
         """
16
-
20
+        User data for Jitsi-Meet token
17 21
         :param avatar_url: url for user avatar_url
18 22
         :param name: display name of user
19 23
         :param email: email of user
@@ -25,6 +29,10 @@ class JitsiMeetUser(object):
25 29
         self.jitsi_meet_user_id = jitsi_meet_user_id
26 30
 
27 31
     def as_dict(self) -> dict:
32
+        """
33
+        Generate dict for JWT token
34
+        :return: user as dict
35
+        """
28 36
         data = {
29 37
             'id': self.jitsi_meet_user_id,
30 38
         }
@@ -44,10 +52,9 @@ class JitsiMeetContext(object):
44 52
             user: typing.Optional[JitsiMeetUser]=None,
45 53
             callee: typing.Optional[JitsiMeetUser]=None,
46 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 58
         :param user: Current user
52 59
         :param callee: User Who respond in 1-to-1 conf
53 60
         :param group: Used only for stats
@@ -57,6 +64,10 @@ class JitsiMeetContext(object):
57 64
         self.group = group
58 65
 
59 66
     def as_dict(self) -> dict:
67
+        """
68
+        Generate dict for JWT token
69
+        :return: context as dict
70
+        """
60 71
         data = {}
61 72
         if self.callee:
62 73
             data['callee'] = self.callee.as_dict()
@@ -78,14 +89,14 @@ class JitsiMeetToken(object):
78 89
             alg: str,
79 90
             duration: int,
80 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 95
         :param app_id: application identifier
85 96
         :param secret: secret share between token generator and XMPP server
86 97
         :param alg: algorithm used
87 98
         :param duration: duration of token
88
-        :param domain: jitsi-meet domain
99
+        :param domain: Jitsi-Meet domain
89 100
         :param room: room name
90 101
         """
91 102
         self.room = room
@@ -97,6 +108,10 @@ class JitsiMeetToken(object):
97 108
         self.context = context
98 109
 
99 110
     def generate(self) -> str:
111
+        """
112
+        Generate JWT token
113
+        :return: JWT token as str
114
+        """
100 115
         now = datetime.datetime.utcnow()
101 116
         exp = now+datetime.timedelta(seconds=self.duration)
102 117
         data = {