Bladeren bron

CalDavZap client integration finale

Bastien Sevajol (Algoo) 8 jaren geleden
bovenliggende
commit
27507d0d7e

+ 8 - 4
tracim/tracim/controllers/calendar.py Bestand weergeven

34
 
34
 
35
     @tg.expose('tracim.templates.calendar.config')
35
     @tg.expose('tracim.templates.calendar.config')
36
     def index(self):
36
     def index(self):
37
-        # TODO: S'assurer d'être identifié !
37
+        # TODO BS 20160720: S'assurer d'être identifié !
38
         user = tmpl_context.identity.get('user')
38
         user = tmpl_context.identity.get('user')
39
         dictified_current_user = Context(CTX.CURRENT_USER).toDict(user)
39
         dictified_current_user = Context(CTX.CURRENT_USER).toDict(user)
40
 
40
 
41
         fake_api = DictLikeClass(
41
         fake_api = DictLikeClass(
42
             current_user=dictified_current_user,
42
             current_user=dictified_current_user,
43
         )
43
         )
44
-        calendar_urls = CalendarManager\
45
-            .get_readable_calendars_urls_for_user(user)
44
+        user_base_url = CalendarManager.get_user_base_url()
45
+        workspace_base_url = CalendarManager.get_workspace_base_url()
46
+        workspace_calendar_urls = CalendarManager\
47
+            .get_workspace_readable_calendars_urls_for_user(user)
46
 
48
 
47
         # Template will use User.auth_token, ensure it's validity
49
         # Template will use User.auth_token, ensure it's validity
48
         user.ensure_auth_token()
50
         user.ensure_auth_token()
49
 
51
 
50
         return DictLikeClass(
52
         return DictLikeClass(
51
             fake_api=fake_api,
53
             fake_api=fake_api,
52
-            clendar_urls=calendar_urls,
54
+            user_base_url=user_base_url,
55
+            workspace_base_url=workspace_base_url,
56
+            workspace_clendar_urls=workspace_calendar_urls,
53
             auth_token=user.auth_token,
57
             auth_token=user.auth_token,
54
         )
58
         )

+ 27 - 2
tracim/tracim/lib/calendar.py Bestand weergeven

30
 CALENDAR_USER_URL_TEMPLATE = 'user/{id}.ics/'
30
 CALENDAR_USER_URL_TEMPLATE = 'user/{id}.ics/'
31
 CALENDAR_WORKSPACE_URL_TEMPLATE = 'workspace/{id}.ics/'
31
 CALENDAR_WORKSPACE_URL_TEMPLATE = 'workspace/{id}.ics/'
32
 
32
 
33
+CALENDAR_USER_BASE_URL = '/user/'
34
+CALENDAR_WORKSPACE_BASE_URL = '/workspace/'
35
+
33
 
36
 
34
 class CalendarManager(object):
37
 class CalendarManager(object):
35
     @classmethod
38
     @classmethod
39
         return cfg.RADICALE_CLIENT_BASE_URL_TEMPLATE
42
         return cfg.RADICALE_CLIENT_BASE_URL_TEMPLATE
40
 
43
 
41
     @classmethod
44
     @classmethod
45
+    def get_user_base_url(cls):
46
+        from tracim.config.app_cfg import CFG
47
+        cfg = CFG.get_instance()
48
+        return os.path.join(cfg.RADICALE_CLIENT_BASE_URL_TEMPLATE, 'user/')
49
+
50
+    @classmethod
51
+    def get_workspace_base_url(cls):
52
+        from tracim.config.app_cfg import CFG
53
+        cfg = CFG.get_instance()
54
+        return os.path.join(cfg.RADICALE_CLIENT_BASE_URL_TEMPLATE, 'workspace/')
55
+
56
+    @classmethod
42
     def get_user_calendar_url(cls, user_id: int):
57
     def get_user_calendar_url(cls, user_id: int):
43
         user_path = CALENDAR_USER_URL_TEMPLATE.format(id=str(user_id))
58
         user_path = CALENDAR_USER_URL_TEMPLATE.format(id=str(user_id))
44
         return os.path.join(cls.get_base_url(), user_path)
59
         return os.path.join(cls.get_base_url(), user_path)
262
         }
277
         }
263
 
278
 
264
     @classmethod
279
     @classmethod
265
-    def get_readable_calendars_urls_for_user(cls, user: User) -> [str]:
266
-        calendar_urls = [cls.get_user_calendar_url(user.user_id)]
280
+    def get_workspace_readable_calendars_urls_for_user(cls, user: User)\
281
+            -> [str]:
282
+        calendar_urls = []
267
         workspace_api = WorkspaceApi(user)
283
         workspace_api = WorkspaceApi(user)
268
         for workspace in workspace_api.get_all_for_user(user):
284
         for workspace in workspace_api.get_all_for_user(user):
269
             if workspace.calendar_enabled:
285
             if workspace.calendar_enabled:
272
                 ))
288
                 ))
273
 
289
 
274
         return calendar_urls
290
         return calendar_urls
291
+
292
+    def is_discovery_path(self, path: str) -> bool:
293
+        """
294
+        If collection url in one of them, Caldav client is tring to discover
295
+        collections.
296
+        :param path: collection path
297
+        :return: True if given collection path is an discover path
298
+        """
299
+        return path in ('user', 'workspace')

+ 4 - 0
tracim/tracim/lib/radicale/rights.py Bestand weergeven

15
         return False
15
         return False
16
     current_user = UserApi(None).get_one_by_email(user)
16
     current_user = UserApi(None).get_one_by_email(user)
17
     manager = CalendarManager(current_user)
17
     manager = CalendarManager(current_user)
18
+
19
+    if manager.is_discovery_path(collection.path):
20
+        return True
21
+
18
     try:
22
     try:
19
         calendar = manager.find_calendar_with_path(collection.path)
23
         calendar = manager.find_calendar_with_path(collection.path)
20
     except NotFound:
24
     except NotFound:

+ 7 - 40
tracim/tracim/templates/calendar/config.mak Bestand weergeven

1
 // Values copied from caldavzap config.js file.
1
 // Values copied from caldavzap config.js file.
2
 
2
 
3
 var globalAccountSettings=[
3
 var globalAccountSettings=[
4
-% for clendar_url in clendar_urls:
5
     {
4
     {
6
-        href: '${clendar_url}',
5
+        href: '${user_base_url}',
7
         userAuth:
6
         userAuth:
8
         {
7
         {
9
             userName: '${fake_api.current_user.email}',
8
             userName: '${fake_api.current_user.email}',
16
         delegation: false,
15
         delegation: false,
17
         forceReadOnly: null,
16
         forceReadOnly: null,
18
         ignoreAlarms: false,
17
         ignoreAlarms: false,
19
-        backgroundCalendars: []
20
-    },
21
-% endfor
22
-/**    {
23
-        href: 'http://127.0.0.1:5232/user/1.ics/',
24
-        userAuth:
25
-        {
26
-            userName: 'admin@admin.admin',
27
-            userPassword: 'admin@admin.admin'
28
-        },
29
-        timeOut: 90000,
30
-        lockTimeOut: 10000,
31
-        checkContentType: true,
32
-        settingsAccount: false,
33
-        delegation: false,
34
-        forceReadOnly: null,
35
-        ignoreAlarms: false,
36
-        backgroundCalendars: []
37
-    },
38
-    {
39
-        href: 'http://127.0.0.1:5232/workspace/1.ics/',
40
-        userAuth:
41
-        {
42
-            userName: 'admin@admin.admin',
43
-            userPassword: 'admin@admin.admin'
44
-        },
45
-        timeOut: 90000,
46
-        lockTimeOut: 10000,
47
-        checkContentType: true,
48
-        settingsAccount: false,
49
-        delegation: false,
50
-        forceReadOnly: null,
51
-        ignoreAlarms: false,
52
-        backgroundCalendars: []
18
+        backgroundCalendars: ['1.ics']
53
     },
19
     },
20
+% if workspace_clendar_urls:
54
     {
21
     {
55
-        href: 'http://127.0.0.1:5232/workspace/2.ics/',
22
+        href: '${workspace_base_url}',
56
         userAuth:
23
         userAuth:
57
         {
24
         {
58
-            userName: 'admin@admin.admin',
59
-            userPassword: 'admin@admin.admin'
25
+            userName: '${fake_api.current_user.email}',
26
+            userPassword: '${auth_token}'
60
         },
27
         },
61
         timeOut: 90000,
28
         timeOut: 90000,
62
         lockTimeOut: 10000,
29
         lockTimeOut: 10000,
67
         ignoreAlarms: false,
34
         ignoreAlarms: false,
68
         backgroundCalendars: []
35
         backgroundCalendars: []
69
     },
36
     },
70
-*/
37
+% endif
71
 ] ;
38
 ] ;
72
 
39
 
73
 var globalBackgroundSync=true;
40
 var globalBackgroundSync=true;