Exemple #1
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
    def test_susbcriber_ignored_when_package_not_installed(self):
        # iterate events should not raise errors if package not installed
        self.uninstall()  # BBB: QI compatibility

        wc = ICheckinCheckoutPolicy(self.doc).checkout(self.folder)
        ICheckinCheckoutPolicy(wc).cancelCheckout()
            if content_type == 'Place':
                new_id = content.generateId(prefix='')
            content.invokeFactory(content_type, new_id)
            content = content[new_id]
            print 'Created {} with id "{}"'.format(content.portal_type, new_id)
        else:
            print 'Found {} with title "{}"'.format(content.portal_type,
                                                    content.Title())
        status = workflow.getStatusOf("pleiades_entity_workflow", content)
        review_state = status and status.get('review_state',
                                             'unknown') or 'unknown'
        print "Workflow state: {}.".format(review_state)

        container = aq_parent(content)
        if not creating:
            policy = ICheckinCheckoutPolicy(content)
            working_copy = policy.checkout(container)
            print "Checked out working copy: {}".format(working_copy.absolute_url_path())
        else:
            policy = None
            working_copy = content

        change_note = args.message
        for key, modify in values.items():
            if key == 'change_note':
                change_note = modify
                continue
            if key == 'id' and creating:
                print "Content id change ignored during creation."
                continue
            if key == 'id':
Exemple #4
0
 def __call__(self):
     policy = ICheckinCheckoutPolicy(self.context, None)
     relation = policy._get_relation_to_baseline()
     relation.from_object = relation.to_object
     relation._p_changed = True
     return "Fixed"
 def test_workingcopy_lock(self):
     self.setRoles(('Contributor', ))
     p1 = self.places['1']
     wc = ICheckinCheckoutPolicy(p1).checkout(self.places)
     xx = ICheckinCheckoutPolicy(wc).checkout(self.places)
 def test_baseline_lock(self):
     self.setRoles(('Contributor', ))
     p1 = self.places['1']
     wc = ICheckinCheckoutPolicy(p1).checkout(self.places)
     xx = ICheckinCheckoutPolicy(p1).checkout(self.places)
Exemple #7
0
 def policy(self):
     return ICheckinCheckoutPolicy(self.context)
Exemple #8
0
def serviceDescriptionUpdated(event):
    context = event.object
    updated_text = event.updated_text
    data = event.data
    old_national_text = context.getRawNationalText().decode('utf-8')
    old_text = context.getRawText().decode('utf-8')

    parent_folder = aq_parent(context)
    policy = ICheckinCheckoutPolicy(context)
    wc = policy.checkout(parent_folder)
    context.reindexObject('review_state')

    dmp = diff_match_patch()
    current_patch = dmp.patch_make(old_national_text, old_text)
    updated_text_patch = dmp.patch_make(old_national_text, updated_text)
    final_patch = current_patch + updated_text_patch
    new_text, success = dmp.patch_apply(final_patch, old_national_text)
    if False in success:
        # XXX
        # We need to handle the possibility of patching failing
        return
    wc.setNationalText(updated_text)
    wc.setText(new_text)
    if data:
        wc.setTitle(data['title'])
        wc.setDescription(data['description'])

    logger.info("Patched Service Description %s at %s" % \
        (context.Title(), context.absolute_url()))

    # Send notification
    creator = context.Creator()
    pm = getToolByName(context, 'portal_membership')
    creator = pm.getMemberById(creator)
    mail_to = None
    if creator is not None:
        mail_to = creator.getProperty('email')
    if not mail_to:
        registry = getUtility(IRegistry)
        mail_to = registry['jarn.kommuner.notifyEmail']
    if not mail_to:
        return

    request = context.REQUEST
    site_title = context.portal_properties.site_properties.title
    mail_template = getMultiAdapter((context, request), name='sd_mail')
    mail_text = mail_template(sd_title=wc.Title(),
                              sd_url=wc.absolute_url(),
                              site_title=site_title,
                              charset='utf-8')

    portal_state = getMultiAdapter((context, request),
                                   name=u"plone_portal_state")
    portal = portal_state.portal()
    mail_from = portal.getProperty('email_from_address')
    mail_host = getToolByName(context, 'MailHost')

    try:
        mail_host.send(mail_text.encode('utf-8'),
                       mto=mail_to,
                       mfrom=mail_from,
                       subject='Service Update',
                       charset='utf-8',
                       msg_type=None)
    except (MailHostError, SMTPException, socket.error):
        logger.error("""mail error: Attempt to send mail failed.\n%s""" %
                     traceback.format_exc())
Exemple #9
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())
Exemple #10
0
 def _get_working_copy(self):
     # needed to function as override. TODO: check this statement
     policy = ICheckinCheckoutPolicy(self.context)
     obj = policy.getWorkingCopy()
     return obj
Exemple #11
0
 def do_checkin(self, working_copy):
     policy = ICheckinCheckoutPolicy(working_copy)
     policy.checkin('')
Exemple #12
0
 def do_cancel(self, working_copy):
     policy = ICheckinCheckoutPolicy(working_copy)
     policy.cancelCheckout()
Exemple #13
0
 def do_checkout(self):
     policy = ICheckinCheckoutPolicy(self.obj)
     working_copy = policy.checkout(self.folder)
     return working_copy