def createRule(self, context, rule_context, rule_id, rule_title, rule_description, rule_event, message, subject, for_types=None, area_id=None): """ Enabled types are taken from the Plone registry, or you can manually set them using for_types Id of the area (used for getting the notification group) is taken from current area, or by area_id param """ registry = queryUtility(IRegistry) settings = registry.forInterface(IGroupwareNotifySettings, check=False) #create the rule rule = Rule() rule.__name__ = rule_id rule.event = rule_event rule.title = rule_title rule.description = rule_description #add the rule to rule's storage storage = getUtility(IRuleStorage) # chooser = INameChooser(storage) if rule_id not in storage.keys(): storage[rule_id] = rule #set the action and add it to the rule action = MailForGroupwareNotificationAction(area_id) if settings and settings.default_email_sender: action.source = settings.default_email_sender action.sender = None action.subject = subject action.message = message rule.actions.append(action) if not for_types: #set the condition and add it to the rule if settings: behavior = ISelectableConstrainTypes(rule_context) allowed_types = behavior.getLocallyAllowedTypes() types_list = set(allowed_types).difference(settings.black_list) condition = PortalTypeCondition() condition.check_types=tuple(types_list) rule.conditions.append(condition) else: # explicit types condition=PortalTypeCondition() condition.check_types=tuple(for_types) rule.conditions.append(condition) logger.info('Created rule %s' % rule_id) #assignment rule_id=rule.id.replace('++rule++','') assignable = IRuleAssignmentManager(rule_context) assignable[rule_id] = RuleAssignment(rule_id) assignable[rule_id].bubbles=True get_assignments(storage[rule_id]).insert('/'.join(rule_context.getPhysicalPath())) logger.info('Enabled rule %s on %s' % (rule_id, rule_context.Title().decode('utf-8')))
def testExecute(self): e = PortalTypeCondition() e.check_types = ['Folder', 'Image'] ex = getMultiAdapter((self.portal, e, DummyEvent(self.folder)), IExecutable) self.assertTrue(ex()) ex = getMultiAdapter((self.portal, e, DummyEvent(self.portal)), IExecutable) self.assertFalse(ex()) self.folder.portal_types = None ex = getMultiAdapter((self.portal, e, DummyEvent(self.folder)), IExecutable) self.assertFalse(ex())
def testExecute(self): e = PortalTypeCondition() e.check_types = ['Folder', 'Image'] ex = getMultiAdapter((self.portal, e, DummyEvent(self.folder)), IExecutable) self.assertTrue(ex()) ex = getMultiAdapter((self.portal, e, DummyEvent(self.portal)), IExecutable) self.assertFalse(ex()) self.folder.portal_types = None ex = getMultiAdapter((self.portal, e, DummyEvent(self.folder)), IExecutable) self.assertFalse(ex())
def testInvokeEditView(self): element = getUtility(IRuleCondition, name='plone.conditions.PortalType') e = PortalTypeCondition() editview = getMultiAdapter((e, self.folder.REQUEST), name=element.editview) self.assertTrue(isinstance(editview, PortalTypeEditFormView))
def testExecute(self): e = PortalTypeCondition() e.check_types = ['Folder', 'Image'] ex = getMultiAdapter((self.portal, e, DummyEvent(self.folder)), IExecutable) self.assertTrue(ex()) ex = getMultiAdapter((self.portal, e, DummyEvent(self.portal)), IExecutable) self.assertFalse(ex()) self.folder.portal_types = None self.portal.getSiteManager().unregisterUtility(provided=ITypesTool) ex = getMultiAdapter((self.portal, e, DummyEvent(self.folder)), IExecutable) self.assertFalse(ex())
def testExecute(self): e = PortalTypeCondition() e.check_types = ['Folder', 'Image'] ex = getMultiAdapter( (self.portal, e, DummyEvent(self.folder)), IExecutable) self.assertTrue(ex()) ex = getMultiAdapter( (self.portal, e, DummyEvent(self.portal)), IExecutable) self.assertFalse(ex()) self.folder.portal_types = None self.portal.getSiteManager().unregisterUtility(provided=ITypesTool) ex = getMultiAdapter( (self.portal, e, DummyEvent(self.folder)), IExecutable) self.assertFalse(ex())