Ejemplo n.º 1
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()
Ejemplo n.º 2
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
Ejemplo n.º 3
0
    def handle_edit(self):
        policy = ICheckinCheckoutPolicy(self.context)
        obj = policy.getWorkingCopy()

        #baseline = policy.getBaseline()

        if obj is None:
            obj = self.context

        state = get_state(obj)

        if state in ['private', 'sent']:
            url = '{0}/edit'.format(obj.absolute_url())
            return self.request.response.redirect(url)

        elif state == 'published':
            # create copy, go to it
            wc = self._checkout()
            url = '{0}/edit'.format(wc.absolute_url())
            return self.request.response.redirect(url)

        elif state == 'pending':
            # retract object, go to it
            transition(obj, to_state='sent')
            url = '{0}/edit'.format(obj.absolute_url())
            return self.request.response.redirect(url)

        raise ValueError ('unknown state')
Ejemplo n.º 4
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
Ejemplo n.º 5
0
    def get_wc(self, context):
        policy = ICheckinCheckoutPolicy(context, None)

        if policy is None:
            return False

        wc = policy.getWorkingCopy()
        return wc
Ejemplo n.º 6
0
    def has_checkout(self):
        policy = ICheckinCheckoutPolicy(self.context, None)

        if policy is None:
            return False

        wc = policy.getWorkingCopy()

        return wc is not None
Ejemplo n.º 7
0
    def get_working_copy(self):

        context = self.context
        policy = ICheckinCheckoutPolicy(context, None)

        if policy is None:
            return False

        wc = policy.getWorkingCopy()
        return wc
Ejemplo n.º 8
0
    def get_working_copy(self):

        context = self.context
        policy = ICheckinCheckoutPolicy(context, None)

        if policy is None:
            return False

        wc = policy.getWorkingCopy()
        return wc
Ejemplo n.º 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()
Ejemplo n.º 10
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
        wc = policy.getWorkingCopy()

        if wc is None:
            return False

        has_wc = (wc is not None)
        is_wc = (self.context.aq_inner.aq_self is wc.aq_inner.aq_self)
        res = has_wc and is_wc
        print "Checkout cancel allowed: ", res
        return res
Ejemplo n.º 11
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()
Ejemplo n.º 12
0
    def can_checkout(self):
        # user is Contributer, state is published, context is baseline and
        # doesn't have a checkout

        # if self.context.portal_type == 'Document':
        #     import pdb; pdb.set_trace()
        local_roles = get_roles(obj=self.context, inherit=True)

        control = getMultiAdapter((self.context, self.request),
                                  name="iterate_control")

        # currently enable the viewlet only for mtr page
        if 'mtr/countries' not in self.context.absolute_url_path():
            return False

        # this happens if the context is not registered for @@iterate_control
        # for example, content types we don't care about

        if not hasattr(control, 'is_checkout'):
            return False

        policy = ICheckinCheckoutPolicy(self.context, None)

        if policy is None:
            return False

        wc = policy.getWorkingCopy()

        is_baseline = not control.is_checkout()
        is_published = get_state(self.context) == 'published'
        # is_country_draft = get_state(self.context) == 'country_draft'
        is_contributor = 'Contributor' in local_roles
        has_wc = wc is not None

        correct_state = is_published    # or is_country_draft

        return is_baseline \
            and correct_state \
            and is_contributor \
            and (not has_wc)
Ejemplo n.º 13
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
Ejemplo n.º 14
0
 def _get_working_copy(self):
     # needed to function as override. TODO: check this statement
     policy = ICheckinCheckoutPolicy(self.context)
     obj = policy.getWorkingCopy()
     return obj