Retrieve object and check permissions.

    Retrieve ObjectVersion of image being requested and check permission
    using the Invenio-Files-REST permission factory.
517929
def protect_api(uuid=None, **kwargs):
    
    bucket, version_id, key = uuid.split(':', 2)
    g.obj = ObjectResource.get_object(bucket, key, version_id)
    return g.obj
613783
def image_get(request, image_id):
    """"""
    image = glanceclient(request).images.get(image_id)
    return Image(image)
123917
def listobjects(self, bucket, versions):
        
        if versions is not missing:
            check_permission(
                current_permission_factory(bucket, 'bucket-read-versions'),
                hidden=False
            )
        return self.make_response(
            data=ObjectVersion.get_by_bucket(
                bucket.id, versions=versions is not missing).limit(1000).all(),
            context={
                'class': ObjectVersion,
                'bucket': bucket,
                'many': True,
            }
        )
79063
def get_managed_object(handle, class_id, params, inMo=None, in_heir=False,
                       dump=False):
    
    return handle.GetManagedObject(inMo, class_id, params,
                      inHierarchical=in_heir,
                      dumpXml=dump)
479913
def has_permission(self, permission, obj=None):
        
        if not permission:
            logger.warn("None permission is not allowed")
            return False
        if obj is None:
            return check_permission(permission, self.context)
        return check_permission(permission, api.get_object(obj))
905984
def fetch(self):
        
        params = values.of({})

        payload = self._version.fetch(
            'GET',
            self._uri,
            params=params,
        )

        return SyncListPermissionInstance(
            self._version,
            payload,
            service_sid=self._solution['service_sid'],
            list_sid=self._solution['list_sid'],
            identity=self._solution['identity'],
        )
1238366
def get(self, request, *args, **kwargs):
        
        private_file = self.get_private_file()

        if not self.can_access_file(private_file):
            return HttpResponseForbidden('Private storage access denied')

        if not private_file.exists():
            return self.serve_file_not_found(private_file)
        else:
            return self.serve_file(private_file)
683091
def check(self, user, permission, obj=_nothing):
        
        if not self.allows(user, permission, obj):
            raise AuthorizationError(
                'Can\'t {} object of class {}'.format(
                    permission, type(obj)))
483398
def get(self, permission_id, expand=[]):
        
        parent_url = self.client.get_url(self.parent_object._manager._URL_KEY, 'GET', 'single', {'id': self.parent_object.id})
        target_url = parent_url + self.client.get_url_path(
            self._URL_KEY, 'GET', 'single', {'permission_id': permission_id})
        return self._get(target_url, expand=expand)
79543
def get_object(self):
        
        queryset = self.filter_queryset(self.get_queryset())
        lookup_url_kwarg = self.lookup_url_kwarg or self.lookup_field
        identifier = self.kwargs[lookup_url_kwarg]
        section, name = self.get_section_and_name(identifier)
        filter_kwargs = {'section': section, 'name': name}
        obj = get_object_or_404(queryset, **filter_kwargs)

        # May raise a permission denied
        self.check_object_permissions(self.request, obj)

        return obj
454556
def get(self, obj, id, sub_object=None):
        
        self.url = '{}{}/{}'.format(self.base_url, obj, id)
        self.method = 'GET'
        if sub_object:
            self.url += '/' + sub_object
        self.resp = requests.get(url=self.url, auth=self.auth,
                                 headers=self.headers, cert=self.ca_cert)
        if self.__process_resp__(obj):
            return self.res
        return False
1224127
def check_parent_object_permissions(self, request, obj):
        
        for permission in self.get_parent_permissions():
            if not permission.has_object_permission(request, self, obj):
                self.permission_denied(request)
689451
def get_object(self):
        
        obj = super(PreviewWrapper, self).get_object()

        if not obj:
            raise http.Http404

        return obj
447738
def check_permissions(self, request):
        
        obj = (
            hasattr(self, 'get_controlled_object') and self.get_controlled_object() or
            hasattr(self, 'get_object') and self.get_object() or getattr(self, 'object', None)
        )
        user = request.user

        # Get the permissions to check
        perms = self.get_required_permissions(self)

        # Check permissions
        has_permissions = self.perform_permissions_check(user, obj, perms)

        if not has_permissions and not user.is_authenticated:
            return HttpResponseRedirect('{}?{}={}'.format(
                resolve_url(self.login_url),
                self.redirect_field_name,
                urlquote(request.get_full_path())
            ))
        elif not has_permissions:
            raise PermissionDenied
563703
def get_value(cls, object_version, key):
        """"""
        obj = cls.get(object_version, key)
        return obj.value if obj else None
364700
def getObject(self, url_or_requests_response, params=None):
        ''
        if isinstance(url_or_requests_response, requests.models.Response):
            # this is a raw xml response that we need to parse
            url = url_or_requests_response.url
            o = lxml.objectify.fromstring(url_or_requests_response.content)
        else:
            # this is an url that we need to fetch
            url = url_or_requests_response
            o = self.get(url, params=params) # (.get() will parse this for us)

        parent = os.path.dirname(url).replace('up.jottacloud.com', 'www.jottacloud.com')
        if o.tag == 'error':
            JFSError.raiseError(o, url)
        elif o.tag == 'device': return JFSDevice(o, jfs=self, parentpath=parent)
        elif o.tag == 'folder': return JFSFolder(o, jfs=self, parentpath=parent)
        elif o.tag == 'mountPoint': return JFSMountPoint(o, jfs=self, parentpath=parent)
        elif o.tag == 'restoredFiles': return JFSFile(o, jfs=self, parentpath=parent)
        elif o.tag == 'deleteFiles': return JFSFile(o, jfs=self, parentpath=parent)
        elif o.tag == 'file':
            return ProtoFile.factory(o, jfs=self, parentpath=parent)
#             try:
#                 if o.latestRevision.state == 'INCOMPLETE':
#                     return JFSIncompleteFile(o, jfs=self, parentpath=parent)
#                 elif o.latestRevision.state == 'CORRUPT':
#                     return JFSCorruptFile(o, jfs=self, parentpath=parent)
#             except AttributeError:
#                 return JFSFile(o, jfs=self, parentpath=parent)
        elif o.tag == 'enableSharing': return JFSenableSharing(o, jfs=self)
        elif o.tag == 'user':
            self.fs = o
            return self.fs
        elif o.tag == 'filedirlist': return JFSFileDirList(o, jfs=self, parentpath=parent)
        elif o.tag == 'searchresult': return JFSsearchresult(o, jfs=self)
        raise JFSError("invalid object: %s <- %s" % (repr(o), url_or_requests_response))
631237
def fetch(self):
        
        params = values.of({})

        payload = self._version.fetch(
            'GET',
            self._uri,
            params=params,
        )

        return DocumentPermissionInstance(
            self._version,
            payload,
            service_sid=self._solution['service_sid'],
            document_sid=self._solution['document_sid'],
            identity=self._solution['identity'],
        )