示例#1
0
    def lock(self, object):
        '''Locks an object'''
        locker = self.locker(object)
        if locker:
            raise LockingError, '%s is already locked' % pathOf(object)

        if self.auto_version:
            vt = getToolByName(self, 'portal_versions', None)
            if vt is not None:
                if (vt.isUnderVersionControl(object)
                    and not vt.isCheckedOut(object)):
                    object = vt.checkout(object)

        user = getSecurityManager().getUser()
        lockitem = LockItem(user)
        object.wl_setLock(lockitem.getLockToken(), lockitem)
示例#2
0
    def lock(self, object):
        '''Locks an object'''
        if not _checkPermission(LockObjects, object):
            raise LockingError, 'Inadequate permissions to lock %s' % object
        locker = self.locker(object)
        if locker:
            raise LockingError, '%s is already locked' % pathOf(object)

        if self.auto_version:
            vt = getToolByName(self, 'portal_versions', None)
            if vt is not None:
                if (vt.isUnderVersionControl(object)
                    and not vt.isCheckedOut(object)):
                    object = vt.checkout(object)

        user = getSecurityManager().getUser()
        lockitem = LockItem(user, timeout=(self.timeout_days * 86400))
        object.wl_setLock(lockitem.getLockToken(), lockitem)
示例#3
0
    def lock(self, obj):
        """Locks an object.
        """
        verifyPermission(LockObjects, obj)
        locker = self.locker(obj)
        if locker:
            raise LockingError, '%s is already locked' % pathOf(obj)

        if self.auto_version:
            vt = getToolByName(self, 'portal_versions', None)
            if vt is not None:
                if (vt.isUnderVersionControl(obj)
                        and not vt.isCheckedOut(obj)):
                    vt.checkout(obj)

        user = getSecurityManager().getUser()
        lockitem = LockItem(user, timeout=(self.timeout_days * 86400))
        obj.wl_setLock(lockitem.getLockToken(), lockitem)
        self.noteLock(obj, user.getId())
示例#4
0
    def lock(self, lock_type=STEALABLE_LOCK, children=False):
        settings = queryAdapter(self.context, ILockSettings)
        if settings is None:
            # No context specific adapter, is this a Plone site?
            pprops = getToolByName(self.context, 'portal_properties', None)
            if pprops is not None and 'site_properties' in pprops.objectIds():
                settings = pprops.site_properties
        if settings is not None and settings.lock_on_ttw_edit is False:
            return
        
        if not self.locked():
            user = getSecurityManager().getUser()
            depth = children and 'infinity' or 0
            lock = LockItem(user, depth=depth, timeout=DEFAULT_TIMEOUT)
            token = lock.getLockToken()
            self.context.wl_setLock(token, lock)

            self._locks()[lock_type.__name__] = dict(type = lock_type,
                                                  token = token)
示例#5
0
    def lock(self, lock_type=STEALABLE_LOCK, children=False):
        settings = queryAdapter(self.context, ILockSettings)
        if settings is None:
            registry = getUtility(IRegistry)
            settings = registry.forInterface(IEditingSchema, prefix='plone')
        if settings is not None and settings.lock_on_ttw_edit is False:
            return

        if not self.locked():
            user = getSecurityManager().getUser()
            depth = children and 'infinity' or 0
            lock = LockItem(user, depth=depth, timeout=lock_type.timeout * 60L)
            token = lock.getLockToken()
            self.context._v_safe_write = True
            self.context.wl_setLock(token, lock)

            locks = self._locks()
            locks[lock_type.__name__] = dict(type=lock_type, token=token)
            safeWrite(self.context)
示例#6
0
文件: LockTool.py 项目: goschtl/zope
    def lock(self, obj):
        """Locks an object.
        """
        verifyPermission(LockObjects, obj)
        locker = self.locker(obj)
        if locker:
            raise LockingError, '%s is already locked' % pathOf(obj)

        if self.auto_version:
            vt = getToolByName(self, 'portal_versions', None)
            if vt is not None:
                if (vt.isUnderVersionControl(obj)
                    and not vt.isCheckedOut(obj)):
                    vt.checkout(obj)

        user = getSecurityManager().getUser()
        lockitem = LockItem(user, timeout=(self.timeout_days * 86400))
        obj.wl_setLock(lockitem.getLockToken(), lockitem)
        self.noteLock(obj, user.getId())
示例#7
0
    def lock(self, lock_type=STEALABLE_LOCK, children=False):
        settings = queryAdapter(self.context, ILockSettings)
        if settings is None:
            # No context specific adapter, is this a Plone site?
            pprops = getToolByName(self.context, 'portal_properties', None)
            if pprops is not None and 'site_properties' in pprops.objectIds():
                settings = pprops.site_properties
        if settings is not None and settings.lock_on_ttw_edit is False:
            return

        if not self.locked():
            user = getSecurityManager().getUser()
            depth = children and 'infinity' or 0
            lock = LockItem(user, depth=depth, timeout=lock_type.timeout * 60L)
            token = lock.getLockToken()
            self.context.wl_setLock(token, lock)

            self._locks()[lock_type.__name__] = dict(type=lock_type,
                                                  token=token)
示例#8
0
    def lock(self, lock_type=STEALABLE_LOCK, children=False):
        settings = queryAdapter(self.context, ILockSettings)
        if settings is None:
            registry = getUtility(IRegistry)
            settings = registry.forInterface(IEditingSchema,
                                             prefix='plone')
        if settings is not None and settings.lock_on_ttw_edit is False:
            return

        if not self.locked():
            user = getSecurityManager().getUser()
            depth = children and 'infinity' or 0
            lock = LockItem(user, depth=depth, timeout=lock_type.timeout * 60L)
            token = lock.getLockToken()
            self.context._v_safe_write = True
            self.context.wl_setLock(token, lock)

            locks = self._locks()
            locks[lock_type.__name__] = dict(type=lock_type, token=token)
            safeWrite(self.context)
示例#9
0
    def apply(self, obj, creator=None, depth='infinity', token=None,
              result=None, url=None, top=1):
        """ Apply, built for recursion (so that we may lock subitems
        of a collection if requested """

        if result is None:
            result = StringIO()
            url = urlfix(self.request['URL'], 'LOCK')
            url = urlbase(url)
        iscol = isDavCollection(obj)
        if iscol and url[-1] != '/':
            url = url + '/'
        errmsg = None
        lock = None

        try:
            lock = LockItem(creator, self.owner, depth, self.timeout,
                            self.type, self.scope, token)
            if token is None:
                token = lock.getLockToken()

        except ValueError:
            errmsg = "412 Precondition Failed"
        except:
            errmsg = "403 Forbidden"

        try:
            if not IWriteLock.providedBy(obj):
                if top:
                    # This is the top level object in the apply, so we
                    # do want an error
                    errmsg = "405 Method Not Allowed"
                else:
                    # We're in an infinity request and a subobject does
                    # not support locking, so we'll just pass
                    pass
            elif obj.wl_isLocked():
                errmsg = "423 Locked"
            else:
                method = getattr(obj, 'wl_setLock')
                vld = getSecurityManager().validate(None, obj, 'wl_setLock',
                                                    method)
                if vld and token and (lock is not None):
                    obj.wl_setLock(token, lock)
                else:
                    errmsg = "403 Forbidden"
        except:
            errmsg = "403 Forbidden"

        if errmsg:
            if top and ((depth in (0, '0')) or (not iscol)):
                # We don't need to raise multistatus errors
                raise errmsg[4:]
            elif not result.getvalue():
                # We haven't had any errors yet, so our result is empty
                # and we need to set up the XML header
                result.write('<?xml version="1.0" encoding="utf-8" ?>\n' \
                             '<d:multistatus xmlns:d="DAV:">\n')
            result.write('<d:response>\n <d:href>%s</d:href>\n' % url)
            result.write(' <d:status>HTTP/1.1 %s</d:status>\n' % errmsg)
            result.write('</d:response>\n')

        if depth == 'infinity' and iscol:
            for ob in obj.objectValues():
                if hasattr(obj, '__dav_resource__'):
                    uri = urljoin(url, absattr(ob.getId()))
                    self.apply(ob, creator, depth, token, result,
                               uri, top=0)
        if not top:
            return token, result
        if result.getvalue():
            # One or more subitems probably failed, so close the multistatus
            # element and clear out all succesful locks
            result.write('</d:multistatus>')
            transaction.abort() # This *SHOULD* clear all succesful locks
        return token, result.getvalue()
示例#10
0
    def apply(self, obj, creator=None, depth='infinity', token=None,
              result=None, url=None, top=1):
        """ Apply, built for recursion (so that we may lock subitems
        of a collection if requested """

        if result is None:
            result = StringIO()
            url = urlfix(self.request['URL'], 'LOCK')
            url = urlbase(url)
        iscol = isDavCollection(obj)
        if iscol and url[-1] != '/':
            url = url + '/'
        errmsg = None
        lock = None

        try:
            lock = LockItem(creator, self.owner, depth, self.timeout,
                            self.type, self.scope, token)
            if token is None:
                token = lock.getLockToken()

        except ValueError:
            errmsg = "412 Precondition Failed"
        except:
            errmsg = "403 Forbidden"

        try:
            if not IWriteLock.providedBy(obj):
                if top:
                    # This is the top level object in the apply, so we
                    # do want an error
                    errmsg = "405 Method Not Allowed"
                else:
                    # We're in an infinity request and a subobject does
                    # not support locking, so we'll just pass
                    pass
            elif obj.wl_isLocked():
                errmsg = "423 Locked"
            else:
                method = getattr(obj, 'wl_setLock')
                vld = getSecurityManager().validate(None, obj, 'wl_setLock',
                                                    method)
                if vld and token and (lock is not None):
                    obj.wl_setLock(token, lock)
                else:
                    errmsg = "403 Forbidden"
        except:
            errmsg = "403 Forbidden"

        if errmsg:
            if top and ((depth in (0, '0')) or (not iscol)):
                # We don't need to raise multistatus errors
                raise errmsg[4:]
            elif not result.getvalue():
                # We haven't had any errors yet, so our result is empty
                # and we need to set up the XML header
                result.write('<?xml version="1.0" encoding="utf-8" ?>\n' \
                             '<d:multistatus xmlns:d="DAV:">\n')
            result.write('<d:response>\n <d:href>%s</d:href>\n' % url)
            result.write(' <d:status>HTTP/1.1 %s</d:status>\n' % errmsg)
            result.write('</d:response>\n')

        if depth == 'infinity' and iscol:
            for ob in obj.objectValues():
                if hasattr(obj, '__dav_resource__'):
                    uri = urljoin(url, absattr(ob.getId()))
                    self.apply(ob, creator, depth, token, result,
                               uri, top=0)
        if not top:
            return token, result
        if result.getvalue():
            # One or more subitems probably failed, so close the multistatus
            # element and clear out all succesful locks
            result.write('</d:multistatus>')
            transaction.abort() # This *SHOULD* clear all succesful locks
        return token, result.getvalue()