def test_can_find_ticket_by_product_and_id(self): """ Can find ticket given #prefix-id""" product2 = "tp2" self._load_product_from_data(self.global_env, product2) p2_env = ProductEnvironment(self.global_env, product2) t1 = self._insert_and_load_ticket_with_env(p2_env, "T1") trs = TicketRelationsSpecifics(self.env) ticket = trs.find_ticket("#%s-%d" % (product2, t1.id)) self.assertEqual(ticket.id, 1)
def test_can_find_ticket_by_id_from_different_env(self): """ Can find ticket from different env given #id""" product2 = "tp2" self._load_product_from_data(self.global_env, product2) p2_env = ProductEnvironment(self.global_env, product2) t1 = self._insert_and_load_ticket_with_env(p2_env, "T1") trs = TicketRelationsSpecifics(self.env) ticket = trs.find_ticket("#%d" % t1.id) self.assertEqual(ticket.id, 1)
def process_request(self, req): tid = req.args.get('id') if not tid: raise TracError(_('No ticket id provided.')) try: ticket = Ticket(self.env, tid) except ValueError: raise TracError(_('Invalid ticket id.')) req.perm.require('TICKET_VIEW') relsys = RelationsSystem(self.env) data = { 'relation': {}, } if req.method == 'POST': # for modifying the relations TICKET_MODIFY is required for # both the source and the destination tickets req.perm.require('TICKET_MODIFY') if 'remove' in req.args: rellist = req.args.get('sel') if rellist: if isinstance(rellist, basestring): rellist = [rellist, ] self.remove_relations(req, rellist) elif 'add' in req.args: relation = dict( destination=req.args.get('dest_tid', ''), type=req.args.get('reltype', ''), comment=req.args.get('comment', ''), ) try: trs = TicketRelationsSpecifics(self.env) dest_ticket = trs.find_ticket(relation['destination']) except NoSuchTicketError: data['error'] = _('Invalid ticket ID.') else: req.perm.require('TICKET_MODIFY', Resource(dest_ticket.id)) try: dbrel = relsys.add(ticket, dest_ticket, relation['type'], relation['comment'], req.authname) except NoSuchTicketError: data['error'] = _('Invalid ticket ID.') except UnknownRelationType: data['error'] = _('Unknown relation type.') except ValidationError as ex: data['error'] = ex.message else: # Notify try: self.notify_relation_changed(dbrel) except Exception, e: self.log.error("Failure sending notification on" "creation of relation: %s", exception_to_unicode(e)) add_warning(req, _("The relation has been added, but an " "error occurred while sending" "notifications: " "%(message)s", message=to_unicode(e))) if 'error' in data: data['relation'] = relation else: raise TracError(_('Invalid operation.'))
def process_request(self, req): tid = req.args.get('id') if not tid: raise TracError(_('No ticket id provided.')) try: ticket = Ticket(self.env, tid) except ValueError: raise TracError(_('Invalid ticket id.')) req.perm.require('TICKET_VIEW') relsys = RelationsSystem(self.env) data = { 'relation': {}, } if req.method == 'POST': # for modifying the relations TICKET_MODIFY is required for # both the source and the destination tickets req.perm.require('TICKET_MODIFY') if 'remove' in req.args: rellist = req.args.get('sel') if rellist: if isinstance(rellist, basestring): rellist = [ rellist, ] self.remove_relations(req, rellist) elif 'add' in req.args: relation = dict( destination=req.args.get('dest_tid', ''), type=req.args.get('reltype', ''), comment=req.args.get('comment', ''), ) try: trs = TicketRelationsSpecifics(self.env) dest_ticket = trs.find_ticket(relation['destination']) except NoSuchTicketError: data['error'] = _('Invalid ticket ID.') else: req.perm.require('TICKET_MODIFY', Resource(dest_ticket.id)) try: relsys.add(ticket, dest_ticket, relation['type'], relation['comment'], req.authname) except NoSuchTicketError: data['error'] = _('Invalid ticket ID.') except UnknownRelationType: data['error'] = _('Unknown relation type.') except ValidationError as ex: data['error'] = ex.message if 'error' in data: data['relation'] = relation else: raise TracError(_('Invalid operation.')) data.update({ 'ticket': ticket, 'reltypes': sorted(relsys.get_relation_types().iteritems(), key=lambda x: x[0]), 'relations': self.get_ticket_relations(ticket), }) return 'relations_manage.html', data, None
def process_request(self, req): tid = req.args.get('id') if not tid: raise TracError(_('No ticket id provided.')) try: ticket = Ticket(self.env, tid) except ValueError: raise TracError(_('Invalid ticket id.')) # For access to the relation management, TICKET_MODIFY is required. req.perm.require('TICKET_MODIFY') relsys = RelationsSystem(self.env) data = { 'relation': {}, } if req.method == 'POST': # for modifying the relations TICKET_MODIFY is required for # both the source and the destination tickets if 'remove' in req.args: rellist = req.args.get('sel') if rellist: if isinstance(rellist, basestring): rellist = [ rellist, ] self.remove_relations(req, rellist) elif 'add' in req.args: relation = dict( destination=req.args.get('dest_tid', ''), type=req.args.get('reltype', ''), comment=req.args.get('comment', ''), ) try: trs = TicketRelationsSpecifics(self.env) dest_ticket = trs.find_ticket(relation['destination']) except NoSuchTicketError: data['error'] = _('Invalid ticket ID.') else: req.perm.require('TICKET_MODIFY', Resource(dest_ticket.id)) try: dbrel = relsys.add(ticket, dest_ticket, relation['type'], relation['comment'], req.authname) except NoSuchTicketError: data['error'] = _('Invalid ticket ID.') except UnknownRelationType: data['error'] = _('Unknown relation type.') except ValidationError as ex: data['error'] = ex.message else: # Notify try: self.notify_relation_changed(dbrel) except Exception, e: self.log.error( "Failure sending notification on" "creation of relation: %s", exception_to_unicode(e)) add_warning( req, _( "The relation has been added, " "but an error occurred while " "sending notifications: " "%(message)s", message=to_unicode(e))) if 'error' in data: data['relation'] = relation else: raise TracError(_('Invalid operation.'))
def process_request(self, req): tid = req.args.get('id') if not tid: raise TracError(_('No ticket id provided.')) try: ticket = Ticket(self.env, tid) except ValueError: raise TracError(_('Invalid ticket id.')) req.perm.require('TICKET_VIEW') relsys = RelationsSystem(self.env) data = { 'relation': {}, } if req.method == 'POST': # for modifying the relations TICKET_MODIFY is required for # both the source and the destination tickets req.perm.require('TICKET_MODIFY') if 'remove' in req.args: rellist = req.args.get('sel') if rellist: if isinstance(rellist, basestring): rellist = [rellist, ] self.remove_relations(req, rellist) elif 'add' in req.args: relation = dict( destination=req.args.get('dest_tid', ''), type=req.args.get('reltype', ''), comment=req.args.get('comment', ''), ) try: trs = TicketRelationsSpecifics(self.env) dest_ticket = trs.find_ticket(relation['destination']) except NoSuchTicketError: data['error'] = _('Invalid ticket ID.') else: req.perm.require('TICKET_MODIFY', Resource(dest_ticket.id)) try: relsys.add(ticket, dest_ticket, relation['type'], relation['comment'], req.authname) except NoSuchTicketError: data['error'] = _('Invalid ticket ID.') except UnknownRelationType: data['error'] = _('Unknown relation type.') except ValidationError as ex: data['error'] = ex.message if 'error' in data: data['relation'] = relation else: raise TracError(_('Invalid operation.')) data.update({ 'ticket': ticket, 'reltypes': sorted(relsys.get_relation_types().iteritems(), key=lambda x: x[0]), 'relations': self.get_ticket_relations(ticket), }) return 'relations_manage.html', data, None