Пример #1
0
    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
Пример #2
0
    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
Пример #3
0
    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
Пример #4
0
    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()
Пример #5
0
    def get_baseline_state(self):
        policy = ICheckinCheckoutPolicy(self.context)
        baseline = policy.getBaseline()
        if baseline is None:
            baseline = self.context

        return get_state(baseline)
Пример #6
0
    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
Пример #7
0
    def get_baseline_state(self):
        policy = ICheckinCheckoutPolicy(self.context)
        baseline = policy.getBaseline()
        if baseline is None:
            baseline = self.context

        return get_state(baseline)
Пример #8
0
 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
Пример #9
0
 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()
Пример #10
0
    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()
Пример #11
0
    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
Пример #12
0
 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())