forked from openwisp/openwisp-notifications
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[feature] Added general setting to disable all notifications openwisp…
…#148 closes openwisp#148
- Loading branch information
1 parent
19bf2ed
commit 2500dc9
Showing
9 changed files
with
204 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
# Generated by Django 3.1.4 on 2020-12-24 08:43 | ||
|
||
import uuid | ||
|
||
import django.db.models.deletion | ||
from django.conf import settings | ||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
migrations.swappable_dependency(settings.AUTH_USER_MODEL), | ||
('openwisp_notifications', '0006_objectnotification'), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='GeneralSetting', | ||
fields=[ | ||
( | ||
'id', | ||
models.UUIDField( | ||
default=uuid.uuid4, | ||
editable=False, | ||
primary_key=True, | ||
serialize=False, | ||
), | ||
), | ||
( | ||
'web', | ||
models.BooleanField( | ||
blank=True, | ||
help_text='Note: If Yes is selected, User will not recieve any notifications. ', | ||
null=True, | ||
verbose_name='disable web notifications', | ||
), | ||
), | ||
( | ||
'email', | ||
models.BooleanField( | ||
blank=True, | ||
help_text='Note: If Yes is selected, User will not recieve any notifications. ', | ||
null=True, | ||
verbose_name='disable email notifications', | ||
), | ||
), | ||
( | ||
'user', | ||
models.OneToOneField( | ||
on_delete=django.db.models.deletion.CASCADE, | ||
to=settings.AUTH_USER_MODEL, | ||
), | ||
), | ||
], | ||
options={ | ||
'verbose_name': 'general settings', | ||
'verbose_name_plural': 'general settings', | ||
'ordering': ['user'], | ||
'abstract': False, | ||
'swappable': 'OPENWISP_NOTIFICATIONS_GENERALSETTING_MODEL', | ||
}, | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
from django.test import TestCase | ||
|
||
from openwisp_notifications.signals import notify | ||
from openwisp_notifications.swapper import load_model | ||
from openwisp_users.tests.utils import TestOrganizationMixin | ||
|
||
GeneralSetting = load_model('GeneralSetting') | ||
Notification = load_model('Notification') | ||
on_queryset = Notification.objects | ||
|
||
|
||
class TestDisableNotifications(TestOrganizationMixin, TestCase): | ||
def setUp(self): | ||
self.admin = self._get_admin() | ||
self.org1 = self._get_org() | ||
|
||
def test_disable_only_email_notifications(self): | ||
''' | ||
notification is created and it have emailed = False | ||
''' | ||
GeneralSetting.objects.create(user=self.admin, email=True, web=False) | ||
notify.send(sender=self.admin, type='default', target=self.org1) | ||
self.assertEqual(on_queryset.count(), 1) | ||
notification = on_queryset.all()[0] | ||
self.assertEqual(notification.emailed, False) | ||
|
||
def test_disable_only_web_notifications(self): | ||
''' | ||
notification is not created when web notifications | ||
are disabled | ||
''' | ||
GeneralSetting.objects.create(user=self.admin, email=False, web=True) | ||
notify.send(sender=self.admin, type='default', target=self.org1) | ||
self.assertEqual(on_queryset.count(), 0) | ||
|
||
def test_disable_all_notifications(self): | ||
''' | ||
notification is not created when all notifications | ||
are disabled | ||
''' | ||
GeneralSetting.objects.create(user=self.admin, email=True, web=True) | ||
notify.send(sender=self.admin, type='default', target=self.org1) | ||
self.assertEqual(on_queryset.count(), 0) | ||
|
||
# test when other organizations are created | ||
org2 = self._create_org(name='test org 2', slug='test-org-2') | ||
notify.send(sender=self.admin, type='default', target=org2) | ||
self.assertEqual(on_queryset.count(), 0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters