def get(self, request, file_mgr_name, system_id=None, file_path=None): """ GET handler """ offset = int(request.GET.get('offset', 0)) limit = int(request.GET.get('limit', 100)) query_string = request.GET.get('query_string') if file_mgr_name != ElasticFileManager.NAME or not query_string: return HttpResponseBadRequest() if system_id is None: system_id = ElasticFileManager.DEFAULT_SYSTEM_ID fmgr = ElasticFileManager() if not (request.GET.get('shared', False) or request.GET.get('projects', False)): listing = fmgr.search(system_id, request.user.username, query_string, offset=offset, limit=limit) elif request.GET.get('shared', False): listing = fmgr.search_shared(system_id, request.user.username, query_string, offset=offset, limit=limit) elif request.GET.get('projects', False): listing = fmgr.search_projects(request.user.username, query_string, offset=offset, limit=limit) return JsonResponse(listing)
def get(self, request, file_mgr_name, system_id=None, file_path=None): """ GET handler """ offset = int(request.GET.get('offset', 0)) limit = int(request.GET.get('limit', 100)) query_string = request.GET.get('query_string') if file_mgr_name != ElasticFileManager.NAME or not query_string: return HttpResponseBadRequest() if system_id is None: system_id = ElasticFileManager.DEFAULT_SYSTEM_ID fmgr = ElasticFileManager() if not request.GET.get('shared', False): if system_id == 'designsafe.storage.default': listing = fmgr.search(system_id, request.user.username, query_string, offset=offset, limit=limit) elif system_id == 'designsafe.storage.community': logger.debug("searching community...") listing = fmgr.search_community('designsafe.storage.community', query_string, offset=offset, limit=limit) else: listing = fmgr.search_shared(system_id, request.user.username, query_string, offset=offset, limit=limit) return JsonResponse(listing)
def get(self, request, file_mgr_name, system_id=None, file_path=None): """GET handler""" offset = int(request.GET.get('offset', 0)) limit = int(request.GET.get('limit', 100)) query_string = request.GET.get('query_string') logger.debug('offset: %s, limit: %s, query_string: %s' % (str(offset), str(limit), query_string)) if file_mgr_name != PublicElasticFileManager.NAME or not query_string: return HttpResponseBadRequest() if system_id is None: system_id = PublicElasticFileManager.DEFAULT_SYSTEM_ID if not request.user.is_authenticated: ag = get_user_model().objects.get( username='******').agave_oauth.client else: ag = request.user.agave_oauth.client if system_id == "nees.public" or system_id == "designsafe.storage.published": file_mgr = PublicElasticFileManager(ag) listing = file_mgr.search(system_id, query_string, offset=offset, limit=limit) elif system_id == "designsafe.storage.community": file_mgr = ElasticFileManager() listing = file_mgr.search_community('designsafe.storage.community', query_string, offset=offset, limit=limit) # logger.info(listing) return JsonResponse(listing)
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()
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()
def get(self, request, file_mgr_name, system_id = None, file_path = None): """ GET handler """ offset = int(request.GET.get('offset', 0)) limit = int(request.GET.get('limit', 100)) query_string = request.GET.get('query_string') if file_mgr_name != ElasticFileManager.NAME or not query_string: return HttpResponseBadRequest() if system_id is None: system_id = ElasticFileManager.DEFAULT_SYSTEM_ID fmgr = ElasticFileManager() if not request.GET.get('shared', False): listing = fmgr.search(system_id, request.user.username, query_string, offset=offset, limit=limit) else: listing = fmgr.search_shared(system_id, request.user.username, query_string, offset=offset, limit=limit) return JsonResponse(listing)
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()
def get(self, request, file_mgr_name, system_id=None, file_path=None): """GET handler.""" query_string = request.GET.get('queryString') offset = int(request.GET.get('offset', 0)) limit = int(request.GET.get('limit', 100)) status = request.GET.get('status', 'published') if file_mgr_name not in [ PublicElasticFileManager.NAME, 'community', 'published' ]: return HttpResponseBadRequest('Wrong Manager') if file_mgr_name == PublicElasticFileManager.NAME: if not request.user.is_authenticated: ag = get_user_model().objects.get( username='******').agave_oauth.client else: ag = request.user.agave_oauth.client if system_id is None or (file_path is None or file_path == '/'): system_id = PublicElasticFileManager.DEFAULT_SYSTEM_ID file_mgr = PublicElasticFileManager(ag) search_mgr = PublicElasticFileManager(ag) if query_string: listing = search_mgr.search(system_id, query_string, offset=offset, limit=limit) elif file_mgr_name == 'community': if not request.user.is_authenticated: ag = get_user_model().objects.get( username='******').agave_oauth.client else: ag = request.user.agave_oauth.client file_mgr = CommunityFileManager(ag) elif file_mgr_name == 'published': if not request.user.is_authenticated: ag = get_user_model().objects.get( username='******').agave_oauth.client else: ag = request.user.agave_oauth.client file_mgr = PublishedFileManager(ag) search_mgr = ElasticFileManager() if query_string: project_id = file_path.split('/')[1] listing = search_mgr.search_published_view( system_id, query_string, project_id=project_id, offset=offset, limit=limit) if query_string is None: listing = file_mgr.listing(system_id, file_path, offset=offset, limit=limit, status=status) listing = listing.to_dict() # logger.debug(listing.to_dict()['children'][0]) return JsonResponse(listing)