瀏覽代碼

Closes #66: Radicale: client parameter url in config

Bastien Sevajol (Algoo) 8 年之前
父節點
當前提交
68b7c4053c
共有 5 個文件被更改,包括 38 次插入65 次删除
  1. 3 4
      tracim/development.ini.base
  2. 9 5
      tracim/tracim/config/app_cfg.py
  3. 18 34
      tracim/tracim/lib/calendar.py
  4. 4 12
      tracim/tracim/model/auth.py
  5. 4 10
      tracim/tracim/model/data.py

+ 3 - 4
tracim/development.ini.base 查看文件

169
 # The following base_url is used for links and icons
169
 # The following base_url is used for links and icons
170
 # integrated in the email notifcations
170
 # integrated in the email notifcations
171
 website.base_url = http://127.0.0.1:8080
171
 website.base_url = http://127.0.0.1:8080
172
+# If config not provided, it will be extracted from website.base_url
173
+website.server_name = 127.0.0.1
172
     
174
     
173
 email.notification.activated = False
175
 email.notification.activated = False
174
 email.notification.from = Tracim Notification <noreply@trac.im>
176
 email.notification.from = Tracim Notification <noreply@trac.im>
188
 # radicale.server.port = 5232
190
 # radicale.server.port = 5232
189
 # radicale.server.ssl = false
191
 # radicale.server.ssl = false
190
 # radicale.server.filesystem.folder = ~/.config/radicale/collections
192
 # radicale.server.filesystem.folder = ~/.config/radicale/collections
191
-## If '', current host will be used
192
-# radicale.client.host = ''
193
-# radicale.client.port = 5232
194
-# radicale.client.ssl = false
193
+# radicale.client.base_url = http://{server_name}:{radicale_port}
195
 
194
 
196
 #####
195
 #####
197
 #
196
 #

+ 9 - 5
tracim/tracim/config/app_cfg.py 查看文件

12
     setting = asbool(global_conf.get('the_setting'))
12
     setting = asbool(global_conf.get('the_setting'))
13
  
13
  
14
 """
14
 """
15
+from urllib.parse import urlparse
15
 
16
 
16
 import tg
17
 import tg
17
 from paste.deploy.converters import asbool
18
 from paste.deploy.converters import asbool
177
         self.WEBSITE_HOME_IMAGE_URL = tg.lurl('/assets/img/home_illustration.jpg')
178
         self.WEBSITE_HOME_IMAGE_URL = tg.lurl('/assets/img/home_illustration.jpg')
178
         self.WEBSITE_HOME_BACKGROUND_IMAGE_URL = tg.lurl('/assets/img/bg.jpg')
179
         self.WEBSITE_HOME_BACKGROUND_IMAGE_URL = tg.lurl('/assets/img/bg.jpg')
179
         self.WEBSITE_BASE_URL = tg.config.get('website.base_url', '')
180
         self.WEBSITE_BASE_URL = tg.config.get('website.base_url', '')
181
+        self.WEBSITE_SERVER_NAME = tg.config.get('website.server_name', None)
182
+
183
+        if not self.WEBSITE_SERVER_NAME:
184
+            self.WEBSITE_SERVER_NAME = urlparse(self.WEBSITE_BASE_URL).hostname
180
 
185
 
181
         self.WEBSITE_HOME_TAG_LINE = tg.config.get('website.home.tag_line', '')
186
         self.WEBSITE_HOME_TAG_LINE = tg.config.get('website.home.tag_line', '')
182
         self.WEBSITE_SUBTITLE = tg.config.get('website.home.subtitle', '')
187
         self.WEBSITE_SUBTITLE = tg.config.get('website.home.subtitle', '')
227
             '~/.config/radicale/collections'
232
             '~/.config/radicale/collections'
228
         )
233
         )
229
 
234
 
230
-        # If None, current host will be used
231
-        self.RADICALE_CLIENT_HOST = tg.config.get('radicale.client.host', None)
232
-        self.RADICALE_CLIENT_PORT = tg.config.get('radicale.client.port', 5232)
233
-        self.RADICALE_CLIENT_SSL = asbool(tg.config.get('radicale.client.ssl', False))
234
-
235
+        self.RADICALE_CLIENT_BASE_URL_TEMPLATE = tg.config.get(
236
+            'radicale.client.base_url',
237
+            'http://{server_name}:{radicale_port}',
238
+        )
235
 
239
 
236
     def get_tracker_js_content(self, js_tracker_file_path = None):
240
     def get_tracker_js_content(self, js_tracker_file_path = None):
237
         js_tracker_file_path = tg.config.get('js_tracker_path', None)
241
         js_tracker_file_path = tg.config.get('js_tracker_path', None)

+ 18 - 34
tracim/tracim/lib/calendar.py 查看文件

1
+import os
2
+
1
 import re
3
 import re
2
 import transaction
4
 import transaction
3
 
5
 
24
 CALENDAR_TYPE_USER = UserCalendar
26
 CALENDAR_TYPE_USER = UserCalendar
25
 CALENDAR_TYPE_WORKSPACE = WorkspaceCalendar
27
 CALENDAR_TYPE_WORKSPACE = WorkspaceCalendar
26
 
28
 
27
-CALENDAR_BASE_URL_TEMPLATE = '{proto}://{domain}:{port}'
28
-CALENDAR_USER_URL_TEMPLATE = \
29
-    CALENDAR_BASE_URL_TEMPLATE + '/user/{id}.ics{extra}/'
30
-CALENDAR_WORKSPACE_URL_TEMPLATE = \
31
-    CALENDAR_BASE_URL_TEMPLATE + '/workspace/{id}.ics{extra}/'
29
+CALENDAR_USER_URL_TEMPLATE = 'user/{id}.ics/'
30
+CALENDAR_WORKSPACE_URL_TEMPLATE = 'workspace/{id}.ics/'
32
 
31
 
33
 
32
 
34
 class CalendarManager(object):
33
 class CalendarManager(object):
35
-    @staticmethod
36
-    def get_base_url():
37
-        from tracim.config.app_cfg import CFG
38
-        cfg = CFG.get_instance()
39
-
40
-        return CALENDAR_BASE_URL_TEMPLATE.format(
41
-            proto='https' if cfg.RADICALE_CLIENT_SSL else 'http',
42
-            domain=cfg.RADICALE_CLIENT_HOST or '127.0.0.1',
43
-            port=str(cfg.RADICALE_CLIENT_PORT)
44
-        )
45
-
46
-    @staticmethod
47
-    def get_user_calendar_url(user_id: int, extra: str=''):
34
+    @classmethod
35
+    def get_base_url(cls):
48
         from tracim.config.app_cfg import CFG
36
         from tracim.config.app_cfg import CFG
49
         cfg = CFG.get_instance()
37
         cfg = CFG.get_instance()
50
 
38
 
51
-        return CALENDAR_USER_URL_TEMPLATE.format(
52
-            proto='https' if cfg.RADICALE_CLIENT_SSL else 'http',
53
-            domain=cfg.RADICALE_CLIENT_HOST or '127.0.0.1',
54
-            port=str(cfg.RADICALE_CLIENT_PORT),
55
-            id=str(user_id),
56
-            extra=extra,
39
+        return cfg.RADICALE_CLIENT_BASE_URL_TEMPLATE.format(
40
+            server_name=cfg.WEBSITE_SERVER_NAME,
41
+            radicale_port=cfg.RADICALE_SERVER_PORT,
57
         )
42
         )
58
 
43
 
59
-    @staticmethod
60
-    def get_workspace_calendar_url(workspace_id: int, extra: str=''):
61
-        from tracim.config.app_cfg import CFG
62
-        cfg = CFG.get_instance()
44
+    @classmethod
45
+    def get_user_calendar_url(cls, user_id: int):
46
+        user_path = CALENDAR_USER_URL_TEMPLATE.format(id=str(user_id))
47
+        return os.path.join(cls.get_base_url(), user_path)
63
 
48
 
64
-        return CALENDAR_WORKSPACE_URL_TEMPLATE.format(
65
-            proto='https' if cfg.RADICALE_CLIENT_SSL else 'http',
66
-            domain=cfg.RADICALE_CLIENT_HOST or '127.0.0.1',
67
-            port=str(cfg.RADICALE_CLIENT_PORT),
68
-            id=str(workspace_id),
69
-            extra=extra,
49
+    @classmethod
50
+    def get_workspace_calendar_url(cls, workspace_id: int):
51
+        workspace_path = CALENDAR_WORKSPACE_URL_TEMPLATE.format(
52
+            id=str(workspace_id)
70
         )
53
         )
54
+        return os.path.join(cls.get_base_url(), workspace_path)
71
 
55
 
72
     def __init__(self, user: User):
56
     def __init__(self, user: User):
73
         self._user = user
57
         self._user = user

+ 4 - 12
tracim/tracim/model/auth.py 查看文件

151
     @property
151
     @property
152
     def calendar_url(self) -> str:
152
     def calendar_url(self) -> str:
153
         # TODO - 20160531 - Bastien: Cyclic import if import in top of file
153
         # TODO - 20160531 - Bastien: Cyclic import if import in top of file
154
-        from tracim.config.app_cfg import CFG
155
-        from tracim.lib.calendar import CALENDAR_USER_URL_TEMPLATE
156
-        cfg = CFG.get_instance()
157
-        return CALENDAR_USER_URL_TEMPLATE.format(
158
-            proto='https' if cfg.RADICALE_CLIENT_SSL else 'http',
159
-            domain=cfg.RADICALE_CLIENT_HOST or request.domain,
160
-            port=cfg.RADICALE_CLIENT_PORT,
161
-            id=self.user_id,
162
-            extra='#' + slugify(self.get_display_name(
163
-                remove_email_part=True
164
-            ), only_ascii=True)
165
-        )
154
+        from tracim.lib.calendar import CalendarManager
155
+        calendar_manager = CalendarManager(None)
156
+
157
+        return calendar_manager.get_user_calendar_url(self.user_id)
166
 
158
 
167
     @classmethod
159
     @classmethod
168
     def by_email_address(cls, email):
160
     def by_email_address(cls, email):

+ 4 - 10
tracim/tracim/model/data.py 查看文件

70
     @property
70
     @property
71
     def calendar_url(self) -> str:
71
     def calendar_url(self) -> str:
72
         # TODO - 20160531 - Bastien: Cyclic import if import in top of file
72
         # TODO - 20160531 - Bastien: Cyclic import if import in top of file
73
-        from tracim.config.app_cfg import CFG
74
-        from tracim.lib.calendar import CALENDAR_WORKSPACE_URL_TEMPLATE
75
-        cfg = CFG.get_instance()
76
-        return CALENDAR_WORKSPACE_URL_TEMPLATE.format(
77
-            proto='https' if cfg.RADICALE_CLIENT_SSL else 'http',
78
-            domain=cfg.RADICALE_CLIENT_HOST or tg.request.domain,
79
-            port=cfg.RADICALE_CLIENT_PORT,
80
-            id=self.workspace_id,
81
-            extra='#' + slugify(self.label),
82
-        )
73
+        from tracim.lib.calendar import CalendarManager
74
+        calendar_manager = CalendarManager(None)
75
+
76
+        return calendar_manager.get_workspace_calendar_url(self.workspace_id)
83
 
77
 
84
     def get_user_role(self, user: User) -> int:
78
     def get_user_role(self, user: User) -> int:
85
         for role in user.roles:
79
         for role in user.roles: