Esempio n. 1
0
    def process_request(self, req):
        req.perm.assert_permission('TICKET_VIEW')

        action = req.args.get('action', 'view')

        if not req.args.has_key('id'):
            req.redirect(self.env.href.wiki())

        db = self.env.get_db_cnx()
        id = int(req.args.get('id'))

        ticket = Ticket(self.env, id, db=db)
        reporter_id = util.get_reporter_id(req)

        if req.method == 'POST':
            if not req.args.has_key('preview'):
                self._do_save(req, db, ticket)
            else:
                # Use user supplied values
                ticket.populate(req.args)
                req.hdf['ticket.action'] = action
                req.hdf['ticket.ts'] = req.args.get('ts')
                req.hdf['ticket.reassign_owner'] = req.args.get('reassign_owner') \
                                                   or req.authname
                req.hdf['ticket.resolve_resolution'] = req.args.get('resolve_resolution')
                reporter_id = req.args.get('author')
                comment = req.args.get('comment')
                if comment:
                    req.hdf['ticket.comment'] = util.escape(comment)
                    # Wiki format a preview of comment
                    req.hdf['ticket.comment_preview'] = wiki_to_html(comment,
                                                                     self.env,
                                                                     req, db)
        else:
            req.hdf['ticket.reassign_owner'] = req.authname
            # Store a timestamp in order to detect "mid air collisions"
            req.hdf['ticket.ts'] = ticket.time_changed

        self._insert_ticket_data(req, db, ticket, reporter_id)

        # If the ticket is being shown in the context of a query, add
        # links to help navigate in the query result set
        if 'query_tickets' in req.session:
            tickets = req.session['query_tickets'].split()
            if str(id) in tickets:
                idx = tickets.index(str(ticket.id))
                if idx > 0:
                    add_link(req, 'first', self.env.href.ticket(tickets[0]),
                             'Ticket #%s' % tickets[0])
                    add_link(req, 'prev', self.env.href.ticket(tickets[idx - 1]),
                             'Ticket #%s' % tickets[idx - 1])
                if idx < len(tickets) - 1:
                    add_link(req, 'next', self.env.href.ticket(tickets[idx + 1]),
                             'Ticket #%s' % tickets[idx + 1])
                    add_link(req, 'last', self.env.href.ticket(tickets[-1]),
                             'Ticket #%s' % tickets[-1])
                add_link(req, 'up', req.session['query_href'])

        add_stylesheet(req, 'common/css/ticket.css')
        return 'ticket.cs', None
Esempio n. 2
0
    def _save_ticket_changes(self, req, env, log, selectedTickets, tickets,
                             values, comment, modify_changetime, send_notifications):
        for id in selectedTickets:
            if id in tickets:
                t = Ticket(env, int(id))
                new_changetime = datetime.now(utc)
                
                log_msg = ""
                if not modify_changetime:
                    original_changetime = to_timestamp(t.time_changed)
                
                _values = values.copy()
                for field in [f for f in values.keys() \
                              if f in self._fields_as_list]:
                    _values[field] = self._merge_keywords(t.values[field], 
                                                          values[field],
                                                          log)
                
                t.populate(_values)
                t.save_changes(req.authname, comment, when=new_changetime)
  
                if send_notifications:
                    tn = TicketNotifyEmail(env)
                    tn.notify(t, newticket=0, modtime=new_changetime)

                if not modify_changetime:
                    self._reset_changetime(env, original_changetime, t)
                    log_msg = "(changetime not modified)"

                log.debug('BatchModifyPlugin: saved changes to #%s %s' % 
                          (id, log_msg))
Esempio n. 3
0
        def _implementation(db):
            for id in selectedTickets:
                if id in tickets:
                    t = Ticket(env, int(id))
                    new_changetime = datetime.now(utc)

                    log_msg = ""
                    if not modify_changetime:
                        original_changetime = to_utimestamp(t.time_changed)

                    _values = new_values.copy()
                    for field in [f for f in new_values.keys() \
                                  if f in self._fields_as_list]:
                        _values[field] = self._merge_keywords(
                            t.values[field], new_values[field], log)

                    t.populate(_values)
                    t.save_changes(req.authname, comment, when=new_changetime)

                    if send_notifications:
                        tn = TicketNotifyEmail(env)
                        tn.notify(t, newticket=0, modtime=new_changetime)

                    if not modify_changetime:
                        self._reset_changetime(env, original_changetime, t)
                        log_msg = "(changetime not modified)"

                    log.debug('BatchModifyPlugin: saved changes to #%s %s' %
                              (id, log_msg))
Esempio n. 4
0
    def _handle_ripe_save(self, req):
        """ hander for save  """
        # TODO: workflow

        # get ticket id
        ticket_id = req.args.get("ticket_id")
        value = req.args.get("value", "").strip()
        field = req.args.get("field")
        old_value = req.args.get("old_value")

        # ticket
        ticket = Ticket(self.env, ticket_id)
        current_value = ticket.values.get(field)

        # validation
        if current_value != old_value and (old_value or current_value):
            self.log.info("Field value should be %s, got %s" % (repr(current_value), repr(old_value)))
            raise TracError("field value inconsistant.")

        # set params
        params = {}
        params[field] = value
        ticket.populate(params)

        # save ticket
        comment = "Updated from report"
        author = get_reporter_id(req, 'author')
        ticket.save_changes(author, comment)

        return value
Esempio n. 5
0
    def process_request(self, req):
        req.perm.assert_permission('TICKET_VIEW')

        action = req.args.get('action', 'view')

        if not req.args.has_key('id'):
            req.redirect(self.env.href.wiki())

        db = self.env.get_db_cnx()
        id = int(req.args.get('id'))

        ticket = Ticket(self.env, id, db=db)
        reporter_id = util.get_reporter_id(req)

        if req.method == 'POST':
            if not req.args.has_key('preview'):
                self._do_save(req, db, ticket)
            else:
                # Use user supplied values
                ticket.populate(req.args)
                req.hdf['ticket.action'] = action
                req.hdf['ticket.ts'] = req.args.get('ts')
                req.hdf['ticket.reassign_owner'] = req.args.get('reassign_owner') \
                                                   or req.authname
                req.hdf['ticket.resolve_resolution'] = req.args.get('resolve_resolution')
                reporter_id = req.args.get('author')
                comment = req.args.get('comment')
                if comment:
                    req.hdf['ticket.comment'] = comment
                    # Wiki format a preview of comment
                    req.hdf['ticket.comment_preview'] = wiki_to_html(comment,
                                                                     self.env,
                                                                     req, db)
        else:
            req.hdf['ticket.reassign_owner'] = req.authname
            # Store a timestamp in order to detect "mid air collisions"
            req.hdf['ticket.ts'] = ticket.time_changed

        self._insert_ticket_data(req, db, ticket, reporter_id)

        # If the ticket is being shown in the context of a query, add
        # links to help navigate in the query result set
        if 'query_tickets' in req.session:
            tickets = req.session['query_tickets'].split()
            if str(id) in tickets:
                idx = tickets.index(str(ticket.id))
                if idx > 0:
                    add_link(req, 'first', self.env.href.ticket(tickets[0]),
                             'Ticket #%s' % tickets[0])
                    add_link(req, 'prev', self.env.href.ticket(tickets[idx - 1]),
                             'Ticket #%s' % tickets[idx - 1])
                if idx < len(tickets) - 1:
                    add_link(req, 'next', self.env.href.ticket(tickets[idx + 1]),
                             'Ticket #%s' % tickets[idx + 1])
                    add_link(req, 'last', self.env.href.ticket(tickets[-1]),
                             'Ticket #%s' % tickets[-1])
                add_link(req, 'up', req.session['query_href'])

        add_stylesheet(req, 'common/css/ticket.css')
        return 'ticket.cs', None
Esempio n. 6
0
    def process_request(self, req):
        req.perm.assert_permission('TICKET_CREATE')

        db = self.env.get_db_cnx()

        if req.method == 'POST' and not req.args.has_key('preview'):
            self._do_create(req, db)

        ticket = Ticket(self.env, db=db)
        ticket.populate(req.args)
        ticket.values.setdefault('reporter', util.get_reporter_id(req))

        if ticket.values.has_key('description'):
            description = wiki_to_html(ticket['description'], self.env, req,
                                       db)
            req.hdf['newticket.description_preview'] = description

        req.hdf['title'] = 'New Ticket'
        req.hdf['newticket'] = dict(
            zip(ticket.values.keys(),
                [util.escape(value) for value in ticket.values.values()]))

        field_names = [
            field['name'] for field in ticket.fields if not field.get('custom')
        ]
        if 'owner' in field_names:
            curr_idx = field_names.index('owner')
            if 'cc' in field_names:
                insert_idx = field_names.index('cc')
            else:
                insert_idx = len(field_names)
            if curr_idx < insert_idx:
                ticket.fields.insert(insert_idx, ticket.fields[curr_idx])
                del ticket.fields[curr_idx]

        for field in ticket.fields:
            name = field['name']
            del field['name']
            if name in ('summary', 'reporter', 'description', 'type', 'status',
                        'resolution'):
                field['skip'] = True
            elif name == 'owner':
                field['label'] = 'Assign to'
            elif name == 'milestone':
                # Don't make completed milestones available for selection
                options = field['options']
                for option in field['options']:
                    milestone = Milestone(self.env, option, db=db)
                    if milestone.is_completed:
                        options.remove(option)
                field['options'] = options
            req.hdf['newticket.fields.' + name] = field

        add_stylesheet(req, 'common/css/ticket.css')
        return 'newticket.cs', None
Esempio n. 7
0
 def _implementation(db):
     """Apply each change to the ticket and save it."""
     for change in changes.strip(',').split(','):
         change_items = change.split(':')
         self.log.debug('WhiteboardModule: change_items=%s', change_items)
         t = Ticket(self.env, int(change_items[0]))
         values = {}
         values[field] = change_items[1]
         
         t.populate(values)
         t.save_changes(req.authname)
Esempio n. 8
0
        def _implementation(db):
            """Apply each change to the ticket and save it."""
            for change in changes.strip(',').split(','):
                change_items = change.split(':')
                self.log.debug('WhiteboardModule: change_items=%s',
                               change_items)
                t = Ticket(self.env, int(change_items[0]))
                values = {}
                values[field] = change_items[1]

                t.populate(values)
                t.save_changes(req.authname)
 def test_remove_all(self):
     test_name = sys._getframe().f_code.co_name
     expected = self.expected_results[test_name]
     ticket = Ticket(self.env)
     ticket.populate({'reporter': 'santa', 'summary': 'Summary line',
                      'description': 'Lorem ipsum dolor sit amet',
                      })
     ticket.insert()
     self.assertEqual(1, len(self._get_docs()))
     rv, output = self._execute('fulltext remove')
     self.assertEqual(expected, output)
     self.assertEqual(0, len(self._get_docs()))
Esempio n. 10
0
    def process_request(self, req):
        req.perm.assert_permission('TICKET_CREATE')

        db = self.env.get_db_cnx()

        if req.method == 'POST' and not req.args.has_key('preview'):
            self._do_create(req, db)

        ticket = Ticket(self.env, db=db)
        ticket.populate(req.args)
        ticket.values.setdefault('reporter', util.get_reporter_id(req))

        if ticket.values.has_key('description'):
            description = wiki_to_html(ticket['description'], self.env, req, db)
            req.hdf['newticket.description_preview'] = description

        req.hdf['title'] = 'New Ticket'
        req.hdf['newticket'] = ticket.values

        field_names = [field['name'] for field in ticket.fields
                       if not field.get('custom')]
        if 'owner' in field_names:
            curr_idx = field_names.index('owner')
            if 'cc' in field_names:
                insert_idx = field_names.index('cc')
            else:
                insert_idx = len(field_names)
            if curr_idx < insert_idx:
                ticket.fields.insert(insert_idx, ticket.fields[curr_idx])
                del ticket.fields[curr_idx]

        for field in ticket.fields:
            name = field['name']
            del field['name']
            if name in ('summary', 'reporter', 'description', 'type', 'status',
                        'resolution'):
                field['skip'] = True
            elif name == 'owner':
                field['label'] = 'Assign to'
            elif name == 'milestone':
                # Don't make completed milestones available for selection
                options = field['options'][:]
                for option in field['options']:
                    milestone = Milestone(self.env, option, db=db)
                    if milestone.is_completed:
                        options.remove(option)
                field['options'] = options
            req.hdf['newticket.fields.' + name] = field

        add_stylesheet(req, 'common/css/ticket.css')
        return 'newticket.cs', None
Esempio n. 11
0
 def test_remove_all(self):
     test_name = sys._getframe().f_code.co_name
     expected = self.expected_results[test_name]
     ticket = Ticket(self.env)
     ticket.populate({
         'reporter': 'santa',
         'summary': 'Summary line',
         'description': 'Lorem ipsum dolor sit amet',
     })
     ticket.insert()
     self.assertEqual(1, len(self._get_docs()))
     rv, output = self._execute('fulltext remove')
     self.assertEqual(expected, output)
     self.assertEqual(0, len(self._get_docs()))
Esempio n. 12
0
    def _batch_modify(self, req):
        tickets = req.session["query_tickets"].split(" ")
        comment = req.args.get("comment", "")
        values = {}

        for field in TicketSystem(self.env).get_ticket_fields():
            name = field["name"]
            if name not in ("summary", "reporter", "description", "type", "status", "resolution", "owner"):
                if req.args.has_key("bm_" + name):
                    values[name] = req.args.get(name)

        for id in tickets:
            t = Ticket(self.env, id)
            t.populate(values)
            t.save_changes(req.authname, comment)
Esempio n. 13
0
def run(options):

  #
  # defualt value
  #
  
  T_STATUS = 'new'
  T_MILESTONE = ''
  
  #
  # begin to create new  ticket
  #
  
  TRAC_ENV = os.environ.get('TRAC_ENV') or os.path.expanduser('/home/trac/glue')
  if not os.path.isdir(TRAC_ENV):
    print >>sys.stderr, "Set TRAC_ENV to the Trac project directory."
    #sys.exit(2)
    return {
      "status": 2
    }
  
  from trac.env import open_environment
  from trac.ticket import Ticket
  t = Ticket(open_environment(TRAC_ENV))
  
  info = dict(
    status=T_STATUS, 
    owner=options["owner"], reporter=options["reporter"], cc=options["cc"],
    milestone=T_MILESTONE, type=options["type"],
    summary=options["summary"].decode(sys.getfilesystemencoding()),
    description = options["description"].decode(sys.getfilesystemencoding())
  )
  
  t.populate(info)
  num = t.insert()
  if not num:
    print >>sys.stderr, "Ticket not created"
    print >>sys.stderr, vals
    #sys.exit(1)
    return {
      "status": 1
    }
  
  #print "Ticket #%d" % (num)
  return {
    "status": 0,
    "id": num
  }
Esempio n. 14
0
    def _do_create(self, req, db):
        if not req.args.get('summary'):
            raise TracError('Tickets must contain a summary.')

        ticket = Ticket(self.env, db=db)
        ticket.values.setdefault('reporter', util.get_reporter_id(req))
        ticket.populate(req.args)
        ticket.insert(db=db)
        db.commit()

        # Notify
        try:
            tn = TicketNotifyEmail(self.env)
            tn.notify(ticket, newticket=True)
        except Exception, e:
            self.log.exception("Failure sending notification on creation of "
                               "ticket #%s: %s" % (ticket.id, e))
Esempio n. 15
0
    def process_request(self, req, env, log):
        tickets = req.session['query_tickets'].split(' ')
        comment = req.args.get('batchmod_value_comment', '')
        modify_changetime = bool(
            req.args.get('batchmod_modify_changetime', False))

        values = self._get_new_ticket_values(req, env)
        self._check_for_resolution(values)
        self._remove_resolution_if_not_closed(values)

        selectedTickets = req.args.get('selectedTickets')
        log.debug('BatchModifyPlugin: selected tickets: %s', selectedTickets)
        selectedTickets = isinstance(
            selectedTickets,
            list) and selectedTickets or selectedTickets.split(',')
        if not selectedTickets:
            raise TracError, 'No tickets selected'

        for id in selectedTickets:
            if id in tickets:
                t = Ticket(env, int(id))

                log_msg = ""
                if not modify_changetime:
                    original_changetime = to_timestamp(t.time_changed)

                _values = values.copy()
                for field in [
                        f for f in values.keys() if f in self._fields_as_list
                ]:
                    _values[field] = self._merge_keywords(
                        t.values[field], values[field], log)

                t.populate(_values)
                t.save_changes(req.authname, comment)

                if not modify_changetime:
                    log_msg = "(changetime not modified)"
                    db = env.get_db_cnx()
                    db.cursor().execute(
                        "UPDATE ticket set changetime=%s where id=%s" %
                        (original_changetime, t.id))
                    db.commit()

                log.debug('BatchModifyPlugin: saved changes to #%s %s' %
                          (id, log_msg))
Esempio n. 16
0
    def _batch_modify(self, req):
        tickets = req.session['query_tickets'].split(' ')
        comment = req.args.get('comment', '')
        values = {}

        for field in TicketSystem(self.env).get_ticket_fields():
            name = field['name']
            if name not in ('summary', 'reporter', \
                        'description', 'type', 'status',
                        'resolution', 'owner'):
                if req.args.has_key('bm_' + name):
                    values[name] = req.args.get(name)

        for id in tickets:
            t = Ticket(self.env, id)
            t.populate(values)
            t.save_changes(req.authname, comment)
Esempio n. 17
0
    def test_delete_milestone_retarget_tickets(self):
        cursor = self.db.cursor()
        cursor.execute("INSERT INTO milestone (name) VALUES ('Test')")
        cursor.close()

        tkt1 = Ticket(self.env)
        tkt1.populate({'summary': 'Foo', 'milestone': 'Test'})
        tkt1.insert()
        tkt2 = Ticket(self.env)
        tkt2.populate({'summary': 'Bar', 'milestone': 'Test'})
        tkt2.insert()

        milestone = Milestone(self.env, 'Test')
        milestone.delete(retarget_to='Other')

        self.assertEqual('Other', Ticket(self.env, tkt1.id)['milestone'])
        self.assertEqual('Other', Ticket(self.env, tkt2.id)['milestone'])
Esempio n. 18
0
    def _process_request(self, req):
        field = req.args.get("whiteboard_group_by")
        changes = req.args.get("whiteboard_changes")

        self.log.debug("WhiteboardModule: field=%s", field)
        self.log.debug("WhiteboardModule: changes=%s", changes)

        db = self.env.get_db_cnx()
        for change in changes.strip(",").split(","):
            change_items = change.split(":")
            self.log.debug("WhiteboardModule: change_items=%s", change_items)
            t = Ticket(self.env, int(change_items[0]))
            values = {}
            values[field] = change_items[1]

            t.populate(values)
            t.save_changes(req.authname, "")
        db.commit()
Esempio n. 19
0
    def test_update_milestone_update_tickets(self):
        cursor = self.db.cursor()
        cursor.execute("INSERT INTO milestone (name) VALUES ('Test')")
        cursor.close()

        tkt1 = Ticket(self.env)
        tkt1.populate({'summary': 'Foo', 'milestone': 'Test'})
        tkt1.insert()
        tkt2 = Ticket(self.env)
        tkt2.populate({'summary': 'Bar', 'milestone': 'Test'})
        tkt2.insert()

        milestone = Milestone(self.env, 'Test')
        milestone.name = 'Testing'
        milestone.update()

        self.assertEqual('Testing', Ticket(self.env, tkt1.id)['milestone'])
        self.assertEqual('Testing', Ticket(self.env, tkt2.id)['milestone'])
Esempio n. 20
0
    def _do_create(self, req, db):
        if not req.args.get('summary'):
            raise TracError('Tickets must contain a summary.')

        ticket = Ticket(self.env, db=db)
        ticket.populate(req.args)
        ticket.values['reporter'] = get_reporter_id(req, 'reporter')
        self._validate_ticket(req, ticket)

        ticket.insert(db=db)
        db.commit()

        # Notify
        try:
            tn = TicketNotifyEmail(self.env)
            tn.notify(ticket, newticket=True)
        except Exception, e:
            self.log.exception("Failure sending notification on creation of "
                               "ticket #%s: %s" % (ticket.id, e))
Esempio n. 21
0
    def _do_create(self, req, db):
        if not req.args.get('summary'):
            raise TracError(u'Les tickets doivent contenir un intitulé.')

        ticket = Ticket(self.env, db=db)
        ticket.populate(req.args)
        ticket.values['reporter'] = get_reporter_id(req, 'reporter')
        self._validate_ticket(req, ticket)

        ticket.insert(db=db)
        db.commit()

        # Notify
        try:
            tn = TicketNotifyEmail(self.env)
            tn.notify(ticket, newticket=True)
        except Exception, e:
            self.log.exception(u"Impossible d'envoyer une notification sur la création du "
                               u"ticket #%s: %s" % (ticket.id, e))
Esempio n. 22
0
 def _save_ticket_changes(self, req, selected_tickets, new_values, comment,
                          action):
     """Save all of the changes to tickets."""
     when = datetime_now(utc)
     list_fields = self._get_list_fields()
     with self.env.db_transaction as db:
         for id in selected_tickets:
             t = Ticket(self.env, int(id))
             _values = new_values.copy()
             for field in list_fields:
                 if field in new_values:
                     old = t.values[field] if field in t.values else ''
                     new = new_values[field]
                     mode = req.args.get('batchmod_value_' + field +
                                         '_mode')
                     new2 = req.args.get(
                         'batchmod_value_' + field + '_secondary', '')
                     _values[field] = self._change_list(
                         old, new, new2, mode)
             controllers = list(self._get_action_controllers(
                 req, t, action))
             for controller in controllers:
                 _values.update(
                     controller.get_ticket_changes(req, t, action))
             t.populate(_values)
             t.save_changes(req.authname, comment, when=when)
             for controller in controllers:
                 controller.apply_action_side_effects(req, t, action)
     tn = BatchTicketNotifyEmail(self.env)
     try:
         tn.notify(selected_tickets, new_values, comment, action,
                   req.authname, when)
     except Exception, e:
         self.log.error(
             "Failure sending notification on ticket batch"
             "change: %s", exception_to_unicode(e))
         add_warning(
             req,
             tag_(
                 "The changes have been saved, but an "
                 "error occurred while sending "
                 "notifications: %(message)s",
                 message=to_unicode(e)))
Esempio n. 23
0
 def _process_request(self, req):
     field = req.args.get('whiteboard_group_by')
     changes = req.args.get('whiteboard_changes')
     
     self.log.debug('WhiteboardModule: field=%s', field)
     self.log.debug('WhiteboardModule: changes=%s', changes)
     
     db = self.env.get_db_cnx()
     for change in changes.strip(',').split(','):
         change_items = change.split(':')
         self.log.debug('WhiteboardModule: change_items=%s', change_items)
         t = Ticket(self.env, int(change_items[0]))
         values = {}
         values[field] = change_items[1]
         
         t.populate(values)
         t.save_changes(req.authname, '')        
     db.commit()
     
Esempio n. 24
0
    def _do_create(self, req, db):
        if not req.args.get('summary'):
            raise TracError(u'Les tickets doivent contenir un intitulé.')

        ticket = Ticket(self.env, db=db)
        ticket.populate(req.args)
        ticket.values['reporter'] = get_reporter_id(req, 'reporter')
        self._validate_ticket(req, ticket)

        ticket.insert(db=db)
        db.commit()

        # Notify
        try:
            tn = TicketNotifyEmail(self.env)
            tn.notify(ticket, newticket=True)
        except Exception, e:
            self.log.exception(
                u"Impossible d'envoyer une notification sur la création du "
                u"ticket #%s: %s" % (ticket.id, e))
Esempio n. 25
0
    def _do_create(self, req, db):
        if not req.args.get('summary'):
            raise TracError('Tickets must contain a summary.')

        ticket = Ticket(self.env, db=db)
        ticket.values.setdefault('reporter', util.get_reporter_id(req))
        ticket.populate(req.args)
        
        #Check for required fields
        ticket.validate_required_fields(req.args)
        
        ticket.insert(db=db)
        db.commit()

        # Notify
        try:
            tn = TicketNotifyEmail(self.env)
            tn.notify(ticket, newticket=True)
        except Exception, e:
            self.log.exception("Failure sending notification on creation of "
                               "ticket #%s: %s" % (ticket.id, e))
Esempio n. 26
0
 def createTicket(self, ticket_fields, env):
     """
     Creates the ticket in trac.
     
     Keyword arguments:
     ticket_fields -- A dictionary with the ticket fields.
     
     Returns: 
     The ticket number.
     """
     
     ticket = Ticket(env)
     
     # Lets populate the ticket with our fields.
     # The ticket has already set all default values for us from trac.ini
     # in it's init, nice huh. 
     # Don't write to ticket.values[] unless you know what you are doing
     ticket.populate(ticket_fields)
     
     # create the ticket
     return ticket.insert()
Esempio n. 27
0
    def createTicket(self, ticket_fields, env):
        """
        Creates the ticket in trac.
        
        Keyword arguments:
        ticket_fields -- A dictionary with the ticket fields.
        
        Returns: 
        The ticket number.
        """

        ticket = Ticket(env)

        # Lets populate the ticket with our fields.
        # The ticket has already set all default values for us from trac.ini
        # in it's init, nice huh.
        # Don't write to ticket.values[] unless you know what you are doing
        ticket.populate(ticket_fields)

        # create the ticket
        return ticket.insert()
Esempio n. 28
0
 def _save_ticket_changes(self, req, selected_tickets,
                          new_values, comment, action):
     """Save all of the changes to tickets."""
     when = datetime.now(utc)
     list_fields = self._get_list_fields()
     with self.env.db_transaction as db:
         for id in selected_tickets:
             t = Ticket(self.env, int(id))
             _values = new_values.copy()
             for field in list_fields:
                 if field in new_values:
                     old = t[field] if field in t else ''
                     new = new_values[field]
                     mode = req.args.get('batchmod_value_' + field +
                                         '_mode')
                     new2 = req.args.get('batchmod_value_' + field +
                                         '_secondary', '')
                     _values[field] = self._change_list(old, new, new2,
                                                        mode)
             controllers = list(self._get_action_controllers(req, t,
                                                             action))
             for controller in controllers:
                 _values.update(controller.get_ticket_changes(req, t,
                                                              action))
             t.populate(_values)
             t.save_changes(req.authname, comment, when=when)
             for controller in controllers:
                 controller.apply_action_side_effects(req, t, action)
     event = BatchTicketChangeEvent(selected_tickets, when,
                                    req.authname, comment, new_values,
                                    action)
     try:
         NotificationSystem(self.env).notify(event)
     except Exception as e:
         self.log.error("Failure sending notification on ticket batch"
                        "change: %s", exception_to_unicode(e))
         add_warning(req, tag_("The changes have been saved, but an "
                               "error occurred while sending "
                               "notifications: %(message)s",
                               message=to_unicode(e)))
Esempio n. 29
0
    def test_ticket(self):
        self.env.config.set('ticket-custom', 'foo', 'text')
        ticket = Ticket(self.env)
        ticket.populate({
            'reporter': 'santa',
            'summary': 'Summary line',
            'description': 'Lorem ipsum dolor sit amet',
            'foo': 'This is a custom field',
            'keywords': 'alpha bravo charlie',
            'cc': '[email protected], [email protected]',
        })
        ticket.insert()
        so = self._get_so()
        self.assertEquals('%s:ticket:1' % self.basename, so.doc_id)
        self.assertEquals('ticket', so.realm)
        self.assertEquals('1', so.id)
        self.assertTrue('#1' in so.title)
        self.assertTrue('Summary line' in so.title)
        self.assertEquals('santa', so.author)
        self.assertEquals(ticket['time'], so.created)
        self.assertEquals(ticket['changetime'], so.changed)
        self.assertTrue('*****@*****.**' in so.involved)
        self.assertTrue('*****@*****.**' in so.involved)
        self.assertTrue('bravo' in so.tags)
        self.assertTrue('Lorem ipsum' in so.oneline)
        self.assertTrue('Lorem ipsum' in so.body)

        original_time = ticket['time']
        ticket['description'] = 'No latin filler here'
        ticket.save_changes('Jack Sprat', 'Could eat no fat')
        so = self._get_so()
        self.assertEquals('%s:ticket:1' % self.basename, so.doc_id)
        self.assertEquals('ticket', so.realm)
        self.assertEquals('1', so.id)
        self.assertEquals(original_time, so.created)
        self.assertEquals(ticket['changetime'], so.changed)
        self.assertFalse('Lorem ipsum' in so.body)
        self.assertTrue('No latin filler here' in so.body)
        self.assertTrue('Could eat no fat' in so.comments)
    def test_ticket(self):
        self.env.config.set('ticket-custom', 'foo', 'text')
        ticket = Ticket(self.env)
        ticket.populate({'reporter': 'santa', 'summary': 'Summary line',
                         'description': 'Lorem ipsum dolor sit amet',
                         'foo': 'This is a custom field',
                         'keywords': 'alpha bravo charlie',
                         'cc': '[email protected], [email protected]',
                         })
        ticket.insert()
        so = self._get_so()
        self.assertEquals('%s:ticket:1' % self.basename, so.doc_id)
        self.assertEquals('ticket', so.realm)
        self.assertEquals('1', so.id)
        self.assertTrue('#1' in so.title)
        self.assertTrue('Summary line' in so.title)
        self.assertEquals('santa', so.author)
        self.assertEquals(ticket['time'], so.created)
        self.assertEquals(ticket['changetime'], so.changed)
        self.assertTrue('*****@*****.**' in so.involved)
        self.assertTrue('*****@*****.**' in so.involved)
        self.assertTrue('bravo' in so.tags)
        self.assertTrue('Lorem ipsum' in so.oneline)
        self.assertTrue('Lorem ipsum' in so.body)

        original_time = ticket['time']
        ticket['description'] = 'No latin filler here'
        ticket.save_changes('Jack Sprat', 'Could eat no fat')
        so = self._get_so()
        self.assertEquals('%s:ticket:1' % self.basename, so.doc_id)
        self.assertEquals('ticket', so.realm)
        self.assertEquals('1', so.id)
        self.assertEquals(original_time, so.created)
        self.assertEquals(ticket['changetime'], so.changed)
        self.assertFalse('Lorem ipsum' in so.body)
        self.assertTrue('No latin filler here' in so.body)
        self.assertTrue('Could eat no fat' in so.comments)
Esempio n. 31
0
    def process_request(self, req, env, log):
        tickets = req.session["query_tickets"].split(" ")
        comment = req.args.get("batchmod_value_comment", "")
        modify_changetime = bool(req.args.get("batchmod_modify_changetime", False))

        values = self._get_new_ticket_values(req, env)
        self._check_for_resolution(values)
        self._remove_resolution_if_not_closed(values)

        selectedTickets = req.args.get("selectedTickets")
        log.debug("BatchModifyPlugin: selected tickets: %s", selectedTickets)
        selectedTickets = isinstance(selectedTickets, list) and selectedTickets or selectedTickets.split(",")
        if not selectedTickets:
            raise TracError, "No tickets selected"

        for id in selectedTickets:
            if id in tickets:
                t = Ticket(env, int(id))

                log_msg = ""
                if not modify_changetime:
                    original_changetime = to_timestamp(t.time_changed)

                _values = values.copy()
                for field in [f for f in values.keys() if f in self._fields_as_list]:
                    _values[field] = self._merge_keywords(t.values[field], values[field], log)

                t.populate(_values)
                t.save_changes(req.authname, comment)

                if not modify_changetime:
                    log_msg = "(changetime not modified)"
                    db = env.get_db_cnx()
                    db.cursor().execute("UPDATE ticket set changetime=%s where id=%s" % (original_changetime, t.id))
                    db.commit()

                log.debug("BatchModifyPlugin: saved changes to #%s %s" % (id, log_msg))
    def _handle_ripe_save(self, req):
        """ hander for save  """
        # TODO: workflow

        # get ticket id
        ticket_id = req.args.get("ticket_id")
        value = req.args.get("value", "").strip()
        field = req.args.get("field")
        old_value = req.args.get("old_value")

        # ticket
        ticket = Ticket(self.env, ticket_id)
        current_value = ticket.values.get(field)

        # validation
        if current_value != old_value and (old_value or current_value):
            self.log.info("Field value should be %s, got %s" % (repr(current_value), repr(old_value)))
            raise TracError("field value inconsistant.")

        # set params
        params = {}
        params[field] = value
        ticket.populate(params)

        # save ticket
        now = datetime.now(utc)
        comment = self.change_comment
        author = get_reporter_id(req, 'author')
        cnum = ticket.save_changes(author, comment, when=now)
        if cnum and self.enable_notification:
            tn = TicketNotifyEmail(self.env)
            try:
                tn.notify(ticket, newticket=False, modtime=now)
            except Exception, e:
                self.log.error("Failure sending notification on change to "
                        "ticket #%s: %s", ticket.id, exception_to_unicode(e))
Esempio n. 33
0
    def generateTracTickets(self, req):
        """
            ok, it's a post so we know we are supposed to go ahead and create some TRAC tickets...the parameters that we care about are:
            #users ...this will be a list...
            #testtemplates ... this will be a list...
            #testcases  ... this will be a list...
            #version...this will be a string...
            #milestone...this will be a string...
            
            This method does one of two things.  It will either return: "True, URL" if ticket creation based on user input was succesful or "False, ErrorMessage" if
            the ticket creation failed.           
            
        """

        #grab the parameters that we care about out of the request object
        testRunKeyWord = str(req.args.get('testrun_keyword'))
        users = req.args.get('testrun_users')
        testTemplates = req.args.get('testrun_selectedtemplates')
        testcases = req.args.get('testrun_selectedtestcases')
        version = str(req.args.get('testrun_selectedversion'))
        milestone = str(req.args.get('testrun_selectedmilestone'))
        testConfiguration = str(req.args.get('testrun_testconfiguration'))

        #-----------------------------------ERROR CHECKING ON PARAMETERS--------------------------------------------
        #it might make sense to create a new method to validate the parameters passed in but for now we'll leave it.

        if testRunKeyWord == None:
            testRunKeyWord = ""
        testRunKeyWord = self.properties.trimOutAnyProblemStrings(
            testRunKeyWord
        )  #this is manually typed in...so it's probably a good idea to look for sqlInjection etc...

        if version == None:
            version = ""
        if milestone == None:
            milestone = ""
        if users == None:
            return False, "No users selected for test run"

        #check to see if the user, templates or testcases parameters is a str/unicode or a list (well if it isn't a unicode or str then it is a list)
        if isinstance(users, unicode):
            users = [users]

        if isinstance(users, str):
            users = [TracText.to_unicode(users)]

        if isinstance(testcases, unicode):
            testcases = [testcases]

        if isinstance(testcases, str):
            testcases = [testcases]

        if isinstance(testTemplates, unicode):
            testTemplates = [testTemplates]

        if isinstance(testTemplates, str):
            testTemplates = [TracText.to_unicode(testTemplates)]

        version = TracText.to_unicode(version).strip()
        milestone = TracText.to_unicode(milestone).strip()

        if testcases == None:
            testcases = []  #so we don't get a blow up later...
            if testTemplates == None:
                return False, "must select at least one testcase or test template to create a test run"

        elif testTemplates == None:
            testTemplates = []

        #--------------------------------------------DONE ERROR CHECKING -----------------------------------------------

        #create combined testcase list
        testcases = self.createCombinedTestCaseList(testTemplates, testcases,
                                                    req)

        allTestcases, errors = self.properties.getTestCases(
            self, req)  #fetch the testcases...
        if errors:
            return False, errors

        if allTestcases == None:
            return False, None

        #one last validation step
        errorMessages = []
        for aUser in users:
            for testId in testcases:
                testId = TracText.to_unicode(testId).strip()
                if testId in allTestcases:
                    continue
                else:
                    self.env.log.info("Testcase : " + testId +
                                      "  not found in master list ")
                    errorMessages.append(
                        "The test: " + testId +
                        ", doesn't match it's file name or you've specified it wrong in the testtemplates.xml file"
                    )

        if errorMessages:
            return False, errorMessages

        #ok this is where we actually create the tickets...
        db = self.env.get_db_cnx()
        for aUser in users:
            for testId in testcases:
                testId = testId.encode('ascii', 'ignore').strip()
                if testId in allTestcases:

                    test = allTestcases[testId]
                    ticket = Ticket(self.env, db=db)
                    ticket.populate(req.args)
                    ticket.values[
                        'reporter'] = req.authname  #the reporter is whoever is logged in
                    ticket.values['summary'] = "TestID: " + test.getId(
                    ) + " -- " + testConfiguration
                    ticket.values[
                        'description'] = "''''''Test Details:''''''\n\n" + test.getDescription(
                        ) + "\n\n''''''Expected result:'''''' \n\n" + test.getExpectedResult(
                        )
                    ticket.values['type'] = 'testcase'
                    ticket.values['status'] = 'new'
                    ticket.values['action'] = 'create'
                    ticket.values['component'] = test.getComponent()
                    ticket.values['owner'] = aUser
                    ticket.values['version'] = version
                    ticket.values['milestone'] = milestone
                    ticket.values['keywords'] = testRunKeyWord
                    #self._validate_ticket(req, ticket)   #probably should validate the ticket here.
                    ticket.insert(db=db)
                    db.commit()
                else:
                    return False, "The test " + testId + " specified in a test template or as the testcaseID in the test file does not exist in the master test list "

        #ok blow away the session vars incase someone trys to refresh the created test run page...no need to recreate all the tickets again...
        #thanks to the haxs in the reporty.py module...
        for var in ('users', 'testcases', 'testtemplates', 'milestone',
                    'version'):
            if req.session.has_key(var):
                del req.session[var]

        #redirect to a custom query report showing the created tickets
        return True, req.base_url + "/query?status=new&status=assigned&status=reopened&status=accepted&testcase_result=&version=" + version + "&milestone=" + milestone + "&type=testcase&order=priority&group=owner"
Esempio n. 34
0
    def generateTracTickets( self, req ) :
        """
            ok, it's a post so we know we are supposed to go ahead and create some TRAC tickets...the parameters that we care about are:
            #users ...this will be a list...
            #testtemplates ... this will be a list...
            #testcases  ... this will be a list...
            #version...this will be a string...
            #milestone...this will be a string...
            
            This method does one of two things.  It will either return: "True, URL" if ticket creation based on user input was succesful or "False, ErrorMessage" if
            the ticket creation failed.           
            
        """
        
        #grab the parameters that we care about out of the request object
        testRunKeyWord = str( req.args.get('testrun_keyword') )
        users = req.args.get('testrun_users')
        testTemplates = req.args.get('testrun_selectedtemplates')
        testcases = req.args.get('testrun_selectedtestcases')
        version = str( req.args.get('testrun_selectedversion'))
        milestone = str( req.args.get('testrun_selectedmilestone'))
        testConfiguration = str( req.args.get('testrun_testconfiguration'))
        
        #-----------------------------------ERROR CHECKING ON PARAMETERS--------------------------------------------
        #it might make sense to create a new method to validate the parameters passed in but for now we'll leave it.
        
        if testRunKeyWord == None : 
            testRunKeyWord = ""
        testRunKeyWord = self.properties.trimOutAnyProblemStrings(testRunKeyWord)  #this is manually typed in...so it's probably a good idea to look for sqlInjection etc...
        
        if version == None:
            version = ""
        if milestone == None:
            milestone = ""
        if users == None :
            return False, "No users selected for test run"
            
        #check to see if the user, templates or testcases parameters is a str/unicode or a list (well if it isn't a unicode or str then it is a list)
        if isinstance( users, unicode): 
            users = [users]
            
        if isinstance( users, str): 
            users = [TracText.to_unicode ( users )]   

        if isinstance( testcases, unicode) :
            testcases = [testcases]
        
        if isinstance( testcases, str ):
            testcases = [testcases]
        
        if isinstance( testTemplates, unicode) :
            testTemplates = [testTemplates]
            
        if isinstance( testTemplates, str ):
            testTemplates = [TracText.to_unicode ( testTemplates) ]
        
        
        version = TracText.to_unicode ( version).strip()  
        milestone = TracText.to_unicode ( milestone ).strip()

        if testcases == None :
            testcases = [] #so we don't get a blow up later...
            if testTemplates == None :
                return False, "must select at least one testcase or test template to create a test run"
    
        elif testTemplates == None :
            testTemplates = []
    
        #--------------------------------------------DONE ERROR CHECKING -----------------------------------------------
       
    
        #create combined testcase list        
        testcases = self.createCombinedTestCaseList( testTemplates, testcases, req ) 
            
        allTestcases, errors = self.properties.getTestCases( self, req ) #fetch the testcases...
        if errors :
            return False, errors
        
        if allTestcases == None : 
            return False, None
        
        #one last validation step
        errorMessages = []
        for aUser in users : 
            for testId in testcases : 
                testId = TracText.to_unicode( testId ).strip()
                if testId in allTestcases :
                    continue
                else:
                    self.env.log.info( "Testcase : " + testId + "  not found in master list " )
                    errorMessages.append( "The test: " + testId + ", doesn't match it's file name or you've specified it wrong in the testtemplates.xml file" )
        
        if errorMessages:
            return False, errorMessages
        
        #ok this is where we actually create the tickets...
        db = self.env.get_db_cnx()
        for aUser in users : 
            for testId in testcases : 
                testId = testId.encode('ascii', 'ignore').strip()
                if testId in allTestcases :
                
                    test = allTestcases[ testId ]
                    ticket = Ticket(self.env, db=db)
                    ticket.populate(req.args)            
                    ticket.values['reporter'] = req.authname #the reporter is whoever is logged in
                    ticket.values['summary'] = "TestID: " + test.getId() + " -- " + testConfiguration
                    ticket.values['description'] = "''''''Test Details:''''''\n\n" + test.getDescription() + "\n\n''''''Expected result:'''''' \n\n" + test.getExpectedResult()
                    ticket.values['type'] = 'testcase'
                    ticket.values['status'] = 'new'
                    ticket.values['action'] = 'create'
                    ticket.values['component'] = test.getComponent()
                    ticket.values['owner'] = aUser
                    ticket.values['version'] = version
                    ticket.values['milestone'] = milestone
                    ticket.values['keywords'] = testRunKeyWord  
                    #self._validate_ticket(req, ticket)   #probably should validate the ticket here.
                    ticket.insert(db=db)
                    db.commit()
                else:
                    return False, "The test " + testId + " specified in a test template or as the testcaseID in the test file does not exist in the master test list "
        
        #ok blow away the session vars incase someone trys to refresh the created test run page...no need to recreate all the tickets again...
        #thanks to the haxs in the reporty.py module...
        for var in ('users', 'testcases', 'testtemplates','milestone','version'):
                if req.session.has_key(var):
                    del req.session[var]
        
        #redirect to a custom query report showing the created tickets
        return True, req.base_url + "/query?status=new&status=assigned&status=reopened&status=accepted&testcase_result=&version=" + version + "&milestone=" + milestone + "&type=testcase&order=priority&group=owner"
Esempio n. 35
0
  info["status"] = options.status

# Component
if options.component is not None:
  info["component"] = unicode(options.component, 'utf-8')
# Milestone
if options.milestone is not None:
  info["milestone"] = unicode(options.milestone, 'utf-8')
# Owner
if options.owner is not None:
  info["owner"] = options.owner
# Type
if options.type is not None:
  info["type"] = unicode(options.type, 'utf-8')

# Check empty comment
if not options.comment:
  print >>sys.stderr, "Not accept empty comment"
  sys.exit(3)

# Change ticket information
t.populate(info)

num = t.save_changes(options.author, unicode(options.comment, 'utf-8'))
if not num:
  print >>sys.stderr, "Failed to update a exist ticket"
  sys.exit(1)

print "Ticket %s updated, comment:%d" % (options.id, num)
sys.exit(0)                 # all is well
Esempio n. 36
0
    def process_request(self, req):
        req.perm.assert_permission('TICKET_CREATE')

        db = self.env.get_db_cnx()

        if req.method == 'POST' and 'owner' in req.args and \
               not req.perm.has_permission('TICKET_MODIFY'):
            del req.args['owner']

        if req.method == 'POST' and not req.args.has_key('preview'):
            self._do_create(req, db)

        ticket = Ticket(self.env, db=db)
        ticket.populate(req.args)
        ticket.values['reporter'] = get_reporter_id(req, 'reporter')

        if ticket.values.has_key('description'):
            description = wiki_to_html(ticket['description'], self.env, req, db)
            req.hdf['newticket.description_preview'] = description

        req.hdf['title'] = 'New Ticket'
        req.hdf['newticket'] = ticket.values

        field_names = [field['name'] for field in ticket.fields
                       if not field.get('custom')]
        if 'owner' in field_names:
            curr_idx = field_names.index('owner')
            if 'cc' in field_names:
                insert_idx = field_names.index('cc')
            else:
                insert_idx = len(field_names)
            if curr_idx < insert_idx:
                ticket.fields.insert(insert_idx, ticket.fields[curr_idx])
                del ticket.fields[curr_idx]
        #处理newticket页面的表单
        for field in ticket.fields:
            name = field['name']
            del field['name']
            if name in ('summary', 'reporter', 'description', 'type', 'status',
                        'resolution'):
                field['skip'] = True
            elif name == 'owner':
                field['label'] = 'Assign to'
                if not req.perm.has_permission('TICKET_MODIFY'):
                    field['skip'] = True
            elif name == 'milestone':
                # Don't make completed milestones available for selection
                options = field['options'][:]
                for option in field['options']:
                    milestone = Milestone(self.env, option, db=db)
                    if milestone.is_completed:
                        options.remove(option)
                field['options'] = options
                #原来的field:newticket.fields
                #现在的field:newticket.fields.name.field
                # 下面是汉化:(不在上面完成,而是在这里统一加入代码
                #field['label']与field['name']都是可以的:
                #<?cs alt:field.label ?><?cs var:field.name ?>
            if name == 'priority':
                field['label'] = u'優先'
            elif name == 'owner':
                field['label'] = u'指派給'            
            elif name == 'keywords':
                field['label'] = u'關鍵字'
            elif name == 'version':
                field['label'] = u'版本'
            elif name == 'milestone':
                field['label'] = u'里程碑'
            elif name == 'component':
                field['label'] = u'组件'    
            elif name == 'cc':
                field['label'] = u'附件給'                
            req.hdf['newticket.fields.' + name] = field

        if req.perm.has_permission('TICKET_APPEND'):
            req.hdf['newticket.can_attach'] = True
            req.hdf['newticket.attachment'] = req.args.get('attachment')

        add_stylesheet(req, 'common/css/ticket.css')
        return 'newticket.cs', None
Esempio n. 37
0
    def generateTracTickets( self, req ) :
        """
            ok, it's a post so we know we are supposed to go ahead and create some TRAC tickets...the parameters that we care about are:
            #users ...this will be a list...
            #testtemplates ... this will be a list...
            #testcases  ... this will be a list...
            #version...this will be a string...
            #milestone...this will be a string...
            
            This method does one of two things.  It will either return: "True, URL" if ticket creation based on user input was succesful or "False, ErrorMessage" if
            the ticket creation failed.           
            
        """
        
        #grab the parameters that we care about out of the request object
        testRunDescription = str( req.args.get('testrundescription') )
        users = req.args.get('users')
        testTemplates = req.args.get('testtemplates')
        testcases = req.args.get('testcases')
        version = str( req.args.get('selectedversion'))
        milestone = str( req.args.get('selectedmilestone'))
        
        #-----------------------------------ERROR CHECKING ON PARAMETERS--------------------------------------------
        if version == None:
            version = ""
        if milestone == None:
            milestone = ""
        if users == None :
            return False, "No users selected for test run"
        if isinstance( users, unicode): 
            users = [users.encode('ascii', 'ignore')]
        
        
        version = version.encode('ascii', 'ignore').strip()
        milestone = milestone.encode('ascii', 'ignore').strip()

        if testcases == None :
            testcases = [] #so we don't get a blow up later...
            if testTemplates == None :
                return False, "must select at least one testcase or test template to create a test run"
                return 'errorCreatingTestRun.cs', None
        elif testTemplates == None :
            testTemplates = []
    
        #create combined testcase list        
        testcases = self.createCombinedTestCaseList( testTemplates, testcases, req ) 
            
        allTestcases = self.properties.getTestCases( self, req ) #fetch the testcases...
        if allTestcases == None : 
            return False, None
        #--------------------------------------------DONE ERROR CHECKING -----------------------------------------------
        
        #ok this is where we actually create the tickets...
        db = self.env.get_db_cnx()
        for aUser in users : 
            for testId in testcases : 
                testId = testId.encode('ascii', 'ignore').strip()
                if testId in allTestcases :
                    test = allTestcases[ testId ]
                    ticket = Ticket(self.env, db=db)
                    ticket.populate(req.args)            
                    ticket.values['reporter'] = req.authname #the reporter is whoever is logged in
                    ticket.values['summary'] = "TestID: " + test.getId() + " -- " + test.getSummary()
                    ticket.values['description'] = "''''''Test Details:''''''\n\n" + test.getDescription() + "\n\n''''''Expected result:'''''' \n\n" + test.getExpectedResult()
                    ticket.values['type'] = 'testcase'
                    ticket.values['status'] = 'new'
                    ticket.values['action'] = 'create'
                    ticket.values['component'] = test.getComponent()
                    ticket.values['owner'] = aUser
                    ticket.values['version'] = version
                    ticket.values['milestone'] = milestone
                    ticket.values['keywords'] = "Test_ver" + version + "_mile_" + milestone
                    #self._validate_ticket(req, ticket)   #probably should validate the ticket here.
                    ticket.insert(db=db)
                    db.commit()
                else:
                    return False, "The test " + testId + " specified in a test template or as the testcaseID in the test file does not exist in the master test list "
        
        #ok blow away the session vars incase someone trys to refresh the created test run page...no need to recreate all the tickets again...
        #thanks to the haxs in the reporty.py module...
        for var in ('users', 'testcases', 'testtemplates','milestone','version'):
                if req.session.has_key(var):
                    del req.session[var]
        
        #redirect to a custom query report showing the created tickets
        return True, req.base_url + "/query?status=new&status=assigned&status=reopened&testcase_result=&version=" + version + "&milestone=" + milestone + "&type=testcase&order=priority&group=owner"
Esempio n. 38
0
    def generateTracTickets(self, req):
        """
            ok, it's a post so we know we are supposed to go ahead and create some TRAC tickets...the parameters that we care about are:
            #users ...this will be a list...
            #testtemplates ... this will be a list...
            #testcases  ... this will be a list...
            #version...this will be a string...
            #milestone...this will be a string...
            
            This method does one of two things.  It will either return: "True, URL" if ticket creation based on user input was succesful or "False, ErrorMessage" if
            the ticket creation failed.           
            
        """

        #grab the parameters that we care about out of the request object
        testRunDescription = str(req.args.get('testrundescription'))
        users = req.args.get('users')
        testTemplates = req.args.get('testtemplates')
        testcases = req.args.get('testcases')
        version = str(req.args.get('selectedversion'))
        milestone = str(req.args.get('selectedmilestone'))

        #-----------------------------------ERROR CHECKING ON PARAMETERS--------------------------------------------
        if version == None:
            version = ""
        if milestone == None:
            milestone = ""
        if users == None:
            return False, "No users selected for test run"
        if isinstance(users, unicode):
            users = [users.encode('ascii', 'ignore')]

        version = version.encode('ascii', 'ignore').strip()
        milestone = milestone.encode('ascii', 'ignore').strip()

        if testcases == None:
            testcases = []  #so we don't get a blow up later...
            if testTemplates == None:
                return False, "must select at least one testcase or test template to create a test run"
                return 'errorCreatingTestRun.cs', None
        elif testTemplates == None:
            testTemplates = []

        #create combined testcase list
        testcases = self.createCombinedTestCaseList(testTemplates, testcases,
                                                    req)

        allTestcases = self.properties.getTestCases(
            self, req)  #fetch the testcases...
        if allTestcases == None:
            return False, None
        #--------------------------------------------DONE ERROR CHECKING -----------------------------------------------

        #ok this is where we actually create the tickets...
        db = self.env.get_db_cnx()
        for aUser in users:
            for testId in testcases:
                testId = testId.encode('ascii', 'ignore').strip()
                if testId in allTestcases:
                    test = allTestcases[testId]
                    ticket = Ticket(self.env, db=db)
                    ticket.populate(req.args)
                    ticket.values[
                        'reporter'] = req.authname  #the reporter is whoever is logged in
                    ticket.values['summary'] = "TestID: " + test.getId(
                    ) + " -- " + test.getSummary()
                    ticket.values[
                        'description'] = "''''''Test Details:''''''\n\n" + test.getDescription(
                        ) + "\n\n''''''Expected result:'''''' \n\n" + test.getExpectedResult(
                        )
                    ticket.values['type'] = 'testcase'
                    ticket.values['status'] = 'new'
                    ticket.values['action'] = 'create'
                    ticket.values['component'] = test.getComponent()
                    ticket.values['owner'] = aUser
                    ticket.values['version'] = version
                    ticket.values['milestone'] = milestone
                    ticket.values[
                        'keywords'] = "Test_ver" + version + "_mile_" + milestone
                    #self._validate_ticket(req, ticket)   #probably should validate the ticket here.
                    ticket.insert(db=db)
                    db.commit()
                else:
                    return False, "The test " + testId + " specified in a test template or as the testcaseID in the test file does not exist in the master test list "

        #ok blow away the session vars incase someone trys to refresh the created test run page...no need to recreate all the tickets again...
        #thanks to the haxs in the reporty.py module...
        for var in ('users', 'testcases', 'testtemplates', 'milestone',
                    'version'):
            if req.session.has_key(var):
                del req.session[var]

        #redirect to a custom query report showing the created tickets
        return True, req.base_url + "/query?status=new&status=assigned&status=reopened&testcase_result=&version=" + version + "&milestone=" + milestone + "&type=testcase&order=priority&group=owner"
Esempio n. 39
0
    def process_request(self, req):
        req.perm.assert_permission('TICKET_CREATE')

        db = self.env.get_db_cnx()

        if req.method == 'POST' and 'owner' in req.args and \
               not req.perm.has_permission('TICKET_MODIFY'):
            del req.args['owner']

        if req.method == 'POST' and not req.args.has_key('preview'):
            self._do_create(req, db)

        ticket = Ticket(self.env, db=db)
        ticket.populate(req.args)
        ticket.values['reporter'] = get_reporter_id(req, 'reporter')

        if ticket.values.has_key('description'):
            description = wiki_to_html(ticket['description'], self.env, req,
                                       db)
            req.hdf['newticket.description_preview'] = description

        req.hdf['title'] = u'Nouveau ticket'
        req.hdf['newticket'] = ticket.values

        field_names = [
            field['name'] for field in ticket.fields if not field.get('custom')
        ]
        if 'owner' in field_names:
            curr_idx = field_names.index('owner')
            if 'cc' in field_names:
                insert_idx = field_names.index('cc')
            else:
                insert_idx = len(field_names)
            if curr_idx < insert_idx:
                ticket.fields.insert(insert_idx, ticket.fields[curr_idx])
                del ticket.fields[curr_idx]

        for field in ticket.fields:
            name = field['name']
            del field['name']
            if name in ('summary', 'reporter', 'description', 'type', 'status',
                        'resolution'):
                field['skip'] = True
            elif name == 'owner':
                field['label'] = u'Assigner à'
                if not req.perm.has_permission('TICKET_MODIFY'):
                    field['skip'] = True
            elif name == 'milestone':
                # Don't make completed milestones available for selection
                options = field['options'][:]
                for option in field['options']:
                    milestone = Milestone(self.env, option, db=db)
                    if milestone.is_completed:
                        options.remove(option)
                field['options'] = options
            field['label'] = translate(self.env, field['label'])
            req.hdf['newticket.fields.' + name] = field

        if req.perm.has_permission('TICKET_APPEND'):
            req.hdf['newticket.can_attach'] = True
            req.hdf['newticket.attachment'] = req.args.get('attachment')

        add_stylesheet(req, 'common/css/ticket.css')
        return 'newticket.cs', None