def _hide_fields_not_configured_for_this_type(self, req, data): ticket_type = req.args[Key.TYPE] ats = AgiloTicketSystem(self.env) normalized_type = ats.normalize_type(ticket_type) data[Key.TYPE] = normalized_type fields_for_type = AgiloConfig(self.env).TYPES.get(normalized_type, []) create_perms = CoreTemplateProvider(self.env).create_permissions(req) if normalized_type in create_perms: for data_field in data['fields']: field_name = data_field[Key.NAME] if field_name == Key.TYPE: current_options = data_field.get('options', []) data_field['options'] = \ self._ticket_types_the_user_can_create_or_modify(normalized_type, current_options, create_perms) data['type_selection'] = data_field data_field[Key.SKIP] = True elif not field_name in fields_for_type: # Skip the field and the value if it's not for this type data_field[Key.SKIP] = True elif data_field[Key.SKIP] and (field_name not in MANDATORY_FIELDS): # We have to make all fields visible which belong to # this ticket type. Unfortunately, Trac just creates # a Ticket (though an AgiloTicket due to our monkey # patching) and we can't influence the instantiation # itself. # Therefore it just depends on the default ticket type # set in the environment what fields this ticket has. # Therefore some fields are marked skipped although they # should be displayed. # trac itself skips some fields because it want to have # more control over the positioning. We have to respect # that. # fs, 04.11.2008: I thought about moving this condition # to_prepare_fields where I think this code should live # but then I would have to copy all the conditions and # probably the code is here for a good reason so I'm # just adding it here. data_field[Key.SKIP] = False elif field_name == Key.OWNER and ats.restrict_owner: # we need to transform the field into a list of users ats.eventually_restrict_owner(data_field) elif len(create_perms) > 0: # Redirect to the first allowed type for the given user. first_allowed_type = create_perms[0] req.redirect(req.href.newticket(type=first_allowed_type)) else: if ticket_type not in AgiloConfig(self.env).ALIASES: raise TracError(u"Unkown type '%s'!" % ticket_type) raise TracError("You are not allowed to create a %s!" % ticket_type) return data
def _hide_fields_not_configured_for_this_type(self, req, data): ticket_type = req.args[Key.TYPE] ats = AgiloTicketSystem(self.env) normalized_type = ats.normalize_type(ticket_type) data[Key.TYPE] = normalized_type fields_for_type = AgiloConfig(self.env).TYPES.get(normalized_type, []) create_perms = CoreTemplateProvider(self.env).create_permissions(req) if normalized_type in create_perms: for data_field in data['fields']: field_name = data_field[Key.NAME] if field_name == Key.TYPE: current_options = data_field.get('options', []) data_field['options'] = \ self._ticket_types_the_user_can_create_or_modify(normalized_type, current_options, create_perms) data['type_selection'] = data_field data_field[Key.SKIP] = True elif not field_name in fields_for_type: # Skip the field and the value if it's not for this type data_field[Key.SKIP] = True elif data_field[Key.SKIP] and (field_name not in MANDATORY_FIELDS): # We have to make all fields visible which belong to # this ticket type. Unfortunately, Trac just creates # a Ticket (though an AgiloTicket due to our monkey # patching) and we can't influence the instantiation # itself. # Therefore it just depends on the default ticket type # set in the environment what fields this ticket has. # Therefore some fields are marked skipped although they # should be displayed. # trac itself skips some fields because it want to have # more control over the positioning. We have to respect # that. # fs, 04.11.2008: I thought about moving this condition # to_prepare_fields where I think this code should live # but then I would have to copy all the conditions and # probably the code is here for a good reason so I'm # just adding it here. data_field[Key.SKIP] = False elif field_name == Key.OWNER and ats.restrict_owner: # we need to transform the field into a list of users ats.eventually_restrict_owner(data_field) elif len(create_perms) > 0: # Redirect to the first allowed type for the given user. first_allowed_type = create_perms[0] req.redirect(req.href.newticket(type=first_allowed_type)) else: if ticket_type not in AgiloConfig(self.env).ALIASES: raise TracError(u"Unkown type '%s'!" % ticket_type) raise TracError("You are not allowed to create a %s!" % ticket_type) return data
def test_just_return_input_if_no_alias_was_found(self): ticket_system = AgiloTicketSystem(self.env) self.assert_none(ticket_system.normalize_type('nonexisting_type'))
def test_can_map_alias_to_trac_type(self): ticket_system = AgiloTicketSystem(self.env) self.assert_equals(Type.TASK, ticket_system.normalize_type(Type.TASK)) self.assert_equals(Type.TASK, ticket_system.normalize_type('Task')) #Task alias