Browse Source

CFG object is now accessible with self.app_config, config is now param of ContentApi + add Minimal notification code

Guénaël Muller 7 years ago
parent
commit
567ba060e3

+ 5 - 4
tracim/config.py View File

1
 # -*- coding: utf-8 -*-
1
 # -*- coding: utf-8 -*-
2
 from urllib.parse import urlparse
2
 from urllib.parse import urlparse
3
+from paste.deploy.converters import asbool
3
 from tracim.lib.utils.logger import logger
4
 from tracim.lib.utils.logger import logger
4
 from depot.manager import DepotManager
5
 from depot.manager import DepotManager
5
 
6
 
8
 
9
 
9
 class RequestWithCFG(Request):
10
 class RequestWithCFG(Request):
10
 
11
 
11
-    def config(self):
12
+    def app_config(self):
12
         cfg = CFG(self.registry.settings)
13
         cfg = CFG(self.registry.settings)
13
         cfg.configure_filedepot()
14
         cfg.configure_filedepot()
14
         return cfg
15
         return cfg
201
         #     'email.notification.processing_mode',
202
         #     'email.notification.processing_mode',
202
         # )
203
         # )
203
         #
204
         #
204
-        # self.EMAIL_NOTIFICATION_ACTIVATED = asbool(settings.get(
205
-        #     'email.notification.activated',
206
-        # ))
205
+        self.EMAIL_NOTIFICATION_ACTIVATED = asbool(settings.get(
206
+            'email.notification.activated',
207
+        ))
207
         # self.EMAIL_NOTIFICATION_SMTP_SERVER = settings.get(
208
         # self.EMAIL_NOTIFICATION_SMTP_SERVER = settings.get(
208
         #     'email.notification.smtp.server',
209
         #     'email.notification.smtp.server',
209
         # )
210
         # )

+ 13 - 10
tracim/lib/core/content.py View File

30
 from sqlalchemy import or_
30
 from sqlalchemy import or_
31
 from sqlalchemy.sql.elements import and_
31
 from sqlalchemy.sql.elements import and_
32
 from tracim.lib.utils.utils import cmp_to_key
32
 from tracim.lib.utils.utils import cmp_to_key
33
-# from tracim.lib.notifications import NotifierFactory
33
+from tracim.lib.core.notifications import NotifierFactory
34
 from tracim.exceptions import SameValueError
34
 from tracim.exceptions import SameValueError
35
 from tracim.lib.utils.utils import current_date_for_filename
35
 from tracim.lib.utils.utils import current_date_for_filename
36
 from tracim.models.revision_protection import new_revision
36
 from tracim.models.revision_protection import new_revision
100
             self,
100
             self,
101
             session: Session,
101
             session: Session,
102
             current_user: typing.Optional[User],
102
             current_user: typing.Optional[User],
103
+            config,
103
             show_archived=False,
104
             show_archived=False,
104
             show_deleted=False,
105
             show_deleted=False,
105
             show_temporary=False,
106
             show_temporary=False,
109
     ):
110
     ):
110
         self._session = session
111
         self._session = session
111
         self._user = current_user
112
         self._user = current_user
113
+        self._config = config
112
         self._user_id = current_user.user_id if current_user else None
114
         self._user_id = current_user.user_id if current_user else None
113
         self._show_archived = show_archived
115
         self._show_archived = show_archived
114
         self._show_deleted = show_deleted
116
         self._show_deleted = show_deleted
1081
         if do_notify:
1083
         if do_notify:
1082
             self.do_notify(content)
1084
             self.do_notify(content)
1083
 
1085
 
1084
-    # TODO - G.M - 28-03-2018 - [Notification] Re-enable notification
1085
     def do_notify(self, content: Content):
1086
     def do_notify(self, content: Content):
1086
-         pass
1087
-    #     """
1088
-    #     Allow to force notification for a given content. By default, it is
1089
-    #     called during the .save() operation
1090
-    #     :param content:
1091
-    #     :return:
1092
-    #     """
1093
-    #     NotifierFactory.create(self._user).notify_content_update(content)
1087
+        """
1088
+        Allow to force notification for a given content. By default, it is
1089
+        called during the .save() operation
1090
+        :param content:
1091
+        :return:
1092
+        """
1093
+        NotifierFactory.create(
1094
+            self._config,
1095
+            self._user
1096
+        ).notify_content_update(content)
1094
 
1097
 
1095
     def get_keywords(self, search_string, search_string_separators=None) -> [str]:
1098
     def get_keywords(self, search_string, search_string_separators=None) -> [str]:
1096
         """
1099
         """

+ 45 - 0
tracim/lib/core/notifications.py View File

1
+# -*- coding: utf-8 -*-
2
+
3
+from tracim.lib.utils.logger import logger
4
+from tracim.models.auth import User
5
+from tracim.models.data import Content
6
+
7
+
8
+class INotifier(object):
9
+    """
10
+    Interface for Notifier instances
11
+    """
12
+    def __init__(self, config, current_user: User=None):
13
+        pass
14
+
15
+    def notify_content_update(self, content: Content):
16
+        raise NotImplementedError
17
+
18
+
19
+class NotifierFactory(object):
20
+
21
+    @classmethod
22
+    def create(cls, config, current_user: User=None) -> INotifier:
23
+        if not config.EMAIL_NOTIFICATION_ACTIVATED:
24
+            return DummyNotifier(config, current_user)
25
+        return EmailNotifier(config, current_user)
26
+
27
+
28
+class DummyNotifier(INotifier):
29
+    send_count = 0
30
+
31
+    def __init__(self, config, current_user: User=None):
32
+        INotifier.__init__(config, current_user)
33
+        logger.info(self, 'Instantiating Dummy Notifier')
34
+
35
+    def notify_content_update(self, content: Content):
36
+        type(self).send_count += 1
37
+        logger.info(
38
+            self,
39
+            'Fake notifier, do not send notification for update of content {}'.format(content.content_id)  # nopep8
40
+        )
41
+
42
+
43
+class EmailNotifier(INotifier):
44
+    # TODO - G.M [emailNotif] move and restore Email Notifier in another file.
45
+    pass

+ 2 - 1
tracim/tests/__init__.py View File

35
             'test', {'depot.backend': 'depot.io.memory.MemoryFileStorage'}
35
             'test', {'depot.backend': 'depot.io.memory.MemoryFileStorage'}
36
         )
36
         )
37
         settings = self.config.get_settings()
37
         settings = self.config.get_settings()
38
-
38
+        self.app_config = CFG(settings)
39
         from tracim.models import (
39
         from tracim.models import (
40
             get_engine,
40
             get_engine,
41
             get_session_factory,
41
             get_session_factory,
118
         content_api = ContentApi(
118
         content_api = ContentApi(
119
             current_user=None,
119
             current_user=None,
120
             session=self.session,
120
             session=self.session,
121
+            config=self.app_config,
121
         )
122
         )
122
         eq_(
123
         eq_(
123
             1,
124
             1,

+ 135 - 62
tracim/tests/library/test_content_api.py View File

105
     def test_delete(self):
105
     def test_delete(self):
106
         uapi = UserApi(
106
         uapi = UserApi(
107
             session=self.session,
107
             session=self.session,
108
-            config=CFG(self.config.get_settings()),
108
+            config=self.app_config,
109
             current_user=None,
109
             current_user=None,
110
         )
110
         )
111
         group_api = GroupApi(current_user=None,session=self.session)
111
         group_api = GroupApi(current_user=None,session=self.session)
122
         api = ContentApi(
122
         api = ContentApi(
123
             current_user=user,
123
             current_user=user,
124
             session=self.session,
124
             session=self.session,
125
+            config=self.app_config,
125
         )
126
         )
126
         item = api.create(ContentType.Folder, workspace, None,
127
         item = api.create(ContentType.Folder, workspace, None,
127
                           'not_deleted', True)
128
                           'not_deleted', True)
135
         user = uapi.get_one(uid)
136
         user = uapi.get_one(uid)
136
         workspace_api = WorkspaceApi(current_user=user, session=self.session)
137
         workspace_api = WorkspaceApi(current_user=user, session=self.session)
137
         workspace = workspace_api.get_one(wid)
138
         workspace = workspace_api.get_one(wid)
138
-        api = ContentApi(current_user=user, session=self.session)
139
+        api = ContentApi(
140
+            current_user=user,
141
+            session=self.session,
142
+            config=self.app_config,
143
+        )
139
         items = api.get_all(None, ContentType.Any, workspace)
144
         items = api.get_all(None, ContentType.Any, workspace)
140
         eq_(2, len(items))
145
         eq_(2, len(items))
141
 
146
 
154
         workspace = workspace_api.get_one(wid)
159
         workspace = workspace_api.get_one(wid)
155
         api = ContentApi(
160
         api = ContentApi(
156
             current_user=user, 
161
             current_user=user, 
157
-            session=self.session
162
+            session=self.session,
163
+            config=self.app_config,
158
         )
164
         )
159
         items = api.get_all(None, ContentType.Any, workspace)
165
         items = api.get_all(None, ContentType.Any, workspace)
160
         eq_(1, len(items))
166
         eq_(1, len(items))
167
         api = ContentApi(
173
         api = ContentApi(
168
             current_user=user,
174
             current_user=user,
169
             session=self.session,
175
             session=self.session,
170
-            show_deleted=True
176
+            config=self.app_config,
177
+            show_deleted=True,
171
         )
178
         )
172
         items = api.get_all(None, ContentType.Any, workspace)
179
         items = api.get_all(None, ContentType.Any, workspace)
173
         eq_(2, len(items))
180
         eq_(2, len(items))
175
     def test_archive(self):
182
     def test_archive(self):
176
         uapi = UserApi(
183
         uapi = UserApi(
177
             session=self.session,
184
             session=self.session,
178
-            config=CFG(self.config.get_settings()),
185
+            config=self.app_config,
179
             current_user=None,
186
             current_user=None,
180
         )
187
         )
181
         group_api = GroupApi(current_user=None, session=self.session)
188
         group_api = GroupApi(current_user=None, session=self.session)
193
         api = ContentApi(
200
         api = ContentApi(
194
             current_user=user,
201
             current_user=user,
195
             session=self.session,
202
             session=self.session,
203
+            config=self.app_config,
196
         )
204
         )
197
         item = api.create(ContentType.Folder, workspace, None,
205
         item = api.create(ContentType.Folder, workspace, None,
198
                           'not_archived', True)
206
                           'not_archived', True)
207
         api = ContentApi(
215
         api = ContentApi(
208
             session=self.session,
216
             session=self.session,
209
             current_user=user,
217
             current_user=user,
218
+            config=self.app_config,
210
         )
219
         )
211
 
220
 
212
         items = api.get_all(None, ContentType.Any, workspace)
221
         items = api.get_all(None, ContentType.Any, workspace)
227
         workspace = workspace_api.get_one(wid)
236
         workspace = workspace_api.get_one(wid)
228
         api = ContentApi(
237
         api = ContentApi(
229
             current_user=user, 
238
             current_user=user, 
230
-            session=self.session
239
+            session=self.session,
240
+            config=self.app_config,
231
         )
241
         )
232
 
242
 
233
         items = api.get_all(None, ContentType.Any, workspace)
243
         items = api.get_all(None, ContentType.Any, workspace)
240
         workspace = workspace_api.get_one(wid)
250
         workspace = workspace_api.get_one(wid)
241
         api = ContentApi(
251
         api = ContentApi(
242
             current_user=user,
252
             current_user=user,
243
-            session=self.session
253
+            session=self.session,
254
+            config=self.app_config,
244
         )
255
         )
245
 
256
 
246
         # Test that the item is still available if "show deleted" is activated
257
         # Test that the item is still available if "show deleted" is activated
247
         api = ContentApi(
258
         api = ContentApi(
248
             current_user=None,
259
             current_user=None,
249
             session=self.session,
260
             session=self.session,
250
-            show_archived=True
261
+            config=self.app_config,
262
+            show_archived=True,
251
         )
263
         )
252
         items = api.get_all(None, ContentType.Any, workspace)
264
         items = api.get_all(None, ContentType.Any, workspace)
253
         eq_(2, len(items))
265
         eq_(2, len(items))
255
     def test_get_all_with_filter(self):
267
     def test_get_all_with_filter(self):
256
         uapi = UserApi(
268
         uapi = UserApi(
257
             session=self.session,
269
             session=self.session,
258
-            config=CFG(self.config.get_settings()),
270
+            config=self.app_config,
259
             current_user=None,
271
             current_user=None,
260
         )
272
         )
261
         group_api = GroupApi(current_user=None, session=self.session)
273
         group_api = GroupApi(current_user=None, session=self.session)
279
         api = ContentApi(
291
         api = ContentApi(
280
             current_user=user,
292
             current_user=user,
281
             session=self.session,
293
             session=self.session,
294
+            config=self.app_config,
282
         )
295
         )
283
         item = api.create(ContentType.Folder, workspace, None,
296
         item = api.create(ContentType.Folder, workspace, None,
284
                           'thefolder', True)
297
                           'thefolder', True)
293
         workspace = workspace_api.get_one(wid)
306
         workspace = workspace_api.get_one(wid)
294
         api = ContentApi(
307
         api = ContentApi(
295
             current_user=user, 
308
             current_user=user, 
296
-            session=self.session
309
+            session=self.session,
310
+            config=self.app_config,
297
         )
311
         )
298
 
312
 
299
         items = api.get_all(None, ContentType.Any, workspace)
313
         items = api.get_all(None, ContentType.Any, workspace)
310
     def test_get_all_with_parent_id(self):
324
     def test_get_all_with_parent_id(self):
311
         uapi = UserApi(
325
         uapi = UserApi(
312
             session=self.session,
326
             session=self.session,
313
-            config=CFG(self.config.get_settings()),
327
+            config=self.app_config,
314
             current_user=None,
328
             current_user=None,
315
         )
329
         )
316
         group_api = GroupApi(current_user=None, session=self.session)
330
         group_api = GroupApi(current_user=None, session=self.session)
326
         ).create_workspace('test workspace', save_now=True)
340
         ).create_workspace('test workspace', save_now=True)
327
         api = ContentApi(
341
         api = ContentApi(
328
             current_user=user, 
342
             current_user=user, 
329
-            session=self.session
343
+            session=self.session,
344
+            config=self.app_config,
330
         )
345
         )
331
         item = api.create(
346
         item = api.create(
332
             ContentType.Folder,
347
             ContentType.Folder,
361
         workspace = workspace_api.get_one(wid)
376
         workspace = workspace_api.get_one(wid)
362
         api = ContentApi(
377
         api = ContentApi(
363
             current_user=user,
378
             current_user=user,
364
-            session=self.session
379
+            session=self.session,
380
+            config=self.app_config,
365
         )
381
         )
366
 
382
 
367
         items = api.get_all(None, ContentType.Any, workspace)
383
         items = api.get_all(None, ContentType.Any, workspace)
375
     def test_set_status_unknown_status(self):
391
     def test_set_status_unknown_status(self):
376
         uapi = UserApi(
392
         uapi = UserApi(
377
             session=self.session,
393
             session=self.session,
378
-            config=CFG(self.config.get_settings()),
394
+            config=self.app_config,
379
             current_user=None,
395
             current_user=None,
380
         )
396
         )
381
         group_api = GroupApi(
397
         group_api = GroupApi(
398
         )
414
         )
399
         api = ContentApi(
415
         api = ContentApi(
400
             current_user=user, 
416
             current_user=user, 
401
-            session=self.session
417
+            session=self.session,
418
+            config=self.app_config,
402
         )
419
         )
403
         c = api.create(ContentType.Folder, workspace, None, 'parent', True)
420
         c = api.create(ContentType.Folder, workspace, None, 'parent', True)
404
         with new_revision(
421
         with new_revision(
411
     def test_set_status_ok(self):
428
     def test_set_status_ok(self):
412
         uapi = UserApi(
429
         uapi = UserApi(
413
             session=self.session,
430
             session=self.session,
414
-            config=CFG(self.config.get_settings()),
431
+            config=self.app_config,
415
             current_user=None,
432
             current_user=None,
416
         )
433
         )
417
         group_api = GroupApi(
434
         group_api = GroupApi(
433
             save_now=True
450
             save_now=True
434
         )
451
         )
435
         api = ContentApi(
452
         api = ContentApi(
436
-            current_user=user, 
437
-            session=self.session
453
+            current_user=user,
454
+            session=self.session,
455
+            config=self.app_config,
438
         )
456
         )
439
         c = api.create(ContentType.Folder, workspace, None, 'parent', True)
457
         c = api.create(ContentType.Folder, workspace, None, 'parent', True)
440
         with new_revision(
458
         with new_revision(
452
     def test_create_comment_ok(self):
470
     def test_create_comment_ok(self):
453
         uapi = UserApi(
471
         uapi = UserApi(
454
             session=self.session,
472
             session=self.session,
455
-            config=CFG(self.config.get_settings()),
473
+            config=self.app_config,
456
             current_user=None,
474
             current_user=None,
457
         )
475
         )
458
         group_api = GroupApi(
476
         group_api = GroupApi(
476
 
494
 
477
         api = ContentApi(
495
         api = ContentApi(
478
             current_user=user,
496
             current_user=user,
479
-            session=self.session
497
+            session=self.session,
498
+            config=self.app_config,
480
         )
499
         )
481
         p = api.create(ContentType.Page, workspace, None, 'this_is_a_page')
500
         p = api.create(ContentType.Page, workspace, None, 'this_is_a_page')
482
         c = api.create_comment(workspace, p, 'this is the comment', True)
501
         c = api.create_comment(workspace, p, 'this is the comment', True)
493
     def test_unit_copy_file_different_label_different_parent_ok(self):
512
     def test_unit_copy_file_different_label_different_parent_ok(self):
494
         uapi = UserApi(
513
         uapi = UserApi(
495
             session=self.session,
514
             session=self.session,
496
-            config=CFG(self.config.get_settings()),
515
+            config=self.app_config,
497
             current_user=None,
516
             current_user=None,
498
         )
517
         )
499
         group_api = GroupApi(
518
         group_api = GroupApi(
529
         )
548
         )
530
         api = ContentApi(
549
         api = ContentApi(
531
             current_user=user,
550
             current_user=user,
532
-            session=self.session
551
+            session=self.session,
552
+            config=self.app_config,
533
         )
553
         )
534
         foldera = api.create(
554
         foldera = api.create(
535
             ContentType.Folder,
555
             ContentType.Folder,
554
             )
574
             )
555
 
575
 
556
         api.save(text_file, ActionDescription.CREATION)
576
         api.save(text_file, ActionDescription.CREATION)
557
-        api2 = ContentApi(current_user=user2, session=self.session)
577
+        api2 = ContentApi(
578
+            current_user=user2,
579
+            session=self.session,
580
+            config=self.app_config,
581
+        )
558
         workspace2 = WorkspaceApi(
582
         workspace2 = WorkspaceApi(
559
             current_user=user2,
583
             current_user=user2,
560
             session=self.session,
584
             session=self.session,
600
     def test_unit_copy_file__same_label_different_parent_ok(self):
624
     def test_unit_copy_file__same_label_different_parent_ok(self):
601
         uapi = UserApi(
625
         uapi = UserApi(
602
             session=self.session,
626
             session=self.session,
603
-            config=CFG(self.config.get_settings()),
627
+            config=self.app_config,
604
             current_user=None,
628
             current_user=None,
605
         )
629
         )
606
         group_api = GroupApi(
630
         group_api = GroupApi(
636
         )
660
         )
637
         api = ContentApi(
661
         api = ContentApi(
638
             current_user=user,
662
             current_user=user,
639
-            session=self.session
663
+            session=self.session,
664
+            config=self.app_config,
640
         )
665
         )
641
         foldera = api.create(
666
         foldera = api.create(
642
             ContentType.Folder,
667
             ContentType.Folder,
664
         api2 = ContentApi(
689
         api2 = ContentApi(
665
             current_user=user2,
690
             current_user=user2,
666
             session=self.session,
691
             session=self.session,
692
+            config=self.app_config,
667
         )
693
         )
668
         workspace2 = WorkspaceApi(
694
         workspace2 = WorkspaceApi(
669
             current_user=user2,
695
             current_user=user2,
708
     def test_unit_copy_file_different_label_same_parent_ok(self):
734
     def test_unit_copy_file_different_label_same_parent_ok(self):
709
         uapi = UserApi(
735
         uapi = UserApi(
710
             session=self.session,
736
             session=self.session,
711
-            config=CFG(self.config.get_settings()),
737
+            config=self.app_config,
712
             current_user=None,
738
             current_user=None,
713
         )
739
         )
714
         group_api = GroupApi(
740
         group_api = GroupApi(
743
         )
769
         )
744
         api = ContentApi(
770
         api = ContentApi(
745
             current_user=user,
771
             current_user=user,
746
-            session=self.session
772
+            session=self.session,
773
+            config=self.app_config,
747
         )
774
         )
748
         foldera = api.create(
775
         foldera = api.create(
749
             ContentType.Folder,
776
             ContentType.Folder,
771
             text_file,
798
             text_file,
772
             ActionDescription.CREATION
799
             ActionDescription.CREATION
773
         )
800
         )
774
-        api2 = ContentApi(current_user=user2, session=self.session)
801
+        api2 = ContentApi(
802
+            current_user=user2,
803
+            session=self.session,
804
+            config=self.app_config,
805
+        )
775
 
806
 
776
         api2.copy(
807
         api2.copy(
777
             item=text_file,
808
             item=text_file,
802
     def test_mark_read__workspace(self):
833
     def test_mark_read__workspace(self):
803
         uapi = UserApi(
834
         uapi = UserApi(
804
             session=self.session,
835
             session=self.session,
805
-            config=CFG(self.config.get_settings()),
836
+            config=self.app_config,
806
             current_user=None,
837
             current_user=None,
807
         )
838
         )
808
         group_api = GroupApi(
839
         group_api = GroupApi(
850
         cont_api_a = ContentApi(
881
         cont_api_a = ContentApi(
851
             current_user=user_a,
882
             current_user=user_a,
852
             session=self.session,
883
             session=self.session,
884
+            config=self.app_config,
853
         )
885
         )
854
         cont_api_b = ContentApi(
886
         cont_api_b = ContentApi(
855
             current_user=user_b,
887
             current_user=user_b,
856
             session=self.session,
888
             session=self.session,
889
+            config=self.app_config,
857
         )
890
         )
858
 
891
 
859
         # Creates page_1 & page_2 in workspace 1
892
         # Creates page_1 & page_2 in workspace 1
903
     def test_mark_read(self):
936
     def test_mark_read(self):
904
         uapi = UserApi(
937
         uapi = UserApi(
905
             session=self.session,
938
             session=self.session,
906
-            config=CFG(self.config.get_settings()),
939
+            config=self.app_config,
907
             current_user=None,
940
             current_user=None,
908
         )
941
         )
909
         group_api = GroupApi(
942
         group_api = GroupApi(
947
         cont_api_a = ContentApi(
980
         cont_api_a = ContentApi(
948
             current_user=user_a,
981
             current_user=user_a,
949
             session=self.session,
982
             session=self.session,
983
+            config=self.app_config,
950
         )
984
         )
951
         cont_api_b = ContentApi(
985
         cont_api_b = ContentApi(
952
             current_user=user_b,
986
             current_user=user_b,
953
             session=self.session,
987
             session=self.session,
988
+            config=self.app_config,
954
         )
989
         )
955
 
990
 
956
         page_1 = cont_api_a.create(ContentType.Page, workspace, None,
991
         page_1 = cont_api_a.create(ContentType.Page, workspace, None,
967
     def test_mark_read__all(self):
1002
     def test_mark_read__all(self):
968
         uapi = UserApi(
1003
         uapi = UserApi(
969
             session=self.session,
1004
             session=self.session,
970
-            config=CFG(self.config.get_settings()),
1005
+            config=self.app_config,
971
             current_user=None,
1006
             current_user=None,
972
         )
1007
         )
973
         group_api = GroupApi(current_user=None, session=self.session)
1008
         group_api = GroupApi(current_user=None, session=self.session)
1007
         cont_api_a = ContentApi(
1042
         cont_api_a = ContentApi(
1008
             current_user=user_a,
1043
             current_user=user_a,
1009
             session=self.session,
1044
             session=self.session,
1045
+            config=self.app_config,
1010
         )
1046
         )
1011
         cont_api_b = ContentApi(
1047
         cont_api_b = ContentApi(
1012
             current_user=user_b,
1048
             current_user=user_b,
1013
             session=self.session,
1049
             session=self.session,
1050
+            config=self.app_config,
1014
         )
1051
         )
1015
 
1052
 
1016
         page_2 = cont_api_a.create(
1053
         page_2 = cont_api_a.create(
1058
     def test_update(self):
1095
     def test_update(self):
1059
         uapi = UserApi(
1096
         uapi = UserApi(
1060
             session=self.session,
1097
             session=self.session,
1061
-            config=CFG(self.config.get_settings()),
1098
+            config=self.app_config,
1062
             current_user=None,
1099
             current_user=None,
1063
         )
1100
         )
1064
         group_api = GroupApi(current_user=None, session=self.session)
1101
         group_api = GroupApi(current_user=None, session=self.session)
1100
         api = ContentApi(
1137
         api = ContentApi(
1101
             current_user=user1,
1138
             current_user=user1,
1102
             session=self.session,
1139
             session=self.session,
1140
+            config=self.app_config,
1103
         )
1141
         )
1104
 
1142
 
1105
         p = api.create(ContentType.Page, workspace, None,
1143
         p = api.create(ContentType.Page, workspace, None,
1121
         api = ContentApi(
1159
         api = ContentApi(
1122
             current_user=user1,
1160
             current_user=user1,
1123
             session=self.session,
1161
             session=self.session,
1162
+            config=self.app_config,
1124
         )
1163
         )
1125
 
1164
 
1126
         content = api.get_one(pcid, ContentType.Any, workspace)
1165
         content = api.get_one(pcid, ContentType.Any, workspace)
1129
 
1168
 
1130
         u2 = UserApi(
1169
         u2 = UserApi(
1131
             session=self.session,
1170
             session=self.session,
1132
-            config=self.config,
1171
+            config=self.app_config,
1133
             current_user=None,
1172
             current_user=None,
1134
         ).get_one(u2id)
1173
         ).get_one(u2id)
1135
         api2 = ContentApi(
1174
         api2 = ContentApi(
1136
             current_user=u2,
1175
             current_user=u2,
1137
             session=self.session,
1176
             session=self.session,
1177
+            config=self.app_config,
1138
         )
1178
         )
1139
         content2 = api2.get_one(pcid, ContentType.Any, workspace)
1179
         content2 = api2.get_one(pcid, ContentType.Any, workspace)
1140
         with new_revision(
1180
         with new_revision(
1159
         api = ContentApi(
1199
         api = ContentApi(
1160
             current_user=user1,
1200
             current_user=user1,
1161
             session=self.session,
1201
             session=self.session,
1202
+            config=self.app_config,
1162
         )
1203
         )
1163
 
1204
 
1164
         updated = api.get_one(pcid, ContentType.Any, workspace)
1205
         updated = api.get_one(pcid, ContentType.Any, workspace)
1173
     def test_update_no_change(self):
1214
     def test_update_no_change(self):
1174
         uapi = UserApi(
1215
         uapi = UserApi(
1175
             session=self.session,
1216
             session=self.session,
1176
-            config=CFG(self.config.get_settings()),
1217
+            config=self.app_config,
1177
             current_user=None,
1218
             current_user=None,
1178
         )
1219
         )
1179
         group_api = GroupApi(
1220
         group_api = GroupApi(
1214
         )
1255
         )
1215
         api = ContentApi(
1256
         api = ContentApi(
1216
             current_user=user1,
1257
             current_user=user1,
1217
-            session=self.session
1258
+            session=self.session,
1259
+            config=self.app_config,
1218
         )
1260
         )
1219
         with self.session.no_autoflush:
1261
         with self.session.no_autoflush:
1220
             page = api.create(
1262
             page = api.create(
1230
         api2 = ContentApi(
1272
         api2 = ContentApi(
1231
             current_user=user2,
1273
             current_user=user2,
1232
             session=self.session,
1274
             session=self.session,
1275
+            config=self.app_config,
1233
         )
1276
         )
1234
         content2 = api2.get_one(page.content_id, ContentType.Any, workspace)
1277
         content2 = api2.get_one(page.content_id, ContentType.Any, workspace)
1235
         with new_revision(
1278
         with new_revision(
1248
     def test_update_file_data(self):
1291
     def test_update_file_data(self):
1249
         uapi = UserApi(
1292
         uapi = UserApi(
1250
             session=self.session,
1293
             session=self.session,
1251
-            config=CFG(self.config.get_settings()),
1294
+            config=self.app_config,
1252
             current_user=None,
1295
             current_user=None,
1253
         )
1296
         )
1254
         group_api = GroupApi(
1297
         group_api = GroupApi(
1290
         # Test starts here
1333
         # Test starts here
1291
         api = ContentApi(
1334
         api = ContentApi(
1292
             current_user=user1,
1335
             current_user=user1,
1293
-            session=self.session
1336
+            session=self.session,
1337
+            config=self.app_config,
1294
         )
1338
         )
1295
         p = api.create(ContentType.File, workspace, None,
1339
         p = api.create(ContentType.File, workspace, None,
1296
                        'this_is_a_page', True)
1340
                        'this_is_a_page', True)
1307
         user1 = uapi.get_one(u1id)
1351
         user1 = uapi.get_one(u1id)
1308
         workspace_api2 = WorkspaceApi(current_user=user1, session=self.session)
1352
         workspace_api2 = WorkspaceApi(current_user=user1, session=self.session)
1309
         workspace = workspace_api2.get_one(wid)
1353
         workspace = workspace_api2.get_one(wid)
1310
-        api = ContentApi(current_user=user1, session=self.session)
1354
+        api = ContentApi(
1355
+            current_user=user1,
1356
+            session=self.session,
1357
+            config=self.app_config,
1358
+        )
1311
 
1359
 
1312
         content = api.get_one(pcid, ContentType.Any, workspace)
1360
         content = api.get_one(pcid, ContentType.Any, workspace)
1313
         eq_(u1id, content.owner_id)
1361
         eq_(u1id, content.owner_id)
1316
         u2 = UserApi(
1364
         u2 = UserApi(
1317
             current_user=None,
1365
             current_user=None,
1318
             session=self.session,
1366
             session=self.session,
1319
-            config=self.config,
1367
+            config=self.app_config,
1320
         ).get_one(u2id)
1368
         ).get_one(u2id)
1321
         api2 = ContentApi(
1369
         api2 = ContentApi(
1322
             current_user=u2,
1370
             current_user=u2,
1323
             session=self.session,
1371
             session=self.session,
1372
+            config=self.app_config,
1324
         )
1373
         )
1325
         content2 = api2.get_one(pcid, ContentType.Any, workspace)
1374
         content2 = api2.get_one(pcid, ContentType.Any, workspace)
1326
         with new_revision(
1375
         with new_revision(
1353
     def test_update_no_change(self):
1402
     def test_update_no_change(self):
1354
         uapi = UserApi(
1403
         uapi = UserApi(
1355
             session=self.session,
1404
             session=self.session,
1356
-            config=CFG(self.config.get_settings()),
1405
+            config=self.app_config,
1357
             current_user=None,
1406
             current_user=None,
1358
         )
1407
         )
1359
         group_api = GroupApi(
1408
         group_api = GroupApi(
1390
             with_notif=False,
1439
             with_notif=False,
1391
             flush=True
1440
             flush=True
1392
         )
1441
         )
1393
-        api = ContentApi(current_user=user1, session=self.session)
1442
+        api = ContentApi(
1443
+            current_user=user1,
1444
+            session=self.session,
1445
+            config=self.app_config,
1446
+        )
1394
         with self.session.no_autoflush:
1447
         with self.session.no_autoflush:
1395
             page = api.create(
1448
             page = api.create(
1396
                 content_type=ContentType.Page,
1449
                 content_type=ContentType.Page,
1407
         api.save(page, ActionDescription.CREATION, do_notify=True)
1460
         api.save(page, ActionDescription.CREATION, do_notify=True)
1408
         transaction.commit()
1461
         transaction.commit()
1409
 
1462
 
1410
-        api2 = ContentApi(current_user=user2, session=self.session)
1463
+        api2 = ContentApi(
1464
+            current_user=user2,
1465
+            session=self.session,
1466
+            config=self.app_config,
1467
+        )
1411
         content2 = api2.get_one(page.content_id, ContentType.Any, workspace)
1468
         content2 = api2.get_one(page.content_id, ContentType.Any, workspace)
1412
         with new_revision(
1469
         with new_revision(
1413
             session=self.session,
1470
             session=self.session,
1426
     def test_archive_unarchive(self):
1483
     def test_archive_unarchive(self):
1427
         uapi = UserApi(
1484
         uapi = UserApi(
1428
             session=self.session,
1485
             session=self.session,
1429
-            config=CFG(self.config.get_settings()),
1486
+            config=self.app_config,
1430
             current_user=None,
1487
             current_user=None,
1431
         )
1488
         )
1432
         group_api = GroupApi(current_user=None, session=self.session)
1489
         group_api = GroupApi(current_user=None, session=self.session)
1468
             current_user=user1,
1525
             current_user=user1,
1469
             session=self.session,
1526
             session=self.session,
1470
             show_archived=True,
1527
             show_archived=True,
1528
+            config=self.app_config,
1471
         )
1529
         )
1472
         p = api.create(ContentType.File, workspace, None,
1530
         p = api.create(ContentType.File, workspace, None,
1473
                        'this_is_a_page', True)
1531
                        'this_is_a_page', True)
1484
         # refresh after commit
1542
         # refresh after commit
1485
         user1 = UserApi(
1543
         user1 = UserApi(
1486
             current_user=None,
1544
             current_user=None,
1487
-            config=self.config,
1545
+            config=self.app_config,
1488
             session=self.session
1546
             session=self.session
1489
         ).get_one(u1id)
1547
         ).get_one(u1id)
1490
         workspace = WorkspaceApi(
1548
         workspace = WorkspaceApi(
1498
 
1556
 
1499
         u2api = UserApi(
1557
         u2api = UserApi(
1500
             session=self.session,
1558
             session=self.session,
1501
-            config=CFG(self.config.get_settings()),
1559
+            config=self.app_config,
1502
             current_user=None,
1560
             current_user=None,
1503
         )
1561
         )
1504
         u2 = u2api.get_one(u2id)
1562
         u2 = u2api.get_one(u2id)
1505
         api2 = ContentApi(
1563
         api2 = ContentApi(
1506
             current_user=u2,
1564
             current_user=u2,
1507
             session=self.session,
1565
             session=self.session,
1508
-            show_archived=True
1566
+            config=self.app_config,
1567
+            show_archived=True,
1509
         )
1568
         )
1510
         content2 = api2.get_one(pcid, ContentType.Any, workspace)
1569
         content2 = api2.get_one(pcid, ContentType.Any, workspace)
1511
         with new_revision(
1570
         with new_revision(
1521
         user1 = UserApi(
1580
         user1 = UserApi(
1522
             current_user=None,
1581
             current_user=None,
1523
             session=self.session,
1582
             session=self.session,
1524
-            config=self.config,
1583
+            config=self.app_config,
1525
         ).get_one(u1id)
1584
         ).get_one(u1id)
1526
         workspace = WorkspaceApi(
1585
         workspace = WorkspaceApi(
1527
             current_user=user1,
1586
             current_user=user1,
1530
         u2 = UserApi(
1589
         u2 = UserApi(
1531
             current_user=None,
1590
             current_user=None,
1532
             session=self.session,
1591
             session=self.session,
1533
-            config=self.config
1592
+            config=self.app_config,
1534
         ).get_one(u2id)
1593
         ).get_one(u2id)
1535
         api = ContentApi(
1594
         api = ContentApi(
1536
             current_user=user1,
1595
             current_user=user1,
1537
             session=self.session,
1596
             session=self.session,
1597
+            config=self.app_config,
1538
             show_archived=True,
1598
             show_archived=True,
1539
         )
1599
         )
1540
         api2 = ContentApi(
1600
         api2 = ContentApi(
1541
             current_user=u2,
1601
             current_user=u2,
1542
             session=self.session,
1602
             session=self.session,
1603
+            config=self.app_config,
1543
             show_archived=True,
1604
             show_archived=True,
1544
         )
1605
         )
1545
 
1606
 
1568
     def test_delete_undelete(self):
1629
     def test_delete_undelete(self):
1569
         uapi = UserApi(
1630
         uapi = UserApi(
1570
             session=self.session,
1631
             session=self.session,
1571
-            config=CFG(self.config.get_settings()),
1632
+            config=self.app_config,
1572
             current_user=None,
1633
             current_user=None,
1573
         )
1634
         )
1574
         group_api = GroupApi(
1635
         group_api = GroupApi(
1612
         api = ContentApi(
1673
         api = ContentApi(
1613
             current_user=user1,
1674
             current_user=user1,
1614
             session=self.session,
1675
             session=self.session,
1676
+            config=self.app_config,
1615
             show_deleted=True,
1677
             show_deleted=True,
1616
         )
1678
         )
1617
         p = api.create(ContentType.File, workspace, None,
1679
         p = api.create(ContentType.File, workspace, None,
1628
         user1 = UserApi(
1690
         user1 = UserApi(
1629
             current_user=None,
1691
             current_user=None,
1630
             session=self.session,
1692
             session=self.session,
1631
-            config=self.config,
1693
+            config=self.app_config,
1632
         ).get_one(u1id)
1694
         ).get_one(u1id)
1633
         workspace = WorkspaceApi(
1695
         workspace = WorkspaceApi(
1634
             current_user=user1,
1696
             current_user=user1,
1642
         u2 = UserApi(
1704
         u2 = UserApi(
1643
             current_user=None,
1705
             current_user=None,
1644
             session=self.session,
1706
             session=self.session,
1645
-            config=self.config,
1707
+            config=self.app_config,
1646
         ).get_one(u2id)
1708
         ).get_one(u2id)
1647
         api2 = ContentApi(
1709
         api2 = ContentApi(
1648
             current_user=u2,
1710
             current_user=u2,
1649
             session=self.session,
1711
             session=self.session,
1712
+            config=self.app_config,
1650
             show_deleted=True,
1713
             show_deleted=True,
1651
         )
1714
         )
1652
         content2 = api2.get_one(pcid, ContentType.Any, workspace)
1715
         content2 = api2.get_one(pcid, ContentType.Any, workspace)
1664
         user1 = UserApi(
1727
         user1 = UserApi(
1665
             current_user=None,
1728
             current_user=None,
1666
             session=self.session,
1729
             session=self.session,
1667
-            config=self.config,
1730
+            config=self.app_config,
1668
         ).get_one(u1id)
1731
         ).get_one(u1id)
1669
         workspace = WorkspaceApi(
1732
         workspace = WorkspaceApi(
1670
             current_user=user1,
1733
             current_user=user1,
1674
         api = ContentApi(
1737
         api = ContentApi(
1675
             current_user=user1,
1738
             current_user=user1,
1676
             session=self.session,
1739
             session=self.session,
1740
+            config=self.app_config,
1677
             show_deleted=True,
1741
             show_deleted=True,
1678
         )
1742
         )
1679
         u2 = UserApi(
1743
         u2 = UserApi(
1680
             current_user=None,
1744
             current_user=None,
1681
             session=self.session,
1745
             session=self.session,
1682
-            config=self.config,
1746
+            config=self.app_config,
1683
         ).get_one(u2id)
1747
         ).get_one(u2id)
1684
         api2 = ContentApi(
1748
         api2 = ContentApi(
1685
             current_user=u2,
1749
             current_user=u2,
1686
             session=self.session,
1750
             session=self.session,
1751
+            config=self.app_config,
1687
             show_deleted=True
1752
             show_deleted=True
1688
         )
1753
         )
1689
 
1754
 
1714
         # at root of a workspace (eg a folder)
1779
         # at root of a workspace (eg a folder)
1715
         uapi = UserApi(
1780
         uapi = UserApi(
1716
             session=self.session,
1781
             session=self.session,
1717
-            config=CFG(self.config.get_settings()),
1782
+            config=self.app_config,
1718
             current_user=None,
1783
             current_user=None,
1719
         )
1784
         )
1720
         group_api = GroupApi(
1785
         group_api = GroupApi(
1738
 
1803
 
1739
         api = ContentApi(
1804
         api = ContentApi(
1740
             current_user=user, 
1805
             current_user=user, 
1741
-            session=self.session
1806
+            session=self.session,
1807
+            config=self.app_config,
1808
+
1742
         )
1809
         )
1743
         a = api.create(ContentType.Folder, workspace, None,
1810
         a = api.create(ContentType.Folder, workspace, None,
1744
                        'this is randomized folder', True)
1811
                        'this is randomized folder', True)
1767
 
1834
 
1768
         uapi = UserApi(
1835
         uapi = UserApi(
1769
             session=self.session,
1836
             session=self.session,
1770
-            config=CFG(self.config.get_settings()),
1837
+            config=self.app_config,
1771
             current_user=None,
1838
             current_user=None,
1772
         )
1839
         )
1773
         group_api = GroupApi(
1840
         group_api = GroupApi(
1791
 
1858
 
1792
         api = ContentApi(
1859
         api = ContentApi(
1793
             current_user=user, 
1860
             current_user=user, 
1794
-            session=self.session
1861
+            session=self.session,
1862
+            config=self.app_config,
1795
         )
1863
         )
1796
         a = api.create(ContentType.Folder, workspace, None,
1864
         a = api.create(ContentType.Folder, workspace, None,
1797
                        'this is randomized folder', True)
1865
                        'this is randomized folder', True)
1820
 
1888
 
1821
         uapi = UserApi(
1889
         uapi = UserApi(
1822
             session=self.session,
1890
             session=self.session,
1823
-            config=CFG(self.config.get_settings()),
1891
+            config=self.app_config,
1824
             current_user=None,
1892
             current_user=None,
1825
         )
1893
         )
1826
         group_api = GroupApi(current_user=None, session=self.session)
1894
         group_api = GroupApi(current_user=None, session=self.session)
1838
 
1906
 
1839
         api = ContentApi(
1907
         api = ContentApi(
1840
             current_user=user, 
1908
             current_user=user, 
1841
-            session=self.session
1909
+            session=self.session,
1910
+            config=self.app_config,
1842
         )
1911
         )
1843
         a = api.create(ContentType.Folder, workspace, None,
1912
         a = api.create(ContentType.Folder, workspace, None,
1844
                        'this is randomized folder', True)
1913
                        'this is randomized folder', True)
1911
         api = ContentApi(
1980
         api = ContentApi(
1912
             current_user=admin,
1981
             current_user=admin,
1913
             session=self.session,
1982
             session=self.session,
1983
+            config=self.app_config,
1914
         )
1984
         )
1915
 
1985
 
1916
         foo_result = api.search(['foo']).all()
1986
         foo_result = api.search(['foo']).all()
1979
 
2049
 
1980
         bob_page = ContentApi(
2050
         bob_page = ContentApi(
1981
             current_user=bob,
2051
             current_user=bob,
1982
-            session=self.session
2052
+            session=self.session,
2053
+            config=self.app_config,
1983
         ).create(
2054
         ).create(
1984
             content_type=ContentType.Page,
2055
             content_type=ContentType.Page,
1985
             workspace=bob_workspace,
2056
             workspace=bob_workspace,
1989
 
2060
 
1990
         admin_page = ContentApi(
2061
         admin_page = ContentApi(
1991
             current_user=admin,
2062
             current_user=admin,
1992
-            session=self.session
2063
+            session=self.session,
2064
+            config=self.app_config,
1993
         ).create(
2065
         ).create(
1994
             content_type=ContentType.Page,
2066
             content_type=ContentType.Page,
1995
             workspace=admin_workspace,
2067
             workspace=admin_workspace,
1999
 
2071
 
2000
         bob_viewable = ContentApi(
2072
         bob_viewable = ContentApi(
2001
             current_user=bob,
2073
             current_user=bob,
2002
-            session=self.session
2074
+            session=self.session,
2075
+            config=self.app_config,
2003
         ).get_all()
2076
         ).get_all()
2004
         eq_(1, len(bob_viewable), 'Bob should view only one content')
2077
         eq_(1, len(bob_viewable), 'Bob should view only one content')
2005
         eq_(
2078
         eq_(

+ 41 - 0
tracim/tests/library/test_notification.py View File

1
+# -*- coding: utf-8 -*-
2
+import os
3
+import re
4
+
5
+from nose.tools import eq_
6
+from nose.tools import ok_
7
+
8
+from tracim.lib.core.notifications import DummyNotifier
9
+from tracim.lib.core.notifications import EmailNotifier
10
+from tracim.lib.core.notifications import NotifierFactory
11
+from tracim.models.auth import User
12
+from tracim.models.data import Content
13
+from tracim.tests import DefaultTest
14
+
15
+
16
+class TestDummyNotifier(DefaultTest):
17
+
18
+    def test_dummy_notifier__notify_content_update(self):
19
+        c = Content()
20
+        notifier = DummyNotifier(self.app_config)
21
+        notifier.notify_content_update(c)
22
+        # INFO - D.A. - 2014-12-09 -
23
+        # Old notification_content_update raised an exception
24
+
25
+
26
+class TestNotifierFactory(DefaultTest):
27
+    def test_notifier_factory_method(self):
28
+        u = User()
29
+
30
+        self.app_config.EMAIL_NOTIFICATION_ACTIVATED = True
31
+        notifier = NotifierFactory.create(self.app_config, u)
32
+        eq_(EmailNotifier, notifier.__class__)
33
+
34
+        self.app_config.EMAIL_NOTIFICATION_ACTIVATED = False
35
+        notifier = NotifierFactory.create(self.app_config, u)
36
+        eq_(DummyNotifier, notifier.__class__)
37
+
38
+
39
+class TestEmailNotifier(DefaultTest):
40
+    # TODO - G.M - 04-03-2017 -  [emailNotif] - Restore test for email Notif
41
+    pass

+ 1 - 0
tracim/tests/library/test_workspace.py View File

33
         content_api = ContentApi(
33
         content_api = ContentApi(
34
             session=self.session,
34
             session=self.session,
35
             current_user=admin,
35
             current_user=admin,
36
+            config=self.app_config,
36
         )
37
         )
37
         folder = content_api.get_canonical_query().filter(
38
         folder = content_api.get_canonical_query().filter(
38
             Content.label == 'folder_1'
39
             Content.label == 'folder_1'

+ 5 - 1
tracim/tests/models/test_content.py View File

88
         user_admin = self.session.query(User)\
88
         user_admin = self.session.query(User)\
89
             .filter(User.email == 'admin@admin.admin').one()
89
             .filter(User.email == 'admin@admin.admin').one()
90
 
90
 
91
-        api = ContentApi(current_user=None, session=self.session)
91
+        api = ContentApi(
92
+            current_user=None,
93
+            session=self.session,
94
+            config=self.app_config,
95
+        )
92
 
96
 
93
         content1_from_api = api.get_one(
97
         content1_from_api = api.get_one(
94
             content1.id,
98
             content1.id,

+ 2 - 3
tracim/views/default.py View File

10
 @view_config(route_name='home', renderer='../templates/mytemplate.jinja2')
10
 @view_config(route_name='home', renderer='../templates/mytemplate.jinja2')
11
 def test_config(request):
11
 def test_config(request):
12
     try:
12
     try:
13
-        project = request.config().WEBSITE_TITLE
13
+        project = request.app_config().WEBSITE_TITLE
14
     except Exception as e:
14
     except Exception as e:
15
         return Response(e, content_type='text/plain', status=500)
15
         return Response(e, content_type='text/plain', status=500)
16
     return {'project': project}
16
     return {'project': project}
17
 
17
 
18
 # @view_config(route_name='home', renderer='../templates/mytemplate.jinja2')
18
 # @view_config(route_name='home', renderer='../templates/mytemplate.jinja2')
19
 # def my_view(request):
19
 # def my_view(request):
20
-#     try:
21
-#         query = request.dbsession.query(MyModel)
20
+#     try:#         query = request.dbsession.query(MyModel)
22
 #         one = query.filter(MyModel.name == 'one').first()
21
 #         one = query.filter(MyModel.name == 'one').first()
23
 #     except DBAPIError:
22
 #     except DBAPIError:
24
 #         return Response(db_err_msg, content_type='text/plain', status=500)
23
 #         return Response(db_err_msg, content_type='text/plain', status=500)