Ejemplo n.º 1
0
def mark_notice_route(request, notice_id):
    """
    Mark notice as read or unread.
    Must be logged in as user, provide a valid ID, and own the notice.
    Return notice.
    """

    db_conn = request['db_conn']

    current_user = get_current_user(request)
    if not current_user:
        return abort(401)
    notice = get_notice({'id': notice_id}, db_conn)
    if not notice:
        return abort(404)
    if notice['user_id'] != current_user['id']:
        return abort(403)

    if 'read' not in request['params']:
        errors = [{
            'name': 'read',
            'message': 'You must specify read or unread.',
        }]
    elif request['params'].get('read') is True:
        notice, errors = mark_notice_as_read(notice, db_conn)
    elif request['params'].get('read') is False:
        notice, errors = mark_notice_as_unread(notice, db_conn)
    if len(errors):
        return 400, {
            'errors': errors,
            'ref': 'qR4CBtcfcYfWDTqK9JOXXLhO',
        }

    return 200, {'notice': deliver_notice(notice, access='private')}
Ejemplo n.º 2
0
def mark_notice_route(request, notice_id):
    """
    Mark notice as read or unread.
    Must be logged in as user, provide a valid ID, and own the notice.
    Return notice.
    """

    db_conn = request['db_conn']

    current_user = get_current_user(request)
    if not current_user:
        return abort(401)
    notice = get_notice({'id': notice_id}, db_conn)
    if not notice:
        return abort(404)
    if notice['user_id'] != current_user['id']:
        return abort(403)

    if 'read' not in request['params']:
        errors = [{
            'name': 'read',
            'message': 'You must specify read or unread.',
        }]
    elif request['params'].get('read') is True:
        notice, errors = mark_notice_as_read(notice, db_conn)
    elif request['params'].get('read') is False:
        notice, errors = mark_notice_as_unread(notice, db_conn)
    if len(errors):
        return 400, {
            'errors': errors,
            'ref': 'qR4CBtcfcYfWDTqK9JOXXLhO',
        }

    return 200, {'notice': deliver_notice(notice, access='private')}
Ejemplo n.º 3
0
def mark_notice_route(request, notice_id):
  """
  Mark notice as read or unread.
  Must be logged in as user, provide a valid ID, and own the notice.
  Return notice.
  """

  db_conn = request['db_conn']

  current_user = get_current_user(request)
  if not current_user:
    return abort(401, 'EWoueZr0TYSccUhdNISK3A')
  notice = get_notice(db_conn, {'id': notice_id})
  if not notice:
    return abort(404, 'xsNPOqJoRw-aUrFo0RhVoA')
  if notice['user_id'] != current_user['id']:
    return abort(403, 'xPkb7MYXRIOaI7HeV9U37A')
  if 'read' not in request['params']:
    errors = [{
      'name': 'read',
      'message': 'You must specify read or unread.',
      'ref': 'bvtS4G4jQnaLlVSLyUXjVg',
    }]
  elif request['params'].get('read') is True:
    notice, errors = mark_notice_as_read(db_conn, notice)
  elif request['params'].get('read') is False:
    notice, errors = mark_notice_as_unread(db_conn, notice)
  if errors:
    return 400, {
      'errors': errors,
      'ref': 'FeEtTWJJQv22dTpz8y5fZA',
    }
  return 200, {'notice': deliver_notice(notice, access='private')}
Ejemplo n.º 4
0
def test_mark_notice_as_read(db_conn):
  create_test_notices(db_conn)
  notice = get_notice(db_conn, {
    'id': notice_a_id
  })
  assert notice
  notice, errors = mark_notice_as_read(db_conn, notice)
  assert not errors
  assert notice
  assert notice['read'] is True
Ejemplo n.º 5
0
def test_mark_as_read(db_conn, notices_table):
    """
    Expect to mark a notice as read.
    """

    notice, errors = insert_notice({"user_id": "abcd1234", "kind": "create_proposal", "tags": ["test"]}, db_conn)
    assert notice["read"] is False
    notice, errors = mark_notice_as_read(notice, db_conn)
    assert len(errors) == 0
    assert notice["read"] is True
    record = notices_table.filter({"user_id": "abcd1234"}).run(db_conn)
    record = list(record)[0]
    assert record["read"] is True
Ejemplo n.º 6
0
def test_mark_as_read(db_conn, notices_table):
    """
    Expect to mark a notice as read.
    """

    notice, errors = insert_notice(
        {
            'user_id': 'abcd1234',
            'kind': 'create_proposal',
            'tags': ['test']
        }, db_conn)
    assert notice['read'] is False
    notice, errors = mark_notice_as_read(notice, db_conn)
    assert len(errors) == 0
    assert notice['read'] is True
    record = notices_table.filter({'user_id': 'abcd1234'}).run(db_conn)
    record = list(record)[0]
    assert record['read'] is True