Esempio n. 1
0
    def get(self, request, file_mgr_name, system_id, file_path):
        fm_cls = FileLookupManager(file_mgr_name)
        fm = fm_cls(None)
        if fm.requires_auth and not request.user.is_authenticated:
            return HttpResponseForbidden('Login Required.')

        if file_mgr_name == 'agave':
            all = request.GET.get("all")
            client = request.user.agave_oauth.client
            fmgr = AgaveFileManager(agave_client=client)
            file_obj = fmgr.listing(system_id, file_path)
            if all:
                file_uuid = file_obj.uuid
                query = {"associationIds": file_uuid}
                objs = client.meta.listMetadata(q=json.dumps(query))
                return JsonResponse([o.value for o in objs], safe=False)
            file_dict = file_obj.to_dict()
            file_dict['keywords'] = file_obj.metadata.value['keywords']
            return JsonResponse(file_dict)
        elif file_mgr_name in ['public', 'community', 'published']:
            pems = [{'username': '******',
                    'permission': {'read': True,
                                'write': False,
                                'execute': False}}]
            if request.user.is_authenticated:
                pems.append({'username': request.user.username,
                            'permission': {'read': True,
                                            'write': False,
                                            'execute': False}})

            return JsonResponse(pems, safe=False)
        return HttpResponseBadRequest('Unsupported file manager.')
Esempio n. 2
0
    def put(self, request, file_mgr_name, system_id, file_path):
        fm_cls = FileLookupManager(file_mgr_name)
        fm = fm_cls(None)
        if fm.requires_auth and not request.user.is_authenticated:
            return HttpResponseForbidden('Login Required.')

        post_body = json.loads(request.body)
        metadata = post_body.get('metadata', {})
        if file_mgr_name == 'agave' or not metadata:
            fmgr = AgaveFileManager(agave_client=request.user.agave_oauth.client)
            try:
                file_obj = fmgr.listing(system_id, file_path)
                file_obj.metadata.update(metadata)
                file_dict = file_obj.to_dict()
                file_dict['keyword'] = file_obj.metadata.value['keywords']
                metrics.info('Data Depot',
                             extra = {
                                 'user': request.user.username,
                                 'sessionId': getattr(request.session, 'session_key', ''),
                                 'operation': 'data_depot_metadata_update',
                                 'info': {
                                     'systemId': system_id,
                                     'filePath': file_path,
                                     'metadata': metadata}
                             })
                event_data = {
                    Notification.EVENT_TYPE: 'data_depot',
                    Notification.OPERATION: 'data_depot_metadata_update',
                    Notification.STATUS: Notification.SUCCESS,
                    Notification.USER: request.user.username,
                    Notification.MESSAGE: 'Metadata was updated successfully.',
                    Notification.EXTRA: {'systemId': system_id,
                                         'filePath': file_path,
                                         'metadata': metadata}
                }
                Notification.objects.create(**event_data)
            except HTTPError as err:
                logger.debug(err.response.text)
                event_data = {
                    Notification.EVENT_TYPE: 'data_depot',
                    Notification.STATUS: Notification.ERROR,
                    Notification.OPERATION: 'data_depot_metadata_update',
                    Notification.USER: request.user.username,
                    Notification.MESSAGE: 'Metadata was updated successfully.',
                    Notification.EXTRA: {'systemId': system_id,
                                         'filePath': file_path,
                                         'metadata': metadata}
                }
                Notification.objects.create(**event_data)
            return JsonResponse(file_dict)

        return HttpResponseBadRequest('Unsupported file manager.')
Esempio n. 3
0
    def get(self, request, file_mgr_name, system_id=None, file_path=''):
        kwargs = {}

        offset = int(request.GET.get('offset', 0))
        limit = int(request.GET.get('limit', 100))
        query_string = request.GET.get('query_string', None)
        type_filters = request.GET.getlist('typeFilters', None)

        if type_filters:
            kwargs['type_filters'] = type_filters

        if not request.user.is_authenticated:
            client = get_user_model().objects.get(
                username='******').agave_oauth.client
        else:
            client = request.user.agave_oauth.client

        if system_id is None:
            system_id = AgaveFileManager.DEFAULT_SYSTEM_ID
        if system_id == AgaveFileManager.DEFAULT_SYSTEM_ID and not file_path:
            file_path = request.user.username
        if system_id == AgaveFileManager.DEFAULT_SYSTEM_ID and \
                (file_path.strip('/') == '$SHARE'):
            file_mgr_name = 'shared'
            kwargs['user_context'] = request.user.username

        fm_cls = FileLookupManager(file_mgr_name)
        fm = fm_cls(agave_client=client)

        if fm.requires_auth and not request.user.is_authenticated:
            return HttpResponseForbidden('Login Required.')
        if query_string:
            fm = SearchLookupManager(file_mgr_name)(request)
        listing = fm.listing(system=system_id,
                             file_path=file_path,
                             offset=offset,
                             limit=limit,
                             **kwargs)
        return JsonResponse(listing, encoder=AgaveJSONEncoder, safe=False)
Esempio n. 4
0
 def test_lookup_returns_for_community(self):
     self.assertEqual(FileLookupManager('community'), CommunityFileManager)
Esempio n. 5
0
 def test_lookup_returns_for_published_files(self):
     self.assertEqual(FileLookupManager('published'), PublishedFileManager)
Esempio n. 6
0
 def test_lookup_returns_for_publications(self):
     self.assertEqual(FileLookupManager('public'), PublicationsManager)
Esempio n. 7
0
 def test_lookup_returns_for_private(self):
     self.assertEqual(FileLookupManager('agave'), PrivateDataFileManager)
Esempio n. 8
0
 def test_lookup_returns_for_shared(self):
     self.assertEqual(FileLookupManager('shared'), SharedDataFileManager)