コード例 #1
0
def publish(event, actor_id=None, params=None, channels=None):
    assert isinstance(event, Event), event
    params = params or {}
    outparams = {}
    channels = ensure_list(channels)
    channels.append(channel(actor_id, clazz=Role))
    for name, clazz in event.params.items():
        obj = params.get(name)
        outparams[name] = object_id(obj, clazz=clazz)
        channels.append(channel(obj, clazz=clazz))
    Notification.publish(event,
                         actor_id=actor_id,
                         params=outparams,
                         channels=channels)
コード例 #2
0
def publish(event, actor_id=None, params=None, channels=None):
    """ Publish a notification to the given channels, while storing
    the parameters and initiating actor for the event. """
    assert isinstance(event, Event), event
    params = params or {}
    outparams = {}
    channels = [channel_tag(c) for c in ensure_list(channels)]
    for name, clazz in event.params.items():
        obj = params.get(name)
        outparams[name] = get_entity_id(obj)
    Notification.publish(event,
                         actor_id=actor_id,
                         params=outparams,
                         channels=channels)
    db.session.flush()
コード例 #3
0
def collection(id):
    require(request.authz.logged_in)
    collection = get_db_collection(id)
    channel_name = channel(collection)
    query = Notification.by_channel(channel_name)
    result = DatabaseQueryResult(request, query)
    return NotificationSerializer.jsonify_result(result)
コード例 #4
0
def index():
    require(request.authz.logged_in)
    role = Role.by_id(request.authz.id)
    require(role is not None)
    query = Notification.by_role(role)
    result = DatabaseQueryResult(request, query, schema=NotificationSchema)
    return jsonify(result)
コード例 #5
0
def collection(id):
    require(request.authz.logged_in)
    collection = get_db_collection(id)
    channel_name = channel(collection)
    query = Notification.by_channel(channel_name)
    result = DatabaseQueryResult(request, query, schema=NotificationSchema)
    return jsonify(result)
コード例 #6
0
ファイル: test_notifications.py プロジェクト: pudo/aleph
    def test_publish_event(self):
        role = self.create_user()
        email = '*****@*****.**'
        label = 'So public'
        recipient = self.create_user(foreign_id='rolex',
                                     email=email)
        update_role(recipient)
        collection = self.create_collection(foreign_id='NoNoNo', label=label)
        event = Events.PUBLISH_COLLECTION
        publish(event, role.id,
                params={'collection': collection},
                channels=[Notification.GLOBAL])
        db.session.commit()

        notifications = Notification.all().all()
        assert 1 == len(notifications), notifications
        not0 = notifications[0]
        assert not0._event == event.name, not0._event
        assert not0.params['collection'] == str(collection.id), not0.params

        with mail.record_messages() as outbox:
            assert len(outbox) == 0, outbox
            generate_digest()
            assert len(outbox) == 1, outbox
            msg = outbox[0]
            assert email in msg.recipients, msg.recipients
            assert label in msg.html, msg.html
コード例 #7
0
    def test_publish_event(self):
        role = self.create_user()
        email = '*****@*****.**'
        label = 'So public'
        recipient = self.create_user(foreign_id='rolex', email=email)
        update_role(recipient)
        collection = self.create_collection(foreign_id='NoNoNo', label=label)
        event = Events.PUBLISH_COLLECTION
        publish(event,
                role.id,
                params={'collection': collection},
                channels=[Notification.GLOBAL])
        db.session.commit()

        notifications = Notification.all().all()
        assert 1 == len(notifications), notifications
        not0 = notifications[0]
        assert not0._event == event.name, not0._event
        assert not0.params['collection'] == collection.id, not0.params

        with mail.record_messages() as outbox:
            assert len(outbox) == 0, outbox
            generate_digest()
            assert len(outbox) == 1, outbox
            msg = outbox[0]
            assert email in msg.recipients, msg.recipients
            assert label in msg.html, msg.html
コード例 #8
0
def index():
    """
    ---
    get:
      summary: Get notifications
      description: Get all the notifications for the user
      responses:
        '200':
          content:
            application/json:
              schema:
                type: object
                allOf:
                - $ref: '#/components/schemas/QueryResponse'
                properties:
                  results:
                    type: array
                    items:
                      $ref: '#/components/schemas/Notification'
          description: OK
      tags:
      - Notification
    """
    require(request.authz.logged_in)
    role = Role.by_id(request.authz.id)
    query = Notification.by_channels(get_role_channels(role), role)
    result = DatabaseQueryResult(request, query)
    return NotificationSerializer.jsonify_result(result)
コード例 #9
0
ファイル: notifications.py プロジェクト: pudo/aleph
def publish(event, actor_id=None, params=None, channels=None):
    """ Publish a notification to the given channels, while storing
    the parameters and initiating actor for the event. """
    assert isinstance(event, Event), event
    params = params or {}
    outparams = {}
    channels = ensure_list(channels)
    channels.append(channel(actor_id, clazz=Role))
    for name, clazz in event.params.items():
        obj = params.get(name)
        outparams[name] = get_entity_id(obj)
        channels.append(channel(obj, clazz=clazz))
    Notification.publish(event,
                         actor_id=actor_id,
                         params=outparams,
                         channels=channels)
    db.session.flush()
コード例 #10
0
ファイル: notifications.py プロジェクト: jbaehne/aleph
def publish(event, actor_id=None, params=None, channels=None):
    """ Publish a notification to the given channels, while storing
    the parameters and initiating actor for the event. """
    assert isinstance(event, Event), event
    params = params or {}
    outparams = {}
    channels = ensure_list(channels)
    channels.append(channel(actor_id, clazz=Role))
    for name, clazz in event.params.items():
        obj = params.get(name)
        outparams[name] = object_id(obj, clazz=clazz)
        channels.append(channel(obj, clazz=clazz))
    Notification.publish(event,
                         actor_id=actor_id,
                         params=outparams,
                         channels=channels)
    db.session.flush()
コード例 #11
0
def index():
    require(request.authz.logged_in)
    role = Role.by_id(request.authz.id)
    query = Notification.by_channels(get_role_channels(role),
                                     since=role.notified_at,
                                     exclude_actor_id=role.id)
    result = DatabaseQueryResult(request, query)
    return NotificationSerializer.jsonify_result(result)
コード例 #12
0
ファイル: notifications_api.py プロジェクト: pudo/aleph
def index():
    require(request.authz.logged_in)
    role = Role.by_id(request.authz.id)
    query = Notification.by_channels(get_role_channels(role),
                                     since=role.notified_at,
                                     exclude_actor_id=role.id)
    result = DatabaseQueryResult(request, query)
    return NotificationSerializer.jsonify_result(result)
コード例 #13
0
    def test_notify_no_email(self):
        data = {'query': {}, 'custom_label': 'Test Alert'}
        assert self.role_no_email.email is None, self.role_no_email.email
        alert = Alert.create(data, self.role_no_email)
        alert.notified_at = datetime.utcnow() - timedelta(hours=72)
        db.session.commit()

        notcount = Notification.all().count()
        assert notcount == 0, notcount
コード例 #14
0
ファイル: test_alerts.py プロジェクト: pudo/aleph
    def test_notify_entity(self):
        data = {'query': 'kwazulu'}
        alert = Alert.create(data, self.role_email.id)
        alert.notified_at = datetime.utcnow() - timedelta(hours=72)
        db.session.add(alert)
        db.session.commit()

        check_alerts()
        notcount = Notification.all().count()
        assert notcount == 2, notcount
コード例 #15
0
    def test_notify_entity(self):
        data = {'query_text': 'kwazulu', 'label': 'Test Alert'}
        alert = Alert.create(data, self.role_email.id)
        alert.notified_at = datetime.utcnow() - timedelta(hours=72)
        db.session.add(alert)
        db.session.commit()

        check_alerts()
        notcount = Notification.all().count()
        assert notcount == 2, notcount
コード例 #16
0
ファイル: test_alerts.py プロジェクト: pudo/aleph
    def test_notify(self):
        data = {'query': 'fruit'}
        alert = Alert.create(data, self.role_email.id)
        alert.notified_at = datetime.utcnow() + timedelta(hours=72)
        db.session.commit()

        notcount = Notification.all().count()
        assert notcount == 0, notcount

        db.session.refresh(alert)
        alert.notified_at = datetime.utcnow() - timedelta(hours=72)
        db.session.add(alert)
        db.session.commit()

        check_alerts()
        notcount = Notification.all().count()
        assert notcount == 1, notcount

        check_alerts()
        notcount = Notification.all().count()
        assert notcount == 1, notcount
コード例 #17
0
    def test_publish_event(self):
        event = Events.PUBLISH_COLLECTION
        role = self.create_user()
        collection = self.create_collection(foreign_id='NoNoNo')
        publish(event, role.id, params={'collection': collection})
        db.session.commit()

        notifications = Notification.all().all()
        assert 1 == len(notifications), notifications
        not0 = notifications[0]
        assert not0._event == event.name, not0._event
        assert not0.params['collection'] == collection.id, not0.params
コード例 #18
0
    def test_notify(self):
        data = {'query_text': '', 'label': 'Test Alert'}
        alert = Alert.create(data, self.role_email)
        alert.notified_at = datetime.utcnow() + timedelta(hours=72)
        db.session.commit()

        notcount = Notification.all().count()
        assert notcount == 0, notcount

        db.session.refresh(alert)
        alert.notified_at = datetime.utcnow() - timedelta(hours=72)
        db.session.add(alert)
        db.session.commit()

        check_alerts()
        notcount = Notification.all().count()
        assert notcount == 3, notcount

        check_alerts()
        notcount = Notification.all().count()
        assert notcount == 3, notcount
コード例 #19
0
ファイル: test_alerts.py プロジェクト: stofstar/aleph
    def test_notify(self):
        data = {'query': 'Kashmir'}
        failed_alert = Alert.create(data, self.role_no_email.id)
        failed_alert.notified_at = datetime.utcnow() - timedelta(hours=72)

        alert = Alert.create(data, self.role_email.id)
        alert.notified_at = datetime.utcnow() + timedelta(hours=72)
        db.session.commit()

        notcount = Notification.all().count()
        assert notcount == 0, notcount

        db.session.refresh(alert)
        alert.notified_at = datetime.utcnow() - timedelta(hours=72)
        db.session.add(alert)
        db.session.commit()

        check_alerts()
        notcount = Notification.all().count()
        assert notcount == 1, notcount

        check_alerts()
        notcount = Notification.all().count()
        assert notcount == 1, notcount
コード例 #20
0
ファイル: notifications.py プロジェクト: nt0z/aleph
def generate_role_digest(role):
    """Generate notification digest emails for the given user."""
    # TODO: get and use the role's locale preference.
    since = datetime.utcnow() - timedelta(hours=25)
    q = Notification.by_role(role, since=since)
    total_count = q.count()
    if total_count == 0:
        return
    notifications = []
    for notification in q.limit(25):
        notifications.append(render_notification(notification))

    subject = '%s notifications' % total_count
    notify_role(role, subject,
                'email/notifications.html',
                total_count=total_count,
                notifications=notifications,
                manage_url=ui_url('notifications'))
コード例 #21
0
def generate_role_digest(role):
    """Generate notification digest emails for the given user."""
    # TODO: get and use the role's locale preference.
    since = datetime.utcnow() - timedelta(hours=25)
    q = Notification.by_role(role, since=since)
    total_count = q.count()
    if total_count == 0:
        return
    notifications = [render_notification(role, n) for n in q.limit(30)]
    notifications = [n for n in notifications if n is not None]
    params = dict(notifications=notifications,
                  role=role,
                  total_count=total_count,
                  manage_url=ui_url('notifications'),
                  ui_url=settings.APP_UI_URL,
                  app_title=settings.APP_TITLE)
    plain = render_template('email/notifications.txt', **params)
    html = render_template('email/notifications.html', **params)
    log.info("Notification: %s", plain)
    subject = '%s notifications' % total_count
    email_role(role, subject, html=html, plain=plain)
コード例 #22
0
ファイル: notifications.py プロジェクト: pudo/aleph
def generate_role_digest(role):
    """Generate notification digest emails for the given user."""
    # TODO: get and use the role's locale preference.
    since = datetime.utcnow() - timedelta(hours=25)
    q = Notification.by_channels(get_role_channels(role),
                                 since=since, exclude_actor_id=role.id)
    total_count = q.count()
    if total_count == 0:
        return
    notifications = [render_notification(role, n) for n in q.limit(30)]
    notifications = [n for n in notifications if n is not None]
    params = dict(notifications=notifications,
                  role=role,
                  total_count=total_count,
                  manage_url=ui_url('notifications'),
                  ui_url=settings.APP_UI_URL,
                  app_title=settings.APP_TITLE)
    plain = render_template('email/notifications.txt', **params)
    html = render_template('email/notifications.html', **params)
    log.info("Notification: %s", plain)
    subject = '%s notifications' % total_count
    email_role(role, subject, html=html, plain=plain)
コード例 #23
0
def index():
    require(request.authz.logged_in)
    role = Role.by_id(request.authz.id)
    query = Notification.by_role(role)
    result = DatabaseQueryResult(request, query)
    return NotificationSerializer.jsonify_result(result)
コード例 #24
0
ファイル: notifications_api.py プロジェクト: renesugar/aleph
def index():
    require(request.authz.logged_in)
    query = Notification.by_role(request.authz.role)
    result = DatabaseQueryResult(request, query, schema=NotificationSchema)
    return jsonify(result)
コード例 #25
0
def flush_notifications(obj, clazz=None):
    channel_ = channel(obj, clazz=clazz)
    Notification.delete_by_channel(channel_)
コード例 #26
0
ファイル: notifications.py プロジェクト: pudo/aleph
def flush_notifications(obj, clazz=None):
    channel_ = channel(obj, clazz=clazz)
    Notification.delete_by_channel(channel_)