Esempio n. 1
0
    def test_app_object_created_notification(self):
        OrganizationUser = swapper_load_model('openwisp_users', 'OrganizationUser')

        org = self._get_org()
        operator = self._get_operator()
        OrganizationUser.objects.create(user=operator, organization=org, is_admin=True)
        oum_obj = TestApp(organization=org, name='Test')
        oum_obj.save()

        n = Notification.objects.get(type='object_created', recipient=operator)
        n_count = Notification.objects.count()
        self.assertEqual(n_count, 2)
        self.assertEqual(n.actor, oum_obj)
        self.assertEqual(n.target, oum_obj)
        self.assertEqual(n.message, '<p>Test object created.</p>')
        n.delete()
Esempio n. 2
0
from openwisp_notifications.swapper import load_model, swapper_load_model
from openwisp_notifications.types import get_notification_configuration
from openwisp_notifications.websockets import handlers as ws_handlers

logger = logging.getLogger(__name__)

EXTRA_DATA = app_settings.get_config()['USE_JSONFIELD']

User = get_user_model()

Notification = load_model('Notification')
NotificationSetting = load_model('NotificationSetting')
IgnoreObjectNotification = load_model('IgnoreObjectNotification')
NotificationsAppConfig = apps.get_app_config(NotificationSetting._meta.app_label)

Group = swapper_load_model('openwisp_users', 'Group')
OrganizationUser = swapper_load_model('openwisp_users', 'OrganizationUser')
Organization = swapper_load_model('openwisp_users', 'Organization')


def notify_handler(**kwargs):
    """
    Handler function to create Notification instance upon action signal call.
    """
    # Pull the options out of kwargs
    kwargs.pop('signal', None)
    actor = kwargs.pop('sender')
    public = bool(kwargs.pop('public', True))
    description = kwargs.pop('description', None)
    timestamp = kwargs.pop('timestamp', timezone.now())
    recipient = kwargs.pop('recipient', None)
Esempio n. 3
0
from django.urls import reverse

from openwisp_notifications import settings as app_settings
from openwisp_notifications.admin import NotificationSettingInline
from openwisp_notifications.signals import notify
from openwisp_notifications.swapper import load_model, swapper_load_model
from openwisp_notifications.widgets import _add_object_notification_widget
from openwisp_users.admin import UserAdmin
from openwisp_users.tests.utils import TestMultitenantAdminMixin, TestOrganizationMixin

from .test_helpers import MessagingRequest

Notification = load_model('Notification')
NotificationSetting = load_model('NotificationSetting')
notification_queryset = Notification.objects.order_by('-timestamp')
Group = swapper_load_model('openwisp_users', 'Group')


class MockUser:
    def __init__(self, is_superuser=False):
        self.is_superuser = is_superuser
        self.id = uuid.uuid4()

    def has_perm(self, perm):
        return True

    @property
    def pk(self):
        return self.id

Esempio n. 4
0
 def get_organization_choices(cls):
     if not hasattr(cls, 'organization_choices'):
         Organization = swapper_load_model('openwisp_users', 'organization')
         cls.organization_choices = [(None, '---------')] + list(
             Organization.objects.all().values_list('pk', 'name'))
     return cls.organization_choices
Esempio n. 5
0
from django.core.management.base import BaseCommand

from openwisp_notifications.handlers import (
    notification_type_registered_unregistered_handler, )
from openwisp_notifications.signals import notify
from openwisp_notifications.swapper import swapper_load_model

Organization = swapper_load_model('openwisp_users', 'Organization')


class BaseCreateNotificationCommand(BaseCommand):
    def handle(self, *args, **kwargs):
        default_org = Organization.objects.first()
        notify.send(sender=default_org, type='default', target=default_org)


class BasePopulateNotificationPreferencesCommand(BaseCommand):
    def handle(self, *args, **kwargs):
        notification_type_registered_unregistered_handler(self)