示例#1
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)
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)
示例#3
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)
示例#4
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=26)
    q = Notification.by_channels(get_role_channels(role), role, since=since)
    total_count = q.count()
    log.info("Daily digest: %r (%s notifications)", role, total_count)
    if total_count == 0:
        return
    notifications = [render_notification(role, n) for n in q.limit(20)]
    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)
示例#5
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_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)