コード例 #1
0
 def remove_all_account_manager_components_from_config(self):
     env = self._testenv.get_trac_environment()
     components = AgiloConfig(env).get_section('components')
     for name in components.get_options_by_prefix('acct_mgr',
                                                  chop_prefix=False):
         components.remove_option(name, save=False)
     components.save()
コード例 #2
0
 def setUp(self):
     self.super()
     config = AgiloConfig(self.env)
     # Adding properties for multiple calculated property testing
     # The problem is that at this point the linkConfiguration as been
     # already initialized so we will need to do it again manually
     config.change_option('actual_time', 'text', 
                          section=AgiloConfig.TICKET_CUSTOM)
     config.change_option(Type.TASK, 
                          'sprint, remaining_time, actual_time, estimated_time, owner, drp_resources',
                          section=AgiloConfig.AGILO_TYPES)
     config.change_option('story.calculate', 
                          'total_remaining_time=sum:get_outgoing.remaining_time, total_actual_time=sum:get_outgoing.actual_time',
                          section=AgiloConfig.AGILO_LINKS)
     config.save()
     
     self.assert_true(config.is_agilo_enabled)
     self.assert_true('actual_time' in config.get_list(Type.TASK, section=AgiloConfig.AGILO_TYPES))
     self.assert_true('actual_time' in config.get_fields_for_type().get(Type.TASK))
     self.assert_equals(config.get('story.calculate', section=AgiloConfig.AGILO_LINKS), 
                      'total_remaining_time=sum:get_outgoing.remaining_time, total_actual_time=sum:get_outgoing.actual_time')
     self._reset_links_configuration()
     # Creates tickets
     self.t1 = self.teh.create_ticket(Type.USER_STORY)
     self.t2 = self.teh.create_ticket(Type.TASK, 
                                      props={Key.REMAINING_TIME: u'20', 
                                             Key.RESOURCES: u'Tim, Tom'})
     self.t3 = self.teh.create_ticket(Type.TASK, 
                                      props={Key.REMAINING_TIME: u'10', 
                                             Key.RESOURCES: u'Tim, Tom'})
     # Now actual_time should be a valid field for Task...
     self.assert_not_none(self.t2.get_field('actual_time'))
コード例 #3
0
 def set_sprint_can_start_or_end_on_weekends(self):
     # The sprint must be running only for exactly one day, otherwise 
     # confirm commitment is not possible anymore (and the total capacity
     # might be different)
     env = self.testenv.get_trac_environment()
     config = AgiloConfig(env)
     config.change_option('sprints_can_start_or_end_on_weekends', True, section='agilo-general')
     config.save()
コード例 #4
0
 def set_sprint_can_start_or_end_on_weekends(self):
     # The sprint must be running only for exactly one day, otherwise
     # confirm commitment is not possible anymore (and the total capacity
     # might be different)
     env = self.testenv.get_trac_environment()
     config = AgiloConfig(env)
     config.change_option('sprints_can_start_or_end_on_weekends',
                          True,
                          section='agilo-general')
     config.save()
コード例 #5
0
 def test_reload_config(self):
     """Tests the reload of the config"""
     types = AgiloConfig(self.env).get_section(AgiloConfig.AGILO_TYPES)
     
     # Add a ticket type
     types.change_option('my_type', ', '.join([Key.PRIORITY, Key.COMPONENT]))
     types.change_option('my_type.alias', 'My Type')
     types.save()
     self.assert_true('my_type' in AgiloConfig(self.env).ALIASES, 
                      "Type not found in aliases, AgiloConfig not reloaded?")
コード例 #6
0
ファイル: ticket_xmlrpc_test.py プロジェクト: nagyist/agilo
    def setUp(self):
        self.super()
        self.tester.login_as(Usernames.admin)
        

        components = AgiloConfig(self.env).get_section('components')
        components.change_option("tracrpc.*", 'enabled')
        components.save()
        
        self.ticket1_id = self.tester.create_new_agilo_task('foo', 'abc')
        self.ticket2_id = self.tester.create_new_agilo_task('bar', 'def')
コード例 #7
0
ファイル: init.py プロジェクト: djangsters/agilo
 def agilo_was_installed(self):
     try:
         from acct_mgr.web_ui import EmailVerificationModule
     except ImportError:
         return
     if not self.env.is_component_enabled(EmailVerificationModule):
         return
     
     components = AgiloConfig(self.env).get_section('components')
     if self.was_email_verification_enabled_explicitely(components):
         return
     components.change_option(self.name_emailverificationmodule(), 'disabled')
     components.save()
コード例 #8
0
ファイル: init.py プロジェクト: nagyist/agilo
    def agilo_was_installed(self):
        try:
            from acct_mgr.web_ui import EmailVerificationModule
        except ImportError:
            return
        if not self.env.is_component_enabled(EmailVerificationModule):
            return

        components = AgiloConfig(self.env).get_section('components')
        if self.was_email_verification_enabled_explicitely(components):
            return
        components.change_option(self.name_emailverificationmodule(),
                                 'disabled')
        components.save()
コード例 #9
0
 def runTest(self):
     env = self._testenv.get_trac_environment()
     config = AgiloConfig(env).get_section(AgiloConfig.AGILO_LINKS)
     option_name = '%s.calculate' % Type.REQUIREMENT
     configured_properties = config.get_list(option_name)
     broken_definition = 'sum:get_outgoing.blubber'
     configured_properties.append(broken_definition)
     config.change_option(option_name, ', '.join(configured_properties))
     config.save()
     self._tester.login_as(Usernames.admin)
     page_url = self._tester.url + '/admin/agilo/types/%s' % Type.REQUIREMENT
     tc.go(page_url)
     tc.code(200)
     
     html = tc.show()
     assert "sum:get_outgoing.rd_points|type=story|story_priority=Mandatory" in html
     assert 'blubber' not in html
コード例 #10
0
 def sprints_can_start_and_end_anytime(self):
     config = AgiloConfig(self.env)
     config.change_option('sprints_can_start_or_end_on_weekends', True, section='agilo-general')
     config.save()
コード例 #11
0
 def remove_all_account_manager_components_from_config(self):
     env = self._testenv.get_trac_environment()
     components = AgiloConfig(env).get_section('components')
     for name in components.get_options_by_prefix('acct_mgr', chop_prefix=False):
         components.remove_option(name, save=False)
     components.save()
コード例 #12
0
 def set_cascade_delete_story_task(self):
     env = self.testenv.get_trac_environment()
     config = AgiloConfig(env)
     config.change_option('delete', 'task-story', section='agilo-links')
     config.save()
コード例 #13
0
 def sprints_can_start_and_end_anytime(self):
     config = AgiloConfig(self.env)
     config.change_option('sprints_can_start_or_end_on_weekends',
                          True,
                          section='agilo-general')
     config.save()
コード例 #14
0
ファイル: types.py プロジェクト: nagyist/agilo
class TypesAdminPanel(AgiloAdminPanel):
    """
    Administration panel for different ticket types and their fields.
    Needs to get imported in agilo/admin/__init__.py in order to appear
    on the web interface.
    """

    _type = 'types'
    _label = ('Types', _('Types'))

    def __init__(self):
        self.agilo_config = AgiloConfig(self.env)

    def _get_field_labels(self):
        """Returns a dictionary of fields and their labels."""
        labels = {}
        for f_name, label in self.agilo_config.LABELS.items():
            if f_name not in MANDATORY_FIELDS:
                labels[f_name] = label
        return labels

    def _get_fields(self, type_name=None):
        """
        If type_name is not set, return a dictionary of ticket types 
        and the corresponding fields as a list. If a type_name gets 
        passed, return a list of fields corresponding to this ticket 
        type.
        """
        fields = self.agilo_config.get_available_types(with_fields=True)
        if type_name:
            fields = fields.get(type_name)
        return fields

    def detail_save_view(self, req, cat, page, ticket_type):
        """Save the detail panel view"""
        # The types will be stored in lowercase and the space is not a
        # valid character for the config file key
        ticket_type = normalize_ticket_type(ticket_type)

        alias = req.args.get(Key.ALIAS)
        if alias:
            self.agilo_config.change_option('%s.%s' % (ticket_type, Key.ALIAS),
                                            alias,
                                            section=AgiloConfig.AGILO_TYPES,
                                            save=False)
        # save fields as string or comma-separated list of values
        # FIXME: (AT) after going crazy, it came out that some types are not
        # saved because there is no specific field assigned and the config
        # won't store the property in the trac.ini. So the agilo type will also
        # not be loaded, even if the alias would be set.
        fields = req.args.get(Key.FIELDS, '')
        # We have to save strings not lists
        if isinstance(fields, list):
            fields = ', '.join(fields)
        self.agilo_config.change_option(ticket_type,
                                        fields,
                                        section=AgiloConfig.AGILO_TYPES,
                                        save=False)
        calc = []
        for res, func in zip(req.args.getlist('result'),
                             req.args.getlist('function')):
            if res and func:
                configstring = u'%s=%s' % (res.strip(), func.strip())
                parsed = parse_calculated_field(configstring)
                if parsed == None:
                    msg = u"Wrong format for calculated property '%s'"
                    raise TracError(_(msg) % res)
                calc.append(configstring)
        calc = ','.join(calc)
        if calc:
            self.agilo_config.change_option(
                '%s.%s' % (ticket_type, LinkOption.CALCULATE),
                calc,
                section=AgiloConfig.AGILO_LINKS,
                save=False)
        self.agilo_config.save()

        # on 0.12 we need to reset the ticket fields explicitely as the synchronization
        # is not done with the trac.ini anymore
        if AgiloTicketSystem(self.env).is_trac_012():
            AgiloTicketSystem(self.env).reset_ticket_fields()
        return req.redirect(req.href.admin(cat, page))

    def detail_view(self, req, cat, page, ticket_type):
        # All keys are saved lower-cased, but this is not done
        # automatically for retrieval
        calc_prop = self.agilo_config.get_list(
            '%s.%s' % (ticket_type, LinkOption.CALCULATE),
            section=AgiloConfig.AGILO_LINKS)
        calculated_properties = []
        if len(calc_prop) > 0:
            for definition in calc_prop:
                parts = definition.split('=', 1)
                if len(parts) == 2:
                    property_name, formula = parts
                    calculated_properties.append(
                        (property_name.strip(), formula.strip()))
                else:
                    message = u"Ignoring broken definition for " \
                              "calculated property: %s" % definition
                    warning(self, message)
        data = {
            'calculate': calculated_properties,
            'view': 'detail',
            'type': ticket_type,
            'alias': self.agilo_config.ALIASES.get(ticket_type, ''),
            'type_fields': self._get_fields(ticket_type),
            'labels': self._get_field_labels(),
        }
        return 'agilo_admin_types.html', data

    def list_view(self, req, cat, page):
        data = {
            'view': 'list',
            'fields': self._get_fields(),
            'aliases': self.agilo_config.ALIASES,
            'labels': self._get_field_labels(),
        }
        return 'agilo_admin_types.html', data
コード例 #15
0
 def set_cascade_delete_story_task(self):
     env = self.testenv.get_trac_environment()
     config = AgiloConfig(env)
     config.change_option('delete', 'task-story', section='agilo-links')
     config.save()
コード例 #16
0
ファイル: custom_fields.py プロジェクト: nagyist/agilo
class CustomFields(Component):
    """ These methods should be part of TicketSystem API/Data Model.
    Adds update_custom_field and delete_custom_field methods.
    (The get_custom_fields is already part of the API - just redirect here,
     and add option to only get one named field back.)
    """
    def __init__(self, *args, **kwargs):
        """Initialize the component and set a TracConfig"""
        self.ticket_custom = \
            AgiloConfig(self.env).get_section(AgiloConfig.TICKET_CUSTOM)
        
    def get_custom_fields(self, field_name=None):
        """
        Returns the custom fields from TicketSystem component.
        Use a field name to find a specific custom field only
        """
        if not field_name:    # return full list
            return AgiloTicketSystem(self.env).get_custom_fields()
        else:                  # only return specific item with cfname
            all = AgiloTicketSystem(self.env).get_custom_fields()
            for item in all:
                if item[Key.NAME] == field_name:
                    return item
            return None        # item not found
    
    def _store_all_options_for_custom_field(self, customfield):
        added_keys = list()
        changed = False
        for key in customfield:
            if key == Key.NAME:
                continue
            elif key == Key.TYPE:
                config_key = customfield[Key.NAME]
            else:
                config_key = '%s.%s' % (customfield[Key.NAME], key)
            value = customfield[key]
            if isinstance(value, list):
                value = '|'.join(value)
            if value not in ['', None]:
                changed = True
                self.ticket_custom.change_option(config_key, value, save=False)
                added_keys.append(key)
        if changed:
            self._remove_old_keys(customfield[Key.NAME], added_keys)
            self.ticket_custom.save()
    
    def _del_custom_field_value(self, customfield, prop=None):
        """Deletes a property from a custom field"""
        if not prop:
            self.ticket_custom.remove_option(customfield[Key.NAME])
        else:
            self.ticket_custom.remove_option('%s.%s' % (customfield[Key.NAME], prop))
    
    def _validate_input(self, customfield, create):
        """Checks the input values and raises a TracError if severe problems
        are detected."""
        # Name, Type are required
        if not (customfield.get(Key.NAME) and customfield.get(Key.TYPE)):
            raise TracError("Custom field needs at least a name and type.")
        
        # Use lowercase custom fieldnames only
        f_name = unicode(customfield[Key.NAME]).lower()
        # Only alphanumeric characters (and [-_]) allowed for custom fieldname
        if re.search('^[a-z0-9-_]+$', f_name) == None:
            raise TracError("Only alphanumeric characters allowed for custom field name (a-z or 0-9 or -_).")
        # If Create, check that field does not already exist
        if create and self.ticket_custom.get(f_name):
            raise TracError("Can not create as field already exists.")
        
        # Check that it is a valid field type
        f_type = customfield[Key.TYPE]
        if not f_type in ('text', 'checkbox', 'select', 'radio', 'textarea'):
            raise TracError("%s is not a valid field type" % f_type)
        
        if (Key.ORDER in customfield) and (not str(customfield.get(Key.ORDER)).isdigit()):
            raise TracError("%s is not a valid number for %s" % (customfield.get(Key.ORDER), Key.ORDER))
        
        customfield[Key.NAME] = f_name
    
    def update_custom_field(self, customfield, create=False):
        """
        Update or create a new custom field (if requested).
        customfield is a dictionary with the following possible keys:
            name = name of field (alphanumeric only)
            type = text|checkbox|select|radio|textarea
            label = label description
            value = default value for field content
            options = options for select and radio types (list, leave first empty for optional)
            cols = number of columns for text area
            rows = number of rows for text area
            order = specify sort order for field
        """
        
        self._validate_input(customfield, create)
        f_type = customfield[Key.TYPE]
        if f_type == 'textarea':
            def set_default_value(key, default):
                if (key not in customfield) or \
                        (not unicode(customfield[key]).isdigit()):
                    customfield[key] = unicode(default)
            # dwt: why is this called twice?
            set_default_value(Key.COLS, 60)
            set_default_value(Key.COLS, 5)
        
        if create:
            number_of_custom_fields = len(self.get_custom_fields())
            # We assume that the currently added custom field is not present in 
            # the return value of get_custom_fields and we start counting from 0
            customfield[Key.ORDER] = str(number_of_custom_fields)
        
        self._store_all_options_for_custom_field(customfield)
        AgiloTicketSystem(self.env).reset_ticket_fields()
        # TODO: Check that you can change the type from select to something different
        # and the options are gone afterwards
    
    
    def _set_custom_field_value(self, customfield, prop=None):
        """Sets a value in the custom fields for a given property key"""
        config_key = value = None
        if prop:
            value = customfield.get(prop)
            if isinstance(value, list):
                value = '|'.join(value)
            config_key = '%s.%s' % (customfield[Key.NAME], prop)
        else:
            # Used to set the type
            config_key = customfield[Key.NAME]
            value = customfield[Key.TYPE]
        self.ticket_custom.change_option(config_key, value)
    
    def _remove_old_keys(self, fieldname, added_keys):
        for key in (Key.VALUE, Key.OPTIONS, Key.COLS, Key.ROWS):
            if key not in added_keys:
                self.ticket_custom.remove_option('%s.%s' % (fieldname, key), 
                                                 save=False)
    
    def delete_custom_field(self, field_name):
        """Deletes a custom field"""
        if not self.ticket_custom.get(field_name):
            return # Nothing to do here - cannot find field
        # Need to redo the order of fields that are after the field to be deleted
        order_to_delete = self.ticket_custom.get_int('%s.%s' % (field_name, Key.ORDER))
        cfs = self.get_custom_fields()
        for field in cfs:
            if field[Key.ORDER] > order_to_delete:
                field[Key.ORDER] -= 1
                self._set_custom_field_value(field, Key.ORDER)
            elif field[Key.NAME] == field_name:
                # Remove any data for the custom field (covering all bases)
                self._del_custom_field_value(field)
        # Save settings
        self.ticket_custom.save()
        AgiloTicketSystem(self.env).reset_ticket_fields()
コード例 #17
0
ファイル: types.py プロジェクト: djangsters/agilo
class TypesAdminPanel(AgiloAdminPanel):
    """
    Administration panel for different ticket types and their fields.
    Needs to get imported in agilo/admin/__init__.py in order to appear
    on the web interface.
    """
    
    _type = 'types'
    _label = ('Types', _('Types'))

    def __init__(self):
        self.agilo_config = AgiloConfig(self.env)

    def _get_field_labels(self):
        """Returns a dictionary of fields and their labels."""
        labels = {}
        for f_name, label in self.agilo_config.LABELS.items():
            if f_name not in MANDATORY_FIELDS:
                labels[f_name] = label
        return labels

    def _get_fields(self, type_name=None):
        """
        If type_name is not set, return a dictionary of ticket types 
        and the corresponding fields as a list. If a type_name gets 
        passed, return a list of fields corresponding to this ticket 
        type.
        """
        fields = self.agilo_config.get_available_types(with_fields=True)
        if type_name:
            fields = fields.get(type_name)
        return fields
    
    def detail_save_view(self, req, cat, page, ticket_type):
        """Save the detail panel view"""
        # The types will be stored in lowercase and the space is not a
        # valid character for the config file key
        ticket_type = normalize_ticket_type(ticket_type)
        
        alias = req.args.get(Key.ALIAS)
        if alias:
            self.agilo_config.change_option('%s.%s' % (ticket_type, Key.ALIAS), 
                                            alias, 
                                            section=AgiloConfig.AGILO_TYPES,
                                            save=False)
        # save fields as string or comma-separated list of values
        # FIXME: (AT) after going crazy, it came out that some types are not
        # saved because there is no specific field assigned and the config 
        # won't store the property in the trac.ini. So the agilo type will also
        # not be loaded, even if the alias would be set.
        fields = req.args.get(Key.FIELDS, '') 
        # We have to save strings not lists
        if isinstance(fields, list):
            fields = ', '.join(fields)
        self.agilo_config.change_option(ticket_type, 
                                        fields,
                                        section=AgiloConfig.AGILO_TYPES,
                                        save=False)
        calc = []
        for res, func in zip(req.args.getlist('result'), 
                             req.args.getlist('function')):
            if res and func:
                configstring = u'%s=%s' % (res.strip(), func.strip())
                parsed = parse_calculated_field(configstring)
                if parsed == None:
                    msg = u"Wrong format for calculated property '%s'"
                    raise TracError(_(msg) % res)
                calc.append(configstring)
        calc = ','.join(calc)
        if calc:
            self.agilo_config.change_option('%s.%s' % (ticket_type, 
                                                       LinkOption.CALCULATE), 
                                            calc,
                                            section=AgiloConfig.AGILO_LINKS,
                                            save=False)
        self.agilo_config.save()
        
        # on 0.12 we need to reset the ticket fields explicitely as the synchronization 
        # is not done with the trac.ini anymore
        if AgiloTicketSystem(self.env).is_trac_012():
            AgiloTicketSystem(self.env).reset_ticket_fields()
        return req.redirect(req.href.admin(cat, page))
    
    def detail_view(self, req, cat, page, ticket_type):
        # All keys are saved lower-cased, but this is not done 
        # automatically for retrieval
        calc_prop = self.agilo_config.get_list('%s.%s' % (ticket_type, 
                                                          LinkOption.CALCULATE),
                                               section=AgiloConfig.AGILO_LINKS)
        calculated_properties = []
        if len(calc_prop) > 0:
            for definition in calc_prop:
                parts = definition.split('=', 1)
                if len(parts) == 2:
                    property_name, formula = parts
                    calculated_properties.append((property_name.strip(), 
                                                  formula.strip()))
                else:
                    message = u"Ignoring broken definition for " \
                              "calculated property: %s" % definition
                    warning(self, message)
        data = {
            'calculate' : calculated_properties,
            'view': 'detail',
            'type': ticket_type,
            'alias' : self.agilo_config.ALIASES.get(ticket_type, ''),
            'type_fields' : self._get_fields(ticket_type),
            'labels' : self._get_field_labels(),
        }
        return 'agilo_admin_types.html', data
    
    def list_view(self, req, cat, page):
        data = {
            'view': 'list',
            'fields': self._get_fields(),
            'aliases' : self.agilo_config.ALIASES,
            'labels' : self._get_field_labels(),
        }
        return 'agilo_admin_types.html', data
コード例 #18
0
 def _restore_old_configuration(self):
     env = self.testenv.get_trac_environment()
     config = AgiloConfig(env)
     for (section, property), value in self._old_configuration.items():
         config.change_option(property, value, section)
     config.save()
コード例 #19
0
 def _restore_old_configuration(self):
     env = self.testenv.get_trac_environment()
     config = AgiloConfig(env)
     for (section, property), value in self._old_configuration.items():
         config.change_option(property, value, section)
     config.save()