Exemplo n.º 1
0
def send_email_consumer(layer_uuid, user_id):
    resource = get_object_or_404(ResourceBase, uuid=layer_uuid)
    user = get_user_model().objects.get(id=user_id)
    send_notification([resource.owner], 'request_download_resourcebase', {
        'resource': resource,
        'from_user': user
    })
Exemplo n.º 2
0
    def post(self, request, *args, **kwargs):
        r_base = ResourceBase.objects.get(pk=kwargs.get('pk'))
        self.resource = OwnerRightsRequestViewUtils.get_resource(r_base)
        form = self.form_class(request.POST)
        if form.is_valid():
            reason = form.cleaned_data['reason']
            # object.save()
            notice_type_label = 'request_resource_edit'
            recipients = OwnerRightsRequestViewUtils.get_message_recipients()

            Message.objects.new_message(
                from_user=request.user,
                to_users=recipients,
                subject=_('System message: A request to modify resource'),
                content=_(
                    'The resource owner has requested to modify the resource')
                + '.'
                ' ' + _('Resource title') + ': ' + self.resource.title + '.'
                ' ' + _('Reason for the request') + ': "' + reason + '".' +
                ' ' +
                _('To allow the change, set the resource to not "Approved" under the metadata settings'
                  + 'and write message to the owner to notify him') + '.')
            send_notification(
                recipients, notice_type_label, {
                    'resource': self.resource,
                    'site_url': settings.SITEURL[:-1],
                    'reason': reason
                })
            return self.form_valid(form)
        else:
            return self.form_invalid(form)
Exemplo n.º 3
0
def comment_post_save(instance, sender, created, **kwargs):
    """ Send a notification when a comment to a layer, map or document has
    been submitted
    """
    notice_type_label = '%s_comment' % instance.content_object.class_name.lower()
    recipients = get_notification_recipients(notice_type_label, instance.author)
    send_notification(recipients, notice_type_label, {"instance": instance})
Exemplo n.º 4
0
def comment_post_save(instance, sender, created, **kwargs):
    """ Send a notification when a comment to a layer, map or document has
    been submitted
    """
    notice_type_label = '%s_comment' % instance.content_object.class_name.lower()
    recipients = get_notification_recipients(notice_type_label, instance.author)
    send_notification(recipients, notice_type_label, {"instance": instance})
Exemplo n.º 5
0
def notify_admins_new_signup(sender, **kwargs):
    staff = get_user_model().objects.filter(Q(is_active=True) & (Q(is_staff=True) | Q(is_superuser=True)))
    send_notification(
        users=staff,
        label="account_approve",
        extra_context={"from_user": kwargs["user"]}
    )
Exemplo n.º 6
0
def pre_save_layer(instance, sender, **kwargs):
    if kwargs.get('raw', False):
        try:
            _resourcebase_ptr = instance.resourcebase_ptr
            instance.owner = _resourcebase_ptr.owner
            instance.uuid = _resourcebase_ptr.uuid
            instance.bbox_polygon = _resourcebase_ptr.bbox_polygon
            instance.srid = _resourcebase_ptr.srid
        except Exception as e:
            logger.exception(e)

    if instance.abstract == '' or instance.abstract is None:
        instance.abstract = 'No abstract provided'
    if instance.title == '' or instance.title is None:
        instance.title = instance.name

    # Set a default user for accountstream to work correctly.
    if instance.owner is None:
        instance.owner = get_valid_user()

    logger.debug("handling UUID In pre_save_layer")
    if hasattr(settings,
               'LAYER_UUID_HANDLER') and settings.LAYER_UUID_HANDLER != '':
        logger.debug("using custom uuid handler In pre_save_layer")
        from geonode.layers.utils import get_uuid_handler
        instance.uuid = get_uuid_handler()(instance).create_uuid()
    else:
        if instance.uuid == '':
            instance.uuid = str(uuid.uuid1())

    logger.debug("In pre_save_layer")
    if instance.alternate is None:
        instance.alternate = _get_alternate_name(instance)
    logger.debug(f"instance.alternate is: {instance.alternate}")

    base_file, info = instance.get_base_file()

    if info:
        instance.info = info

    if base_file is not None:
        extension = f'.{base_file.name}'
        if extension in vec_exts:
            instance.storeType = 'dataStore'
        elif extension in cov_exts:
            instance.storeType = 'coverageStore'

    if instance.bbox_polygon is None:
        instance.set_bbox_polygon((-180, -90, 180, 90), 'EPSG:4326')
    instance.set_bounds_from_bbox(instance.bbox_polygon, instance.srid
                                  or instance.bbox_polygon.srid)

    # Send a notification when a layer is created
    if instance.pk is None and instance.title:
        # Resource Created
        notice_type_label = f'{instance.class_name.lower()}_created'
        recipients = get_notification_recipients(notice_type_label,
                                                 resource=instance)
        send_notification(recipients, notice_type_label,
                          {'resource': instance})
Exemplo n.º 7
0
def notification_post_save_resource(instance, sender, created, **kwargs):
    """ Send a notification when a layer, map or document is created or
    updated
    """
    notice_type_label = '%s_created' if created else '%s_updated'
    notice_type_label = notice_type_label % instance.class_name.lower()
    recipients = get_notification_recipients(notice_type_label)
    send_notification(recipients, notice_type_label, {'resource': instance})
Exemplo n.º 8
0
def notification_post_save_resource(instance, sender, created, **kwargs):
    """ Send a notification when a layer, map or document is created or
    updated
    """
    notice_type_label = '%s_created' if created else '%s_updated'
    notice_type_label = notice_type_label % instance.class_name.lower()
    recipients = get_notification_recipients(notice_type_label)
    send_notification(recipients, notice_type_label, {'resource': instance})
Exemplo n.º 9
0
def notify_admins_new_signup(sender, **kwargs):
    staff = get_user_model().objects.filter(
        Q(is_active=True) & (Q(is_staff=True) | Q(is_superuser=True)))
    send_notification(users=staff,
                      label="account_approve",
                      extra_context={"from_user": kwargs["user"]})

    if groups_settings.AUTO_ASSIGN_REGISTERED_MEMBERS_TO_REGISTERED_MEMBERS_GROUP_AT == 'registration':
        _add_user_to_registered_members(kwargs["user"])
Exemplo n.º 10
0
def rating_post_save(instance, sender, created, **kwargs):
    """ Send a notification when rating a layer, map or document
    """
    notice_type_label = '%s_rated' % instance.content_object.class_name.lower()
    recipients = get_notification_recipients(notice_type_label,
                                             instance.user,
                                             resource=instance.content_object)
    send_notification(recipients,
                      notice_type_label,
                      {'resource': instance.content_object, 'user': instance.user, 'rating': instance.rating})
Exemplo n.º 11
0
def notify_admins_new_signup(sender, **kwargs):
    staff = get_user_model().objects.filter(
        Q(is_active=True) & (Q(is_staff=True) | Q(is_superuser=True)))
    send_notification(users=staff,
                      label="account_approve",
                      extra_context={
                          "from_user":
                          kwargs["user"],
                          "account_approval_required":
                          settings.ACCOUNT_APPROVAL_REQUIRED
                      })
Exemplo n.º 12
0
def comment_post_save(instance, sender, created, **kwargs):
    """ Send a notification when a comment to a layer, map or document has
    been submitted
    """
    notice_type_label = f'{instance.content_type.model.lower()}_comment'
    recipients = get_comment_notification_recipients(
        notice_type_label, instance.author, resource=instance.content_object)
    send_notification(recipients, notice_type_label, {
        'resource': instance.content_object,
        'author': instance.author
    })
Exemplo n.º 13
0
def pre_save_layer(instance, sender, **kwargs):
    if kwargs.get('raw', False):
        try:
            _resourcebase_ptr = instance.resourcebase_ptr
            instance.owner = _resourcebase_ptr.owner
            instance.uuid = _resourcebase_ptr.uuid
            instance.bbox_polygon = _resourcebase_ptr.bbox_polygon
            instance.srid = _resourcebase_ptr.srid
        except Exception as e:
            logger.exception(e)

    if instance.abstract == '' or instance.abstract is None:
        instance.abstract = 'No abstract provided'
    if instance.title == '' or instance.title is None:
        instance.title = instance.name

    # Set a default user for accountstream to work correctly.
    if instance.owner is None:
        instance.owner = get_valid_user()

    if instance.uuid == '':
        instance.uuid = str(uuid.uuid1())

    logger.debug("In pre_save_layer")
    if instance.alternate is None:
        instance.alternate = _get_alternate_name(instance)
    logger.debug("instance.alternate is: {}".format(instance.alternate))

    base_file, info = instance.get_base_file()

    if info:
        instance.info = info

    if base_file is not None:
        extension = '.%s' % base_file.name
        if extension in vec_exts:
            instance.storeType = 'dataStore'
        elif extension in cov_exts:
            instance.storeType = 'coverageStore'

    if instance.bbox_polygon is None:
        instance.set_bbox_polygon((-180, -90, 180, 90), 'EPSG:4326')
    instance.set_bounds_from_bbox(instance.bbox_polygon,
                                  instance.bbox_polygon.srid)
    # Send a notification when a layer is created
    if instance.pk is None and instance.title:
        # Resource Created
        notice_type_label = '%s_created' % instance.class_name.lower()
        recipients = get_notification_recipients(notice_type_label,
                                                 resource=instance)
        send_notification(recipients, notice_type_label,
                          {'resource': instance})
Exemplo n.º 14
0
 def emit_notifications(self, for_timestamp=None):
     notifications = self.get_notifications(for_timestamp)
     for n, ndata in notifications:
         if not n.can_send:
             continue
         try:
             users = n.get_users()
             content = self.compose_notifications(ndata, when=for_timestamp)
             send_notification(users=users, label=AppConf.NOTIFICATION_NAME, extra_context=content)
             emails = n.get_emails()
             self.send_mails(n, emails, ndata, for_timestamp)
         finally:
             n.mark_send()
Exemplo n.º 15
0
def comment_post_save(instance, sender, created, **kwargs):
    """ Send a notification when a comment to a layer, map or document has
    been submitted
    """
    notice_type_label = '%s_comment' % instance.content_type.model.lower()
    recipients = get_comment_notification_recipients(
        notice_type_label, instance.content_object.owner)
    send_notification(recipients,
                      notice_type_label,
                      extra_context={
                          "instance":
                          instance,
                          'notice_settings_url':
                          reverse('pinax_notifications:notice_settings')
                      })
Exemplo n.º 16
0
 def emit_notifications(self, for_timestamp=None):
     notifications = self.get_notifications(for_timestamp)
     for n, ndata in notifications:
         if not n.can_send:
             continue
         try:
             users = n.get_users()
             content = self.compose_notifications(ndata, when=for_timestamp)
             send_notification(
                 users=users,
                 label=AppConf.NOTIFICATION_NAME,
                 extra_context=content)
             emails = n.get_emails()
             self.send_mails(n, emails, ndata, for_timestamp)
         finally:
             n.mark_send()
Exemplo n.º 17
0
def request_permissions(request):
    """ Request permission to download a resource.
    """
    uuid = request.POST['uuid']
    resource = get_object_or_404(ResourceBase, uuid=uuid)
    try:
        send_notification([resource.owner],
                          'request_download_resourcebase',
                          {'resource': resource, 'from_user': request.user})
        return HttpResponse(
            json.dumps({'success': 'ok', }),
            status=200,
            content_type='text/plain')
    except Exception:
        # traceback.print_exc()
        return HttpResponse(
            json.dumps({'error': _('error delivering notification')}),
            status=400,
            content_type='text/plain')
Exemplo n.º 18
0
def message_received_notification(**kwargs):
    """ Send a notification when a comment to a layer, map or document has
    been submitted
    """
    notice_type_label = 'message_received'
    message = kwargs.get('message')
    thread = message.thread

    recipients = _get_user_to_notify(message)

    ctx = {
        'message': message.content,
        'thread_subject': thread.subject,
        'sender': message.sender,
        'thread_url': settings.SITEURL + thread.get_absolute_url()[1:],
        'site_url': settings.SITEURL
    }
    logger.debug(f"message_received_notification to: {recipients}")
    send_notification(recipients, notice_type_label, ctx)
Exemplo n.º 19
0
def notification_post_save_resource(instance, sender, created, **kwargs):
    """ Send a notification when a layer, map or document is created or
    updated
    """
    notice_type_label = '%s_created' if created else '%s_updated'
    notice_type_label = notice_type_label % instance.class_name.lower()
    recipients = get_notification_recipients(notice_type_label)
    send_notification(recipients, notice_type_label, {'resource': instance})

    # Approval Notifications Here
    if settings.ADMIN_MODERATE_UPLOADS:
        if instance.is_approved and not instance.is_published:
            notice_type_label = '%s_approved'
            notice_type_label = notice_type_label % instance.class_name.lower()
            recipients = get_notification_recipients(notice_type_label)
            send_notification(recipients, notice_type_label,
                              {'resource': instance})

    # Publishing Notifications Here
    if settings.RESOURCE_PUBLISHING:
        if instance.is_approved and instance.is_published:
            notice_type_label = '%s_published'
            notice_type_label = notice_type_label % instance.class_name.lower()
            recipients = get_notification_recipients(notice_type_label)
            send_notification(recipients, notice_type_label,
                              {'resource': instance})
Exemplo n.º 20
0
def notification_post_save_resource(instance, sender, created, **kwargs):
    """ Send a notification when a layer, map or document is created or
    updated
    """
    notice_type_label = '%s_created' if created else '%s_updated'
    notice_type_label = notice_type_label % instance.class_name.lower()
    recipients = get_notification_recipients(notice_type_label)
    send_notification(recipients, notice_type_label, {'resource': instance})

    # Approval Notifications Here
    if settings.ADMIN_MODERATE_UPLOADS:
        if instance.is_approved and not instance.is_published:
            notice_type_label = '%s_approved'
            notice_type_label = notice_type_label % instance.class_name.lower()
            recipients = get_notification_recipients(notice_type_label)
            send_notification(recipients, notice_type_label, {'resource': instance})

    # Publishing Notifications Here
    if settings.RESOURCE_PUBLISHING:
        if instance.is_approved and instance.is_published:
            notice_type_label = '%s_published'
            notice_type_label = notice_type_label % instance.class_name.lower()
            recipients = get_notification_recipients(notice_type_label)
            send_notification(recipients, notice_type_label, {'resource': instance})
Exemplo n.º 21
0
def profile_signed_up(user, form, **kwargs):
    staff = auth.get_user_model().objects.filter(is_staff=True)
    send_notification(staff, "account_approve", {"from_user": user})
Exemplo n.º 22
0
def request_permissions(request):
    """ Request permission to download a resource.
    """
    uuid = request.POST['uuid']
    resource = get_object_or_404(ResourceBase, uuid=uuid)
    try:

        resource_owner = resource.owner
        requester_username = request.user
        requester_name = request.POST['requester_name']
        requester_email = request.POST['requester_email']
        requester_institution = request.POST['requester_institution']
        requester_position = request.POST['requester_position']
        purposes = request.POST['purposes']
        retention = request.POST['retention']
        resource_title = request.POST['resource_title']
        absolute_url = request.POST['absolute_url']

        try:
            # Save the request download resources to the model
            roda = Roda(uuid=uuid,
                        requester_username=requester_username,
                        requester_name=requester_name,
                        requester_email=requester_email,
                        requester_institution=requester_institution,
                        requester_position=requester_position,
                        purposes=purposes,
                        retention=retention,
                        resource_title=resource_title,
                        resource_owner=resource_owner,
                        absolute_url=absolute_url)
            roda.save()
            # Add notification to inbox user as well
            subject = 'System message: A request to download resource'
            message = f'{requester_name} has requested to download the resource {resource_title}. Reason for the request: {purposes}. To allow his/her download the resource, please go to {absolute_url}. Under the permissions setting, change data and assign download to {requester_username}.'
            thread = Thread.objects.create(subject=subject)
            thread.userthread_set.create(user=resource_owner, unread=True)
            thread.userthread_set.create(user=request.user, unread=False)
            Message.objects.create(sender=request.user,
                                   thread=thread,
                                   content=message)
        except Exception:
            return HttpResponse(json.dumps({
                'error':
                _('Permission to download the resource could not be requested to resource owner because of an error.'
                  )
            }),
                                status=500,
                                content_type='text/plain')

        logger.debug("Record request download resources...")
        send_notification([resource.owner], 'request_download_resourcebase', {
            'resource': resource,
            'from_user': request.user
        })
        return HttpResponse(json.dumps({
            'success': 'ok',
        }),
                            status=200,
                            content_type='text/plain')

    except Exception:
        # traceback.print_exc()
        return HttpResponse(json.dumps(
            {'error': _('error delivering notification')}),
                            status=403,
                            content_type='text/plain')
Exemplo n.º 23
0
def profile_pre_save(instance, sender, **kw):
    matching_profiles = Profile.objects.filter(id=instance.id)
    if matching_profiles.count() == 0:
        return
    if instance.is_active and not matching_profiles.get().is_active:
        send_notification((instance,), "account_active")
Exemplo n.º 24
0
def rating_post_save(instance, sender, created, **kwargs):
    """ Send a notification when rating a layer, map or document
    """
    notice_type_label = '%s_rated' % instance.content_object.class_name.lower()
    recipients = get_notification_recipients(notice_type_label, instance.user)
    send_notification(recipients, notice_type_label, {"instance": instance})
Exemplo n.º 25
0
def notification_post_delete_resource(instance, sender, **kwargs):
    """ Send a notification when a layer, map or document is deleted
    """
    notice_type_label = '%s_deleted' % instance.class_name.lower()
    recipients = get_notification_recipients(notice_type_label)
    send_notification(recipients, notice_type_label, {'resource': instance})
Exemplo n.º 26
0
 def _notify_account_activated(self):
     """Notify user that its account has been activated by a staff member"""
     became_active = self.is_active and not self._previous_active_state
     if became_active and self.last_login is None:
         send_notification(users=(self,), label="account_active")
Exemplo n.º 27
0
def profile_signed_up(user, form, **kwargs):
    staff = auth.get_user_model().objects.filter(is_staff=True)
    send_notification(staff, "account_approve", {"from_user": user})
Exemplo n.º 28
0
def profile_pre_save(instance, sender, **kw):
    matching_profiles = Profile.objects.filter(id=instance.id)
    if matching_profiles.count() == 0:
        return
    if instance.is_active and not matching_profiles.get().is_active:
        send_notification((instance, ), "account_active")
Exemplo n.º 29
0
def notification_post_delete_resource(instance, sender, **kwargs):
    """ Send a notification when a layer, map or document is deleted
    """
    notice_type_label = '%s_deleted' % instance.class_name.lower()
    recipients = get_notification_recipients(notice_type_label)
    send_notification(recipients, notice_type_label, {'resource': instance})