Example #1
0
def persistent_file_download(auth, **kwargs):
    id_or_guid = kwargs.get('fid_or_guid')
    file = BaseFileNode.active.filter(_id=id_or_guid).first()
    if not file:
        guid = Guid.load(id_or_guid)
        if guid:
            file = guid.referent
        else:
            raise HTTPError(http_status.HTTP_404_NOT_FOUND,
                            data={
                                'message_short':
                                'File Not Found',
                                'message_long':
                                'The requested file could not be found.'
                            })
    if not file.is_file:
        raise HTTPError(
            http_status.HTTP_400_BAD_REQUEST,
            data={'message_long': 'Downloading folders is not permitted.'})

    auth_redirect = check_contributor_auth(file.target,
                                           auth,
                                           include_public=True,
                                           include_view_only_anon=True)
    if auth_redirect:
        return auth_redirect

    query_params = request.args.to_dict()

    return redirect(file.generate_waterbutler_url(**query_params),
                    code=http_status.HTTP_302_FOUND)
Example #2
0
def persistent_file_download(auth, **kwargs):
    id_or_guid = kwargs.get('fid_or_guid')
    file = BaseFileNode.active.filter(_id=id_or_guid).first()
    if not file:
        guid = Guid.load(id_or_guid)
        if guid:
            file = guid.referent
        else:
            raise HTTPError(httplib.NOT_FOUND, data={
                'message_short': 'File Not Found',
                'message_long': 'The requested file could not be found.'
            })
    if not file.is_file:
        raise HTTPError(httplib.BAD_REQUEST, data={
            'message_long': 'Downloading folders is not permitted.'
        })

    auth_redirect = check_contributor_auth(file.target, auth,
                                           include_public=True,
                                           include_view_only_anon=True)
    if auth_redirect:
        return auth_redirect

    query_params = request.args.to_dict()

    return redirect(
        file.generate_waterbutler_url(**query_params),
        code=httplib.FOUND
    )