Exemple #1
0
    def post(self, request, file_mgr_name, system_id, file_path):
        if request.is_ajax():
            body = json.loads(request.body)
        else:
            body = request.POST.copy()

        if file_mgr_name == AgaveFileManager.NAME \
            or file_mgr_name == 'public':
            if not request.user.is_authenticated:
                return HttpResponseForbidden('Login required')

            fm = AgaveFileManager(agave_client=request.user.agave_oauth.client)
            username = body.get('username')
            permission = body.get('permission')
            try:
                pem = fm.share(system_id, file_path, username, permission)
                metrics.info('Data Depot',
                             extra = {
                                 'user': request.user.username,
                                 'sessionId': getattr(request.session, 'session_key', ''),
                                 'operation': 'data_depot_share',
                                 'info': {
                                     'systemId': system_id,
                                     'filePath': file_path}
                             })
                event_data = {
                    Notification.EVENT_TYPE: 'data_depot',
                    Notification.OPERATION: 'data_depot_share',
                    Notification.STATUS: Notification.SUCCESS,
                    Notification.USER: request.user.username,
                    Notification.MESSAGE: '{} permissions were granted to {}.'.format(permission, username),
                    Notification.EXTRA: {'system': system_id,
                                         'file_path': file_path,
                                         'username': username,
                                         'permission': permission}
                }
                Notification.objects.create(**event_data)
            except HTTPError as err:
                logger.debug(err.response.text)
                event_data = {
                    Notification.EVENT_TYPE: 'data_depot_share',
                    Notification.STATUS: Notification.ERROR,
                    Notification.OPERATION: 'data_depot_share',
                    Notification.USER: request.user.username,
                    Notification.MESSAGE: 'There was an error updating permissions for a file/folder.',
                    Notification.EXTRA: {'message': err.response.text}
                }
                Notification.objects.create(**event_data)
                return HttpResponseBadRequest(err.response.text)
            return JsonResponse(pem, encoder=AgaveJSONEncoder, safe=False)

        return HttpResponseBadRequest("Unsupported operation")
Exemple #2
0
    def post(self, request, file_mgr_name, system_id, file_path):
        if request.is_ajax():
            body = json.loads(request.body)
        else:
            body = request.POST.copy()

        if file_mgr_name == AgaveFileManager.NAME \
            or file_mgr_name == 'public':
            if not request.user.is_authenticated():
                return HttpResponseForbidden('Log in required')

            fm = AgaveFileManager(agave_client=request.user.agave_oauth.client)
            username = body.get('username')
            permission = body.get('permission')

            pem = fm.share(system_id, file_path, username, permission)
            return JsonResponse(pem, encoder=AgaveJSONEncoder, safe=False)

        return HttpResponseBadRequest("Unsupported operation")