def unlock(self): storage_path = get_storage_path(self.context) LM = LockManager(self.context) path = '{}/xml_content.xml'.format(storage_path) LM.unlock(path, token=None) return 'unlocked'
def _check_lock(self, path, op): if not self.supports_locks: return True # flag set by tests in order to avoid false posititves ignore_errors = getattr(self, 'ignore_errors', False) try: context = zope.globalrequest.getRequest().PUBLISHED.context lm = LockManager(context) except AttributeError: lm = LockManager(None) try: log_info = lm.get_lock(path) except LockError: return owner = log_info['owner'] lock_mode = log_info['mode'] lock_owner = (owner == plone.api.user.get_current().getUserName()) allowed = LOCK_PERMISSION_MAP.get( lockstate(mode=lock_mode, op=op, lock_owner=lock_owner), _marker) msg = '(lock_mode={}, op={}, lock_owner={}'.format( lock_mode, op, lock_owner) if allowed is _marker and not ignore_errors: raise ValueError('No entry found for ({})'.format(msg)) if not allowed and not ignore_errors: raise FileIsLocked('File is locked ({})'.format(msg))
def lock(self): storage_path = get_storage_path(self.context) LM = LockManager(self.context) path = '{}/xml_content.xml'.format(storage_path) lock_info = LM.lock(path, mode='shared') return lock_info
def info(self): if not util.is_xml_content(self.context): return storage_path = get_storage_path(self.context) path = '{}/xml_content.xml'.format(storage_path) LM = LockManager(self.context) try: lock_info = LM.get_lock(path) except Exception as e: lock_info = None return dict(lock_info=lock_info, storage_key=util.get_storage_key(self.context), storage_path=util.get_storage_path(self.context))
def _check_lock(self, path, op): lm = LockManager(None) try: log_info = lm.get_lock(path) except LockError: return owner = log_info['owner'] lock_mode = log_info['mode'] lock_owner = (owner == plone.api.user.get_current().getUserName()) allowed = LOCK_PERMISSION_MAP.get( lockstate(mode=lock_mode, op=op, lock_owner=lock_owner), _marker) msg = '(lock_mode={}, op={}, lock_owner={}'.format( lock_mode, op, lock_owner) if allowed is _marker: raise ValueError('No entry found for ({})'.format(msg)) if not allowed: raise FileIsLocked('File is locked ({})'.format(msg))
def _check_lock(self, path, op): # flag set by tests in order to avoid false posititves ignore_errors = getattr(self, 'ignore_errors', False) lm = LockManager(None) try: log_info = lm.get_lock(path) except LockError: return owner = log_info['owner'] lock_mode = log_info['mode'] lock_owner = (owner == plone.api.user.get_current().getUserName()) allowed = LOCK_PERMISSION_MAP.get( lockstate(mode=lock_mode, op=op, lock_owner=lock_owner), _marker) msg = '(lock_mode={}, op={}, lock_owner={}'.format( lock_mode, op, lock_owner) if allowed is _marker and not ignore_errors: raise ValueError('No entry found for ({})'.format(msg)) if not allowed and not ignore_errors: raise FileIsLocked('File is locked ({})'.format(msg))
def lock_manager(self): return LockManager(self.portal)