Ejemplo n.º 1
0
    def get_all_actions(self):
        actions = parse_workflow_config(self.ticket_workflow_section.options())

        has_new_state = any('new' in [a['newstate']] + a['oldstates']
                            for a in actions.itervalues())
        if has_new_state:
            # Special action that gets enabled if the current status no
            # longer exists, as no other action can then change its state.
            # (#5307/#11850)
            reset = {
                'default': 0,
                'label': 'Reset',
                'newstate': 'new',
                'oldstates': [],
                'operations': ['reset_workflow'],
                'permissions': ['TICKET_ADMIN']
            }
            for key, val in reset.items():
                actions['_reset'].setdefault(key, val)

        for name, info in actions.iteritems():
            for val in ('<none>', '< none >'):
                sub_val(actions[name]['oldstates'], val, None)
            if not info['newstate']:
                self.log.warning("Ticket workflow action '%s' doesn't define "
                                 "any transitions", name)
        return actions
Ejemplo n.º 2
0
    def get_all_actions_for_type(self, ticket_type):
        actions = get_workflow_config_by_type(self.config, ticket_type)
        if not actions:
            return actions

        # Special action that gets enabled if the current status no longer
        # exists, as no other action can then change its state. (#5307/#11850)
        reset = {
            'default': 0,
            'label': 'reset',
            'newstate': 'new',
            'oldstates': [],
            'operations': ['reset_workflow'],
            'permissions': ['TICKET_ADMIN']
        }
        for key, val in reset.items():
            actions['_reset'].setdefault(key, val)

        for name, info in actions.iteritems():
            for val in ('<none>', '< none >'):
                sub_val(actions[name]['oldstates'], val, None)
            if not info['newstate']:
                self.log.warning("Ticket workflow action '%s' doesn't define "
                                 "any transitions", name)
        return actions
Ejemplo n.º 3
0
def parse_workflow_config(rawactions):
    """Given a list of options from [ticket-workflow]"""

    required_attrs = {
        'oldstates': [],
        'newstate': '',
        'name': '',
        'label': '',
        'default': 0,
        'operations': [],
        'permissions': [],
    }
    optional_attrs = {
        'set_owner': [],
        'set_resolution': [],
    }
    known_attrs = required_attrs.copy()
    known_attrs.update(optional_attrs)

    actions = defaultdict(dict)
    for option, value in rawactions:
        parts = option.split('.')
        name = parts[0]
        if len(parts) == 1:
            try:
                # Base name, of the syntax: old,states,here -> newstate
                oldstates, newstate = [x.strip() for x in value.split('->')]
            except ValueError:
                continue  # Syntax error, a warning will be logged later
            actions[name]['oldstates'] = to_list(oldstates)
            actions[name]['newstate'] = newstate
        else:
            attribute = parts[1]
            if attribute not in known_attrs or \
                    isinstance(known_attrs[attribute], str):
                actions[name][attribute] = value
            elif isinstance(known_attrs[attribute], int):
                actions[name][attribute] = int(value)
            elif isinstance(known_attrs[attribute], list):
                actions[name][attribute] = to_list(value)

    for action, attributes in actions.items():
        if 'label' not in attributes:
            if 'name' in attributes:  # backwards-compatibility, #11828
                attributes['label'] = attributes['name']
            else:
                attributes['label'] = action.replace("_", " ").strip()
        for key, val in required_attrs.items():
            attributes.setdefault(key, val)
        for val in ('<none>', '< none >'):
            sub_val(attributes['oldstates'], val, None)

    return actions
Ejemplo n.º 4
0
    def get_all_actions(self):
        actions = parse_workflow_config(self.ticket_workflow_section.options())

        # Special action that gets enabled if the current status no longer
        # exists, as no other action can then change its state. (#5307/#11850)
        reset = {
            'default': 0,
            'label': 'reset',
            'newstate': 'new',
            'oldstates': [],
            'operations': ['reset_workflow'],
            'permissions': ['TICKET_ADMIN']
        }
        for key, val in reset.items():
            actions['_reset'].setdefault(key, val)

        for name, info in actions.iteritems():
            for val in ('<none>', '< none >'):
                sub_val(actions[name]['oldstates'], val, None)
            if not info['newstate']:
                self.log.warning("Ticket workflow action '%s' doesn't define "
                                 "any transitions", name)
        return actions