Beispiel #1
0
def get_item(item_id):
    _format = flask.request.args.get('format', 'NITFFormatter')
    _version = flask.request.args.get('version')
    service = get_resource_service('formatters')
    formatted = service.get_version(item_id, _version, _format)
    mimetype = formatted.get('mimetype')
    response = app.response_class(response=formatted.get('formatted_item'),
                                  status=200,
                                  mimetype=mimetype)
    post_api_audit({'_items': [{'_id': item_id}]})
    return response
Beispiel #2
0
def get_item(item_id):
    if CompanyTokenAuth().check_auth(
            flask.request.headers.get('Authorization'), None, None, 'GET'):
        _format = flask.request.args.get('format', 'NINJSFormatter')
        _version = flask.request.args.get('version')
        service = get_resource_service('formatters')
        formatted = service.get_version(item_id, _version, _format)
        mimetype = formatted.get('mimetype')
        response = app.response_class(response=formatted.get('formatted_item'),
                                      status=200,
                                      mimetype=mimetype)
        post_api_audit({'_items': [{'_id': item_id}]})
        return response
    else:
        abort(401, gettext('Invalid token'))
Beispiel #3
0
def get_item(item_id):
    auth = app.auth
    if not auth.authorized([], None, flask.request.method):
        return abort(401, gettext('Invalid token'))

    _format = flask.request.args.get('format', 'NINJSFormatter')
    _version = flask.request.args.get('version')
    service = get_resource_service('formatters')
    formatted = service.get_version(item_id, _version, _format)
    mimetype = formatted.get('mimetype')
    response = app.response_class(response=formatted.get('formatted_item'), status=200, mimetype=mimetype)

    post_api_audit({'_items': [{'_id': item_id}]})
    # Record the retrieval of the item in the history collection
    get_resource_service('history').create_history_record([{'_id': item_id, 'version': formatted.get('version')}],
                                                          'api', {'_id': None,
                                                                  'company': ObjectId(g.user)}, 'news_api')
    return response
Beispiel #4
0
def get_item(asset_id):
    auth = app.auth
    if not auth.authorized([], None, flask.request.method):
        return abort(401, gettext('Invalid token'))

    try:
        media_file = flask.current_app.media.get(asset_id, ASSETS_RESOURCE)
    except bson.errors.InvalidId:
        media_file = None
    if not media_file:
        flask.abort(404)

    data = wrap_file(flask.request.environ, media_file, buffer_size=1024 * 256)
    response = flask.current_app.response_class(
        data, mimetype=media_file.content_type, direct_passthrough=True)
    response.content_length = media_file.length
    response.last_modified = media_file.upload_date
    response.set_etag(media_file.md5)
    response.make_conditional(flask.request)
    response.headers['Content-Disposition'] = 'inline'
    post_api_audit({'_items': [{'_id': asset_id}]})
    return response
Beispiel #5
0
 def on_fetched(self, doc):
     post_api_audit(doc)
Beispiel #6
0
 def on_fetched_item(self, doc):
     self._prefix_hateoas(doc.get('_links', {}))
     post_api_audit(doc)
Beispiel #7
0
    def on_fetched(self, doc):
        self._prefix_hateoas(doc.get('_links', {}))
        for item in doc.get('_items', []):
            self._prefix_hateoas(item)

        post_api_audit(doc)
Beispiel #8
0
 def on_fetched_item(self, doc):
     self._enhance_links(doc)
     post_api_audit(doc)
Beispiel #9
0
 def on_fetched(self, doc):
     self._enhance_hateoas(doc)
     post_api_audit(doc)