Browse Source

Merge pull request #67 from buxx/66/dev/radicale_client_url

Tracim 8 years ago
parent
commit
3a99ddb8b1

+ 5 - 4
tracim/development.ini.base View File

@@ -169,6 +169,8 @@ website.treeview.content = all
169 169
 # The following base_url is used for links and icons
170 170
 # integrated in the email notifcations
171 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 175
 email.notification.activated = False
174 176
 email.notification.from = Tracim Notification <noreply@trac.im>
@@ -188,10 +190,9 @@ email.notification.smtp.password = your_smtp_password
188 190
 # radicale.server.port = 5232
189 191
 # radicale.server.ssl = false
190 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
+## url can be extended like http://127.0.0.1:5232/calendar
194
+## in this case, you have to create your own proxy behind this url.
195
+# radicale.client.base_url = http://127.0.0.1:5232
195 196
 
196 197
 #####
197 198
 #

+ 27 - 5
tracim/tracim/config/app_cfg.py View File

@@ -12,6 +12,7 @@ convert them into boolean, for example, you should use the
12 12
     setting = asbool(global_conf.get('the_setting'))
13 13
  
14 14
 """
15
+from urllib.parse import urlparse
15 16
 
16 17
 import tg
17 18
 from paste.deploy.converters import asbool
@@ -177,6 +178,16 @@ class CFG(object):
177 178
         self.WEBSITE_HOME_IMAGE_URL = tg.lurl('/assets/img/home_illustration.jpg')
178 179
         self.WEBSITE_HOME_BACKGROUND_IMAGE_URL = tg.lurl('/assets/img/bg.jpg')
179 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
185
+            logger.warning(
186
+                self,
187
+                'NOTE: Generated website.server_name parameter from '
188
+                'website.base_url parameter -> {0}'
189
+                .format(self.WEBSITE_SERVER_NAME)
190
+            )
180 191
 
181 192
         self.WEBSITE_HOME_TAG_LINE = tg.config.get('website.home.tag_line', '')
182 193
         self.WEBSITE_SUBTITLE = tg.config.get('website.home.subtitle', '')
@@ -227,11 +238,22 @@ class CFG(object):
227 238
             '~/.config/radicale/collections'
228 239
         )
229 240
 
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
-
241
+        self.RADICALE_CLIENT_BASE_URL_TEMPLATE = \
242
+            tg.config.get('radicale.client.base_url', None)
243
+
244
+        if not self.RADICALE_CLIENT_BASE_URL_TEMPLATE:
245
+            self.RADICALE_CLIENT_BASE_URL_TEMPLATE = \
246
+                'http://{0}:{1}'.format(
247
+                    self.WEBSITE_SERVER_NAME,
248
+                    self.RADICALE_SERVER_PORT,
249
+                )
250
+            logger.warning(
251
+                self,
252
+                'NOTE: Generated radicale.client.base_url parameter with '
253
+                'followings parameters: website.server_name, '
254
+                'radicale.server.port -> {0}'
255
+                .format(self.RADICALE_CLIENT_BASE_URL_TEMPLATE)
256
+            )
235 257
 
236 258
     def get_tracker_js_content(self, js_tracker_file_path = None):
237 259
         js_tracker_file_path = tg.config.get('js_tracker_path', None)

+ 16 - 36
tracim/tracim/lib/calendar.py View File

@@ -1,3 +1,5 @@
1
+import os
2
+
1 3
 import re
2 4
 import transaction
3 5
 
@@ -24,50 +26,28 @@ CALENDAR_WORKSPACE_PATH_RE = 'workspace\/([0-9]+).ics'
24 26
 CALENDAR_TYPE_USER = UserCalendar
25 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 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 36
         from tracim.config.app_cfg import CFG
49 37
         cfg = CFG.get_instance()
38
+        return cfg.RADICALE_CLIENT_BASE_URL_TEMPLATE
50 39
 
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,
57
-        )
58
-
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()
40
+    @classmethod
41
+    def get_user_calendar_url(cls, user_id: int):
42
+        user_path = CALENDAR_USER_URL_TEMPLATE.format(id=str(user_id))
43
+        return os.path.join(cls.get_base_url(), user_path)
63 44
 
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,
45
+    @classmethod
46
+    def get_workspace_calendar_url(cls, workspace_id: int):
47
+        workspace_path = CALENDAR_WORKSPACE_URL_TEMPLATE.format(
48
+            id=str(workspace_id)
70 49
         )
50
+        return os.path.join(cls.get_base_url(), workspace_path)
71 51
 
72 52
     def __init__(self, user: User):
73 53
         self._user = user

+ 4 - 12
tracim/tracim/model/auth.py View File

@@ -151,18 +151,10 @@ class User(DeclarativeBase):
151 151
     @property
152 152
     def calendar_url(self) -> str:
153 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 159
     @classmethod
168 160
     def by_email_address(cls, email):

+ 4 - 10
tracim/tracim/model/data.py View File

@@ -70,16 +70,10 @@ class Workspace(DeclarativeBase):
70 70
     @property
71 71
     def calendar_url(self) -> str:
72 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 78
     def get_user_role(self, user: User) -> int:
85 79
         for role in user.roles: