def checkout_allowed(self): """ Overrided to check for the checkout permission, as it is normal """ context = aq_inner(self.context) if not IIterateAware.providedBy(context): return False archiver = IObjectArchiver(context) if not archiver.isVersionable(): return False policy = ICheckinCheckoutPolicy(context, None) if policy is None: return False if policy.getWorkingCopy() is not None: return False # check if its is a checkout if policy.getBaseline() is not None: return False checkPermission = getSecurityManager().checkPermission if not checkPermission(CheckoutPermission, context): return False return True
def checkin_allowed(self): """Check if a checkin is allowed """ context = aq_inner(self.context) checkPermission = getSecurityManager().checkPermission if not interfaces.IIterateAware.providedBy(context): return False archiver = interfaces.IObjectArchiver(context) if not archiver.isVersionable(): return False if not IWorkingCopy.providedBy(context): return False policy = ICheckinCheckoutPolicy(context, None) if policy is None: return False original = policy.getBaseline() if original is None: return False can_modify = checkPermission( Products.CMFCore.permissions.ModifyPortalContent, original, ) if not can_modify: return False return True
def checkin_allowed(self): """ Overrided to check for the checkin permission, as it should be normal """ context = aq_inner(self.context) checkPermission = getSecurityManager().checkPermission if not IIterateAware.providedBy(context): return False archiver = IObjectArchiver(context) if not archiver.isVersionable(): return False if not IWorkingCopy.providedBy(context): return False policy = ICheckinCheckoutPolicy(context, None) if policy is None: return False try: original = policy.getBaseline() except: return False if original is None: return False checkPermission = getSecurityManager().checkPermission if not checkPermission(CheckinPermission, original): return False return True
def reply(self): # Disable CSRF protection if "IDisableCSRFProtection" in dir(plone.protect.interfaces): alsoProvides(self.request, plone.protect.interfaces.IDisableCSRFProtection) policy = ICheckinCheckoutPolicy(self.context) working_copy = policy.getWorkingCopy() if not policy.getBaseline(): # We are in the baseline, get the working copy policy policy = ICheckinCheckoutPolicy(working_copy) control = getMultiAdapter((working_copy, self.request), name="iterate_control") if not control.checkin_allowed(): pm = getToolByName(self.context, "portal_membership") if bool(pm.isAnonymousUser()): return self._error(401, "Not authenticated", "Checkin not allowed") else: return self._error(403, "Not authorized", "Checkin not allowed") policy.checkin("") return self.reply_no_content()
def get_baseline_state(self): policy = ICheckinCheckoutPolicy(self.context) baseline = policy.getBaseline() if baseline is None: baseline = self.context return get_state(baseline)
def checkout_allowed(self): """Check if a checkout is allowed. """ context = aq_inner(self.context) checkPermission = getSecurityManager().checkPermission if not interfaces.IIterateAware.providedBy(context): return False archiver = interfaces.IObjectArchiver(context) if not archiver.isVersionable(): return False policy = ICheckinCheckoutPolicy(context, None) if policy is None: return False if policy.getWorkingCopy() is not None: return False # check if its is a checkout if policy.getBaseline() is not None: return False can_check_out = checkPermission(permissions.CheckoutPermission, context) if not can_check_out: return False return True
def cancel_allowed(self): """Check to see if the user can cancel the checkout on the given working copy """ policy = ICheckinCheckoutPolicy(self.context, None) if policy is None: return False original = policy.getBaseline() return original is not None
def __call__(self): policy = ICheckinCheckoutPolicy(self.context) if IBaseline.providedBy(self.context): self.baseline = self.context self.working_copy = policy.getWorkingCopy() elif IWorkingCopy.providedBy(self.context): self.working_copy = self.context self.baseline = policy.getBaseline() else: raise AttributeError('Invalid Context') return self.index()
def reply(self): policy = ICheckinCheckoutPolicy(self.context) working_copy = policy.getWorkingCopy() if not policy.getBaseline(): # We are in the baseline, get the working copy policy policy = ICheckinCheckoutPolicy(working_copy) control = getMultiAdapter((working_copy, self.request), name="iterate_control") if not control.cancel_allowed(): return self._error(403, "Not authorized", "Cancel not allowed") baseline = policy.cancelCheckout() baseline.reindexObject() return self.reply_no_content()
def checkout_allowed(self): """Check if a checkout is allowed. """ context = aq_inner(self.context) if not interfaces.IIterateAware.providedBy(context): return False archiver = interfaces.IObjectArchiver(context) if not archiver.isVersionable(): return False policy = ICheckinCheckoutPolicy(context, None) if policy is None: return False if policy.getWorkingCopy() is not None: return False # check if its is a checkout if policy.getBaseline() is not None: return False return True
def handle_check(self): policy = ICheckinCheckoutPolicy(self.context) baseline = policy.getBaseline() if baseline is None: baseline = self.context return self.request.response.redirect(baseline.absolute_url())