How to use the girder.constants.AccessType.READ function in girder

To help you get started, we’ve selected a few girder examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Kitware / flow / server / __init__.py View on Github external
def streamGen():
            start = time.time()
            endtime = None
            oldLog = ''
            while (time.time() - start < timeout and
                   cherrypy.engine.state == cherrypy.engine.states.STARTED and
                   (endtime is None or time.time() < endtime)):
                # Display new log info from this job since the
                # last execution of this loop.
                job = jobApi.model('job', 'jobs').load(
                    jobId,
                    user=jobApi.getCurrentUser(),
                    level=AccessType.READ)
                newLog = job['log']
                if newLog != oldLog:
                    start = time.time()
                    logDiff = newLog[newLog.find(oldLog) + len(oldLog):]
                    oldLog = newLog
                    # We send a separate message for each line,
                    # as I discovered that any information after the
                    # first newline was being lost...
                    for line in logDiff.rstrip().split('\n'):
                        yield sseMessage(line)
                if endtime is None:
                    result = AsyncResult(celeryTaskId,
                                         backend=getCeleryApp().backend)
                    if (result.state == celery.states.FAILURE or
                            result.state == celery.states.SUCCESS or
                            result.state == celery.states.REVOKED):
github Kitware / cumulus / girder / cumulus / cumulus_plugin / job.py View on Github external
def create(self, params):
        user = self.getCurrentUser()

        body = getBodyJson()

        self.requireParams(['name'], body)

        if 'commands' not in body and 'scriptId' not in body:
            raise RestException('command or scriptId must be provided',
                                code=400)

        if 'scriptId' in body:
            script = ModelImporter.model('script', 'cumulus').load(body['scriptId'],
                                                          user=user,
                                                          level=AccessType.READ)
            if not script:
                raise RestException('Script not found', 400)

            del body['scriptId']
            body['commands'] = script['commands']

        if 'onTerminate' in body and 'scriptId' in body['onTerminate']:
            script = ModelImporter.model('script', 'cumulus') \
                .load(body['onTerminate']['scriptId'], user=user,
                      level=AccessType.READ)
            if not script:
                raise RestException('onTerminate script not found', 400)

            del body['onTerminate']['scriptId']
            body['onTerminate']['commands'] = script['commands']
github Kitware / minerva / girder / models / user.py View on Github external
:param user: The user running the query. Only returns users that this
                     user can see.
        :param limit: Result limit.
        :param offset: Result offset.
        :param sort: The sort structure to pass to pymongo.
        :returns: Iterable of users.
        """
        # Perform the find; we'll do access-based filtering of the result set
        # afterward.
        if text is not None:
            cursor = self.textSearch(text, sort=sort)
        else:
            cursor = self.find({}, sort=sort)

        return self.filterResultsByPermission(
            cursor=cursor, user=user, level=AccessType.READ, limit=limit,
            offset=offset)
github girder / girder / girder / models / folder.py View on Github external
parentType = parentType.lower()
        if parentType not in ('folder', 'user', 'collection'):
            raise ValidationException('The parentType must be folder, collection, or user.')

        q = {
            'parentId': parent['_id'],
            'parentCollection': parentType
        }
        q.update(filters)

        # Perform the find; we'll do access-based filtering of the result set
        # afterward.
        cursor = self.find(q, sort=sort, **kwargs)

        return self.filterResultsByPermission(
            cursor=cursor, user=user, level=AccessType.READ, limit=limit, offset=offset)
github girder / girder / plugins / hashsum_download / girder_hashsum_download / __init__.py View on Github external
def load(self, info):
        HashedFile(info['apiRoot'].file)
        FileModel().exposeFields(level=AccessType.READ, fields=SUPPORTED_ALGORITHMS)

        events.bind('data.process', 'hashsum_download', _computeHashHook)
github Kitware / candela / app / resonantlab / server / anonymousAccess.py View on Github external
def itemInfo(self, item, params):
        info = {}

        anonUser = self.getAnonymousUser()
        user = self.getCurrentUser()
        if user is None:
            user = anonUser

        # Figure out the visibility of the item
        folder = self.model('folder').load(
            item['folderId'], user=user,
            level=AccessType.READ, exc=True)

        if item['baseParentType'] == 'user':
            if item['baseParentId'] == anonUser['_id']:
                info['visibility'] = 'PublicScratch'
            elif folder.get('public', False) is True:
                info['visibility'] = 'PublicUser'
            else:
                info['visibility'] = 'PrivateUser'
        else:
            info['visibility'] = 'PublicLibrary'

        # Figure out the editability of the item
        try:
            self.model('item').load(item['_id'],
                                    level=AccessType.WRITE,
                                    user=user,
github Kitware / minerva / server / rest / wfs_dataset.py View on Github external
               level=AccessType.READ)
    def createWfsDataset(self, wfsSource, params):
        baseURL = wfsSource['meta']['minerva']['wfs_params']['base_url']
        typeName = params['typeName']
        self.requireParams(('name'), params)
        name = params['name']
        minerva_metadata = {
            'dataset_type': 'wfs',
            #'legend': legend,
            'source_id': wfsSource['_id'],
            'type_name': typeName,
            'base_url': baseURL
        }
        dataset = self.constructDataset(name, minerva_metadata)
        return dataset
    createWfsDataset.description = (
github girder / girder / plugins / thumbnails / server / rest.py View on Github external
                    level=AccessType.READ)
        .param('width', 'The desired width.', required=False, dataType='integer', default=0)
        .param('height', 'The desired height.', required=False, dataType='integer', default=0)
        .param('crop', 'Whether to crop the image to preserve aspect ratio. '
               'Only used if both width and height parameters are nonzero.',
               dataType='boolean', required=False, default=True)
        .param('attachToId', 'The lifecycle of this thumbnail is bound to the '
               'resource specified by this ID.')
        .param('attachToType', 'The type of resource to which this thumbnail is attached.',
               enum=['folder', 'user', 'collection', 'item'])
        .errorResponse()
        .errorResponse(('Write access was denied on the attach destination.',
                        'Read access was denied on the file.'), 403)
    )
    def createThumbnail(self, file, width, height, crop, attachToId, attachToType):
        user = self.getCurrentUser()
github girder / girder / plugins / jobs / girder_jobs / job_rest.py View on Github external
def getJob(self, job):
        user = self.getCurrentUser()

        # If the job is not public check access
        if not job.get('public', False):
            if user:
                self._model.requireAccess(job, user, level=AccessType.READ)
            else:
                self.ensureTokenScopes('jobs.job_' + str(job['_id']))

        return job
github girder / girder / plugins / item_tasks / girder_item_tasks / rest.py View on Github external
def _transformInputs(self, inputs, token):
        """
        Validates and sanitizes the input bindings. If they are Girder inputs, adds
        the necessary token info. If the token does not allow DATA_READ, or if the user
        does not have read access to the resource, raises an AccessException.
        """
        transformed = {}
        for k, v in six.viewitems(inputs):
            if v['mode'] == 'girder':
                ensureTokenScopes(token, TokenScope.DATA_READ)
                rtype = v.get('resource_type', 'file')
                if rtype not in {'file', 'item', 'folder'}:
                    raise ValidationException('Invalid input resource_type: %s.' % rtype)

                resource = self.model(rtype).load(
                    v['id'], level=AccessType.READ, user=self.getCurrentUser(), exc=True)

                transformed[k] = utils.girderInputSpec(
                    resource, resourceType=rtype, token=token, dataFormat='none')
            elif v['mode'] == 'inline':
                transformed[k] = {
                    'mode': 'inline',
                    'data': v['data']
                }
            else:
                raise ValidationException('Invalid input mode: %s.' % v['mode'])

        return transformed