Exemplo n.º 1
0
    def get(self, request, file_mgr_name, system_id=None, file_path=None):
        if file_mgr_name == AgaveFileManager.NAME:
            if not request.user.is_authenticated:
                return HttpResponseForbidden('Login required')

            fm = AgaveFileManager(agave_client=request.user.agave_oauth.client)
            if system_id is None:
                system_id = AgaveFileManager.DEFAULT_SYSTEM_ID
            if file_path is None:
                file_path = request.user.username

            if system_id == AgaveFileManager.DEFAULT_SYSTEM_ID and \
                (file_path.strip('/') == '$SHARE' or
                 file_path.strip('/').split('/')[0] != request.user.username):

                listing = ElasticFileManager.listing(
                    system=system_id,
                    file_path=file_path,
                    user_context=request.user.username)
                return JsonResponse(listing)
            else:
                offset = int(request.GET.get('offset', 0))
                limit = int(request.GET.get('limit', 100))
                listing = fm.listing(system=system_id,
                                     file_path=file_path,
                                     offset=offset,
                                     limit=limit)
                return JsonResponse(listing,
                                    encoder=AgaveJSONEncoder,
                                    safe=False)
        return HttpResponseBadRequest()
Exemplo n.º 2
0
    def get(self, request, file_mgr_name, system_id=None, file_path=None):
        if file_mgr_name == AgaveFileManager.NAME:
            if not request.user.is_authenticated:
                return HttpResponseForbidden('Login required')

            fm = AgaveFileManager(agave_client=request.user.agave_oauth.client)
            if system_id is None:
                system_id = AgaveFileManager.DEFAULT_SYSTEM_ID
            if file_path is None:
                file_path = request.user.username

            if system_id == AgaveFileManager.DEFAULT_SYSTEM_ID and \
                (file_path.strip('/') == '$SHARE' or
                 file_path.strip('/').split('/')[0] != request.user.username):

                listing = ElasticFileManager.listing(
                    system=system_id,
                    file_path=file_path,
                    user_context=request.user.username)
                return JsonResponse(listing)
            else:
                query_string = request.GET.get('query_string')

                offset = int(request.GET.get('offset', 0))
                limit = int(request.GET.get('limit', 100))
                if (not query_string) or (query_string == ""):
                    listing = fm.listing(system=system_id,
                                         file_path=file_path,
                                         offset=offset,
                                         limit=limit)
                else:
                    query_string = request.GET.get('query_string')
                    # Performing an Agave listing here prevents a race condition.
                    listing = fm.listing(system=system_id,
                                         file_path='/',
                                         offset=offset,
                                         limit=limit)
                    efmgr = ElasticFileManager()
                    listing = efmgr.search_in_project(system_id,
                                                      query_string,
                                                      offset=offset,
                                                      limit=limit)
                return JsonResponse(listing,
                                    encoder=AgaveJSONEncoder,
                                    safe=False)
        return HttpResponseBadRequest()
Exemplo n.º 3
0
    def get(self, request, file_mgr_name, system_id=None, file_path=None):
        if file_mgr_name == AgaveFileManager.NAME:
            if not request.user.is_authenticated():
                return HttpResponseForbidden('Log in required')

            fm = AgaveFileManager(agave_client=request.user.agave_oauth.client)
            if system_id is None:
                system_id = AgaveFileManager.DEFAULT_SYSTEM_ID
            if file_path is None:
                file_path = request.user.username
            
            if system_id == AgaveFileManager.DEFAULT_SYSTEM_ID and \
                (file_path.strip('/') == '$SHARE' or
                 file_path.strip('/').split('/')[0] != request.user.username):

                listing = ElasticFileManager.listing(system=system_id,
                                                     file_path=file_path,
                                                     user_context=request.user.username)
                return JsonResponse(listing)
            else:
                try:
                    offset = int(request.GET.get('offset', 0))
                    limit = int(request.GET.get('limit', 100))
                    listing = fm.listing(system=system_id, file_path=file_path,
                                         offset=offset, limit=limit)
                    return JsonResponse(listing, encoder=AgaveJSONEncoder, safe=False)
                except HTTPError as e:
                    logger.exception('Unable to list files')
                    if e.response.status_code == 403:
                        return HttpResponseForbidden(e.response.text)
                    elif e.response.status_code >= 500:
                        return HttpResponseServerError(e.response.text)
                    elif e.response.status_code >= 400:
                        return HttpResponseBadRequest(e.response.text)

        return HttpResponseBadRequest()