示例#1
0
    def __call__(self):
        context = aq_inner(self.context)
        request = aq_inner(self.request)
        form = request.form
        status = IStatusMessage(self.request)

        operation = request.get('operation', None)

        if operation == 'move_up':
            assignable = IRuleAssignmentManager(context)
            rule_id = request.get('rule_id')
            keys = list(assignable.keys())
            idx = keys.index(rule_id)
            del keys[idx]
            keys.insert(idx - 1, rule_id)
            assignable.updateOrder(keys)
        elif operation == 'move_down':
            assignable = IRuleAssignmentManager(context)
            rule_id = request.get('rule_id')
            keys = list(assignable.keys())
            idx = keys.index(rule_id)
            del keys[idx]
            keys.insert(idx + 1, rule_id)
            assignable.updateOrder(keys)
        elif 'form.button.AddAssignment' in form:
            rule_id = form.get('rule_id')
            api.assign_rule(self.context, rule_id)
        elif 'form.button.Delete' in form:
            rule_ids = form.get('rule_ids', ())
            for r in rule_ids:
                api.unassign_rule(self.context, r)

            status.addStatusMessage(_(u'Assignments deleted.'), type='info')
        elif 'form.button.Enable' in form:
            rule_ids = form.get('rule_ids', ())
            for r in rule_ids:
                api.edit_rule_assignment(context, r, enabled=True)

            status.addStatusMessage(_(u'Assignments enabled.'), type='info')
        elif 'form.button.Disable' in form:
            rule_ids = form.get('rule_ids', ())
            for r in rule_ids:
                api.edit_rule_assignment(context, r, enabled=False)

            status.addStatusMessage(_(u'Assignments disabled.'), type='info')
        elif 'form.button.Bubble' in form:
            rule_ids = form.get('rule_ids', ())
            for r in rule_ids:
                api.edit_rule_assignment(
                    context, r, bubbles=True, enabled=True)

            status.addStatusMessage(_(u'Changes saved.'), type='info')
        elif 'form.button.NoBubble' in form:
            rule_ids = form.get('rule_ids', ())
            for r in rule_ids:
                api.edit_rule_assignment(context, r, bubbles=False)

            status.addStatusMessage(_(u'Changes saved.'), type='info')

        return self.template()
示例#2
0
def copy_contentrules(source_object, target_object):
    """Copy contentrules.
    """
    source_assignable = IRuleAssignmentManager(source_object, None)
    if source_assignable is not None:
        try:
            IRuleAssignmentManager(target_object)
        except TypeError:
            logger.info(
                'Cound not assign contentrules to {0}'.format(
                    target_object.absolute_url()
                )
            )
            return
        rules_storage = getUtility(IRuleStorage)
        available_rules = [r for r in rules_storage]
        for rule_id in source_assignable:
            if rule_id not in available_rules:
                logger.info(
                    'Contentrule {0} does not exist, skip assignment!'.format(
                        rule_id
                    )
                )
                continue
            assign_rule(target_object, rule_id)
示例#3
0
def _activate_rule(rule_id, context=None):
    assignable = IRuleAssignmentManager(context)
    assignment = assignable.get(rule_id, None)
    if not assignment:
        assignment = assignable[rule_id] = RuleAssignment(rule_id)
    assignment.enabled = True
    assignment.bubbles = True
    apirules.assign_rule(context, assignment.__name__)
示例#4
0
    def apply_rule(self):
        'Apply content rule to requested folder'

        self.true_rule_id = self.rule_id.split('+')[-1]

        # 'form.button.AddAssignment'
        rules_api.assign_rule(self.context, self.true_rule_id)

        # imprints IFTTT marker on rules
        alsoProvides(self.rule, IFTTTMarker)
示例#5
0
def doOnInstall(site, addon_name):

    site_domain = platform.uname()[1]

    forum_id = 'forumail'
    forum_name = 'Forumail'

    user_id = 'forumailer'
    user_name = 'Foru Mailer'

    group_id = 'Forumailers'
    group_name = 'Forumailers'

    # Create forum:
    forum = api.content.create(type='Folder', title=forum_name, container=site)
    # Assign interface for mail-dropping via mailtoplone.base:
    mark(forum, IBlogMailDropBoxMarker)
    # Set default-view of forum:
    forum.setLayout('forumail_view')
    # Create group:
    api.group.create(groupname=group_id, title=group_name)
    # Assign group-permissions to forum:
    forum.manage_setLocalRoles(group_id, ['Contributor', 'Reader'])
    # Update content- and permission-change in portal_catalog:
    forum.reindexObject()
    forum.reindexObjectSecurity()

    # Import contentrule of profile 'forumail'
    # (! If this is done before content-creation and no user is assigned to group,
    # contentrule will righteously complain, that there's nobody to send the mail to.)
    # and complain, no recipients are designated:
    site.portal_setup.runAllImportStepsFromProfile(
        'profile-' + addon_name + ':' + addon_name.split('.')[1],
        ignore_dependencies=True)
    # Assign contentrule to forum:
    assign_rule(forum, forum_id)

    if site_domain != 'localhost.localdomain':

        user_mail = user_id + '@' + site_domain

        # Add user, we need at least one, so collective.contentrule.mailtogroup  will not complain:
        api.user.create(username=user_id,
                        password=user_id,
                        email=user_mail,
                        properties=dict(fullname=user_name))
        # Assign user to group:
        api.group.add_user(groupname=group_id, username=user_id)
        # Create forum-post, should trigger an email-noti:
        post = api.content.create(
            type='News Item',
            title='Welcome to the Forum of "%s"' % site.Title(),
            text='Express yourself, don\'t repress yourself!',
            container=forum)
示例#6
0
    def testRuleAssignmentAddedAPI(self):
        api.assign_rule(self.folder.f1.f11, 'r2', enabled=True, bubbles=True)
        self.assertTrue('r2' in self.f11a)
        self.assertTrue(self.f11a['r2'].enabled)
        self.assertTrue(self.f11a['r2'].bubbles)

        api.assign_rule(self.folder.f1.f11, 'r3', enabled=True, bubbles=False,
                        insert_before='r2')
        self.assertTrue('r3' in self.f11a)
        self.assertTrue(self.f11a['r3'].enabled)
        self.assertFalse(self.f11a['r3'].bubbles)

        self.assertEqual(self.f11a.keys(), ['r1', 'r3', 'r2'])
示例#7
0
def copy_contentrules(source_object, target_object):
    """Copy contentrules.
    """
    source_assignable = IRuleAssignmentManager(source_object, None)
    if source_assignable is not None:
        try:
            IRuleAssignmentManager(target_object)
        except TypeError:
            logger.info("Cound not assign contentrules to {0}".format(
                target_object.absolute_url()))
            return
        for rule_id in source_assignable:
            assign_rule(target_object, rule_id)
def copy_contentrules(source_object, target_object):
    """Copy contentrules.
    """
    source_assignable = IRuleAssignmentManager(source_object, None)
    if source_assignable is not None:
        try:
            IRuleAssignmentManager(target_object)
        except TypeError:
            logger.info("Cound not assign contentrules to {0}".format(
                target_object.absolute_url()))
            return
        for rule_id in source_assignable:
            assign_rule(target_object, rule_id)
示例#9
0
def doOnInstall(site, addon_name):

    site_domain = platform.uname()[1]

    forum_id = 'forumail'
    forum_name = 'Forumail'

    user_id = 'forumailer'
    user_name = 'Foru Mailer'

    group_id = 'Forumailers'
    group_name = 'Forumailers'

    # Create forum:    
    forum = api.content.create(type='Folder', title=forum_name, container=site)
    # Assign interface for mail-dropping via mailtoplone.base:
    mark(forum, IBlogMailDropBoxMarker)
    # Set default-view of forum:
    forum.setLayout('forumail_view')
    # Create group:
    api.group.create(groupname=group_id, title=group_name)
    # Assign group-permissions to forum:
    forum.manage_setLocalRoles(group_id, ['Contributor', 'Reader'])
    # Update content- and permission-change in portal_catalog:
    forum.reindexObject()
    forum.reindexObjectSecurity()

 
    # Import contentrule of profile 'forumail' 
    # (! If this is done before content-creation and no user is assigned to group,
    # contentrule will righteously complain, that there's nobody to send the mail to.)
    # and complain, no recipients are designated:
    site.portal_setup.runAllImportStepsFromProfile('profile-' + addon_name + ':' + addon_name.split('.')[1], ignore_dependencies=True)
    # Assign contentrule to forum:
    assign_rule(forum, forum_id)

    if site_domain != 'localhost.localdomain':
        
        user_mail = user_id + '@' + site_domain

        # Add user, we need at least one, so collective.contentrule.mailtogroup  will not complain:
        api.user.create(username=user_id, password=user_id, email=user_mail, properties=dict(fullname=user_name))
        # Assign user to group:
        api.group.add_user(groupname=group_id, username=user_id)
        # Create forum-post, should trigger an email-noti:
        post = api.content.create(type='News Item', title='Welcome to the Forum of "%s"'%site.Title(), text='Express yourself, don\'t repress yourself!', container=forum)
示例#10
0
def copy_contentrules(source_object, target_object):
    """Copy contentrules.
    """
    source_assignable = IRuleAssignmentManager(source_object, None)
    if source_assignable is not None:
        try:
            IRuleAssignmentManager(target_object)
        except TypeError:
            logger.info('Cound not assign contentrules to {0}'.format(
                target_object.absolute_url()))
            return
        rules_storage = getUtility(IRuleStorage)
        available_rules = [r for r in rules_storage]
        for rule_id in source_assignable:
            if rule_id not in available_rules:
                logger.info(
                    'Contentrule {0} does not exist, skip assignment!'.format(
                        rule_id))
                continue
            assign_rule(target_object, rule_id)
示例#11
0
 def globally_assign(self):
     self.authorize()
     portal = getToolByName(self.context, 'portal_url').getPortalObject()
     api.assign_rule(portal, self.context.__name__)
示例#12
0
 def globally_assign(self):
     self.authorize()
     portal = getToolByName(self.context, 'portal_url').getPortalObject()
     api.assign_rule(portal, self.context.__name__)
示例#13
0
    def _initRules(self, node):
        """Import rules from the given node
        """

        site = self.environ.getSite()
        storage = queryUtility(IRuleStorage)
        if storage is None:
            return

        for child in node.childNodes:
            if child.nodeName == 'rule':

                rule = None
                name = child.getAttribute('name')
                if name:
                    rule = storage.get(name, None)

                if rule is None:
                    rule = Rule()

                    if not name:
                        chooser = INameChooser(storage)
                        name = chooser.chooseName(None, rule)

                    storage[name] = rule
                else:
                    # Clear out conditions and actions since we're expecting
                    # new ones
                    del rule.conditions[:]
                    del rule.actions[:]

                rule.title = child.getAttribute('title')
                rule.description = child.getAttribute('description')
                event_name = child.getAttribute('event')
                rule.event = _resolveDottedName(event_name)
                if not rule.event:
                    raise ImportError('Can not import {0}'.format(event_name))

                rule.enabled = as_bool(child.getAttribute('enabled'), True)
                rule.stop = as_bool(child.getAttribute('stop-after'))
                rule.cascading = as_bool(child.getAttribute('cascading'))
                # Aq-wrap to enable complex setters for elements below
                # to work

                rule = rule.__of__(site)

                for rule_config_node in child.childNodes:
                    if rule_config_node.nodeName == 'conditions':
                        for condition_node in rule_config_node.childNodes:
                            if not condition_node.nodeName == 'condition':
                                continue

                            type_ = condition_node.getAttribute('type')
                            element_type = getUtility(IRuleCondition,
                                                      name=type_)
                            if element_type.factory is None:
                                continue

                            condition = element_type.factory()

                            # Aq-wrap in case of complex setters
                            condition = condition.__of__(rule)

                            handler = IRuleElementExportImportHandler(
                                condition)
                            handler.import_element(condition_node)

                            rule.conditions.append(aq_base(condition))

                    elif rule_config_node.nodeName == 'actions':
                        for action_node in rule_config_node.childNodes:
                            if not action_node.nodeName == 'action':
                                continue

                            type_ = action_node.getAttribute('type')
                            element_type = getUtility(IRuleAction, name=type_)
                            if element_type.factory is None:
                                continue

                            action = element_type.factory()

                            # Aq-wrap in case of complex setters
                            action = action.__of__(rule)

                            handler = IRuleElementExportImportHandler(action)
                            handler.import_element(action_node)

                            rule.actions.append(aq_base(action))

            elif child.nodeName == 'assignment':
                location = child.getAttribute('location')
                if location.startswith('/'):
                    location = location[1:]

                try:
                    container = site.unrestrictedTraverse(str(location))
                except KeyError:
                    continue

                name = child.getAttribute('name')
                api.assign_rule(
                    container,
                    name,
                    enabled=as_bool(child.getAttribute('enabled')),
                    bubbles=as_bool(child.getAttribute('bubbles')),
                    insert_before=child.getAttribute('insert-before'),
                )
示例#14
0
    def _initRules(self, node):
        """Import rules from the given node
        """

        site = self.environ.getSite()
        storage = queryUtility(IRuleStorage)
        if storage is None:
            return

        for child in node.childNodes:
            if child.nodeName == 'rule':

                rule = None
                name = child.getAttribute('name')
                if name:
                    rule = storage.get(name, None)

                if rule is None:
                    rule = Rule()

                    if not name:
                        chooser = INameChooser(storage)
                        name = chooser.chooseName(None, rule)

                    storage[name] = rule
                else:
                    # Clear out conditions and actions since we're expecting new ones
                    del rule.conditions[:]
                    del rule.actions[:]

                rule.title = child.getAttribute('title')
                rule.description = child.getAttribute('description')
                event_name = child.getAttribute('event')
                rule.event = _resolveDottedName(event_name)
                if not rule.event:
                    raise ImportError("Can not import %s" % event_name)

                rule.enabled = as_bool(child.getAttribute('enabled'), True)
                rule.stop = as_bool(child.getAttribute('stop-after'))
                rule.cascading = as_bool(child.getAttribute('cascading'))
                # Aq-wrap to enable complex setters for elements below
                # to work

                rule = rule.__of__(site)

                for rule_config_node in child.childNodes:
                    if rule_config_node.nodeName == 'conditions':
                        for condition_node in rule_config_node.childNodes:
                            if not condition_node.nodeName == 'condition':
                                continue

                            type_ = condition_node.getAttribute('type')
                            element_type = getUtility(IRuleCondition, name=type_)
                            if element_type.factory is None:
                                continue

                            condition = element_type.factory()

                            # Aq-wrap in case of complex setters
                            condition = condition.__of__(rule)

                            handler = IRuleElementExportImportHandler(condition)
                            handler.import_element(condition_node)

                            rule.conditions.append(aq_base(condition))

                    elif rule_config_node.nodeName == 'actions':
                        for action_node in rule_config_node.childNodes:
                            if not action_node.nodeName == 'action':
                                continue

                            type_ = action_node.getAttribute('type')
                            element_type = getUtility(IRuleAction, name=type_)
                            if element_type.factory is None:
                                continue

                            action = element_type.factory()

                            # Aq-wrap in case of complex setters
                            action = action.__of__(rule)

                            handler = IRuleElementExportImportHandler(action)
                            handler.import_element(action_node)

                            rule.actions.append(aq_base(action))

            elif child.nodeName == 'assignment':
                location = child.getAttribute('location')
                if location.startswith("/"):
                    location = location[1:]

                try:
                    container = site.unrestrictedTraverse(str(location))
                except KeyError:
                    continue

                name = child.getAttribute('name')
                api.assign_rule(container, name,
                                enabled=as_bool(child.getAttribute('enabled')),
                                bubbles=as_bool(child.getAttribute('bubbles')),
                                insert_before=child.getAttribute('insert-before'),
                                )