Пример #1
0
def draft_delete_api(public_id):
    data = request.get_json(force=True)
    if data.get('version') is None:
        return err(400, 'Must specify version to delete')
    version = data.get('version')

    try:
        valid_public_id(public_id)
        draft = g.db_session.query(Message).filter(
            Message.public_id == public_id).one()
    except InputError:
        return err(400, 'Invalid public id {}'.format(public_id))
    except NoResultFound:
        return err(404, 'No draft found with public_id {}'.
                   format(public_id))

    if draft.namespace != g.namespace:
        return err(404, 'No draft found with public_id {}'.
                   format(public_id))

    if not draft.is_draft:
        return err(400, 'Message with public id {} is not a draft'.
                   format(public_id))

    if draft.version != version:
        return err(409, 'Draft {0}.{1} has already been updated to version '
                   '{2}'.format(public_id, version, draft.version))

    result = sendmail.delete_draft(g.db_session, g.namespace.account,
                                   public_id)
    return g.encoder.jsonify(result)
Пример #2
0
def draft_delete_api(public_id):
    data = request.get_json(force=True)
    if data.get('version') is None:
        return err(400, 'Must specify version to delete')
    version = data.get('version')

    try:
        valid_public_id(public_id)
        draft = g.db_session.query(Message).filter(
            Message.public_id == public_id).one()
    except InputError:
        return err(400, 'Invalid public id {}'.format(public_id))
    except NoResultFound:
        return err(404, 'No draft found with public_id {}'.format(public_id))

    if draft.namespace != g.namespace:
        return err(404, 'No draft found with public_id {}'.format(public_id))

    if not draft.is_draft:
        return err(
            400, 'Message with public id {} is not a draft'.format(public_id))

    if draft.version != version:
        return err(
            409, 'Draft {0}.{1} has already been updated to version '
            '{2}'.format(public_id, version, draft.version))

    try:
        result = sendmail.delete_draft(g.db_session, g.namespace.account,
                                       public_id)
    except ActionError as e:
        return err(e.error, str(e))

    return g.encoder.jsonify(result)
Пример #3
0
def draft_delete_api(public_id):
    data = request.get_json(force=True)
    # Validate draft id, version, etc.
    draft = get_draft(public_id, data.get('version'), g.namespace.id,
                      g.db_session)

    try:
        result = sendmail.delete_draft(g.db_session, g.namespace.account,
                                       draft)
    except ActionError as e:
        return err(e.error, str(e))

    return g.encoder.jsonify(result)
Пример #4
0
def draft_delete_api(public_id):
    data = request.get_json(force=True)
    # Validate draft id, version, etc.
    draft = get_draft(public_id, data.get('version'), g.namespace.id,
                      g.db_session)

    try:
        result = sendmail.delete_draft(g.db_session, g.namespace.account,
                                       draft)
    except ActionError as e:
        return err(e.error, str(e))

    return g.encoder.jsonify(result)
Пример #5
0
def draft_delete_api(public_id):
    try:
        draft = g.db_session.query(Message).filter(
            Message.public_id == public_id).one()
    except NoResultFound:
        return err(404, 'No draft found with public_id {}'.
                   format(public_id))

    if draft.namespace != g.namespace:
        return err(404, 'No draft found with public_id {}'.
                   format(public_id))

    if not draft.is_draft:
        return err(400, 'Message with public id {} is not a draft'.
                   format(public_id))

    result = sendmail.delete_draft(g.db_session, g.namespace.account,
                                   public_id)
    return g.encoder.jsonify(result)
Пример #6
0
def draft_delete_api(public_id):
    try:
        draft = g.db_session.query(Message).filter(
            Message.public_id == public_id).one()
    except NoResultFound:
        return err(404, 'No draft found with public_id {}'.
                   format(public_id))

    if draft.namespace != g.namespace:
        return err(404, 'No draft found with public_id {}'.
                   format(public_id))

    if not draft.is_draft:
        return err(400, 'Message with public id {} is not a draft'.
                   format(public_id))

    result = sendmail.delete_draft(g.db_session, g.namespace.account,
                                   public_id)
    return g.encoder.jsonify(result)