def _create_requirement_tree(env):
    t_manager = AgiloTicketModelManager(env)
    for req_nr in range(number_of_requirements):
        stories = []
        for story_nr in range(number_of_stories_per_requirement):
            tasks = []
            for task_nr in range(number_of_tasks_per_story):
                task = dict()
                task['t_type'] = Type.TASK
                task[Key.SUMMARY] = 'Task %d.%d.%d' % (req_nr, story_nr, task_nr)
                task[Key.SPRINT] = sprint_name
                t = t_manager.create(**task)
                tasks.append(t)
            story = dict()
            story['t_type'] = Type.USER_STORY
            story[Key.SUMMARY] = 'Story %d.%d' % (req_nr, story_nr)
            story[Key.SPRINT] = sprint_name
            s = t_manager.create(**story)
            for t in tasks:
                s.link_to(t)
            stories.append(s)
        requirement = dict()
        requirement['t_type'] = Type.REQUIREMENT
        requirement[Key.SUMMARY] = 'Requirement %d' % (req_nr)
        r = t_manager.create(**requirement)
        for s in stories:
            r.link_to(s)
    return number_of_requirements * number_of_stories_per_requirement * number_of_tasks_per_story
Esempio n. 2
0
    def __init__(self, env, a_commit_message):
        self.env = env
        self.message = a_commit_message
        # REFACT: rename tm to ticket_model_manager to make the type clearer
        self.tm = AgiloTicketModelManager(self.env)

        self.validation_errors = list()
        self.commands = list()
def _create_orphan_tasks(env):
    t_manager = AgiloTicketModelManager(env)
    for task_nr in range(number_of_tasks_per_bug):
        task = dict()
        task['t_type'] = Type.TASK
        task[Key.SUMMARY] = 'Orphan Task %d' % (task_nr)
        task[Key.SPRINT] = sprint_name
        t_manager.create(**task)
    return number_of_tasks_per_bug
Esempio n. 4
0
 def ticket_as_json(self, req, ticket_or_ticket_id):
     if isinstance(ticket_or_ticket_id, AgiloTicket):
         ticket = ticket_or_ticket_id
     else:
         # Use the model manager that uses the request cache
         ticket = AgiloTicketModelManager(
             self.env).get(tkt_id=ticket_or_ticket_id)
     ticket_json = ticket.as_dict()
     ticket_json['can_edit'] = self.can_edit_ticket(req, ticket)
     return ticket_json
Esempio n. 5
0
 def __init__(self, project, rev, repo, env=None):
     """Initialize the class with the project path and the revision"""
     try:
         self.env = env or Environment(project)
         self.tm = AgiloTicketModelManager(self.env)
         self.repo = repo
         repos = self.env.get_repository(self.repo)
         repos.sync()
     except Exception, e:
         print >> sys.stderr, "An Error occurred while opening Trac project: %s => %s" % (project, to_unicode(e))
         sys.exit(1)
def create_emtpy_sprint(env):
    assert sprint_name != None, 'Please configure a sprint name.'
    sprint = SprintModelManager(env).create(name=sprint_name,
                                                  start=now(),
                                                  duration=14)
    assert sprint is not None
    t_manager = AgiloTicketModelManager(env)
    for t_id, t_type, t_status in sprint._fetch_tickets():
        ticket = t_manager.create(tkt_id=t_id, t_type=t_type)
        if ticket[Key.SPRINT] == sprint.name:
            ticket[Key.SPRINT] = None
            t_manager.save(ticket, None, 'reset sprint field for performance measurement')
Esempio n. 7
0
 def validate(self, value):
     from agilo.ticket.model import AgiloTicket, \
         AgiloTicketModelManager
     from agilo.scrum.backlog import Backlog
     if isinstance(value, (AgiloTicket, Backlog.BacklogItem)):
         return value
     value = self.super()
     try:
         value = AgiloTicketModelManager(self.env).get(tkt_id=value)
     except Exception:
         self.message = "must be a valid AgiloTicket id"
         self.error(value)
     return value
Esempio n. 8
0
    def get_tickets_matching(self, t_id, summary):
        """
        Returns a list of dictionaries (id: value, summary: value) matching the summary 
        request and excluding the requesting ticket having id = id.
        """
        try:
            t_id = int(t_id)  # Make sure it is an int :-)
            keyword = re.compile(summary, re.IGNORECASE)
            db = self.env.get_db_cnx()

            from agilo.ticket.model import AgiloTicketModelManager
            sql = """SELECT id, type, summary FROM ticket WHERE id != $id $allowed 
                  AND id NOT IN (SELECT dest FROM %s WHERE src = $id UNION
                  SELECT src FROM %s WHERE dest = $id) ORDER BY summary""" \
                    % (LINKS_TABLE, LINKS_TABLE)
            sql_query = string.Template(sql)
            sql_allowed = "AND ticket.type IN ('%s')"
            t_type = AgiloTicketModelManager(
                self.env).get(tkt_id=t_id).get_type()
            linkconfig = LinksConfiguration(self.env)
            if linkconfig.is_allowed_source_type(t_type):
                allowed_types = linkconfig.get_allowed_destination_types(
                    t_type)
                allowed = sql_allowed % '\', \''.join(allowed_types)
            else:
                debug(self, "No Key found for #%s#" % repr(t_type))
                allowed = ''

            sql_query = sql_query.substitute({'id': t_id, 'allowed': allowed})
            debug(self, "SQL: %s" % sql_query)
            cursor = db.cursor()
            cursor.execute(sql_query)

            results = []
            for row in cursor:
                if keyword.search(row[2] or ''):
                    results.append({
                        'id': row[0],
                        'type': row[1],
                        'summary': row[2]
                    })

            debug(self, "Search Results: %s" % str(results))
            return results

        except Exception, e:
            warning(self, e)
            msg = "[%s]: ERROR: Search module unable to complete query!" % \
                    self.__class__.__name__
            raise TracError(msg)
Esempio n. 9
0
 def _add_links_for_ticket(self, req, ticket):
     try:
         src_ticket_id = int(req.args['src'])
     except:
         pass
     else:
         src_ticket = AgiloTicketModelManager(
             self.env).get(tkt_id=src_ticket_id)
         if ticket != None and src_ticket != None:
             if src_ticket.is_link_to_allowed(ticket):
                 return src_ticket.link_to(ticket)
             else:
                 msg = 'You may not link #%d (Type %s) to #%d (Type %s)'
                 error(
                     self,
                     msg % (src_ticket.id, src_ticket.get_type(), ticket.id,
                            ticket.get_type()))
Esempio n. 10
0
def _create_bug_trees(env):
    t_manager = AgiloTicketModelManager(env)
    for bug_nr in range(number_of_bugs):
        tasks = []
        for task_nr in range(number_of_tasks_per_bug):
            task = dict()
            task['t_type'] = Type.TASK
            task[Key.SUMMARY] = 'Bug Task %d.%d' % (bug_nr, task_nr)
            task[Key.SPRINT] = sprint_name
            t = t_manager.create(**task)
            tasks.append(t)
        bug = dict()
        bug['t_type'] = Type.BUG
        bug[Key.SUMMARY] = 'Bug %d' % (bug_nr)
        bug[Key.SPRINT] = sprint_name
        b = t_manager.create(**bug)
        for t in tasks:
            b.link_to(t)
    return number_of_bugs * number_of_tasks_per_bug
Esempio n. 11
0
 def __init__(self):
     self.action_map = {
         Action.ATTACHMENT_CREATE: self.check_attachment_create,
         Action.CONFIRM_COMMITMENT: self.confirm_commitment,
         Action.TICKET_EDIT: self.check_ticket_edit,
         # We need also to catch trac's Actions for modifying tickets 
         # - otherwise too many things will be allowed!
         Action.TICKET_CHANGE: self.check_ticket_edit,
         Action.TICKET_MODIFY: self.check_ticket_edit,
         Action.TICKET_EDIT_PAGE_ACCESS: self.check_ticket_edit_page_access,
         Action.TICKET_EDIT_DESCRIPTION: self.check_edit_description,
         
         # We don't have add a check for TICKET_APPEND because all three 
         # roles get the TICKET_APPEND permission via meta permissions. 
         # Therefore checking for team members is useless.
         # Action.TICKET_APPEND: self.check_ticket_append,
         Action.LINK_EDIT: self.check_link_edit,
         Action.SAVE_REMAINING_TIME: self.check_save_remaining_time,
         Action.BACKLOG_EDIT: self.check_backlog_edit,
     }
     self.tm = AgiloTicketModelManager(self.env)
Esempio n. 12
0
 def testTicketWithModelManager(self):
     """Tests the ticket creation via ModelManager"""
     from agilo.ticket.model import AgiloTicketModelManager
     manager = AgiloTicketModelManager(self.env)
     t1 = manager.create(summary='This is a test ticket',
                         t_type=Type.TASK,
                         remaining_time='12',
                         description='take this')
     self.assert_true(t1.exists)
     self.assertNotEqual(0, t1.id)
     self.assert_equals('This is a test ticket', t1[Key.SUMMARY])
     self.assert_equals('12', t1[Key.REMAINING_TIME])
     self.assert_equals('take this', t1[Key.DESCRIPTION])
     t2 = manager.get(tkt_id=t1.id)
     self.assert_true(t2.exists)
     self.assert_equals(t1.id, t2.id)
     # test cache too
     self.assert_equals(id(t1), id(t2))
     # Now change the summary
     t2.summary = 'A new summary'
     manager.save(t2, author='tester', comment='Updated summary...')
     # is the same object so...
     self.assert_equals(t2.summary, t1.summary)
Esempio n. 13
0
        def _execute(self, team_controller, date_converter=None,
                     as_key=None):
            """Runs the command, returns the result or raise a CommandError"""
            from agilo.ticket.model import AgiloTicketModelManager 
            ticket_manager = AgiloTicketModelManager(team_controller.env)
            # ask to agilo config which types have the story points
            # attribute
            from agilo.utils.config import AgiloConfig
            ac = AgiloConfig(team_controller.env)
            types = []
            for t_type, fields in ac.TYPES.items():
                if Key.STORY_POINTS in fields:
                    types.append(t_type)
            # choose the right operator
            types_condition = "in ('%s')" % "', '".join(types)
            if len(types) == 1:
                types_condition = types[0] # just equals that type

            stories = ticket_manager.select(criteria={'type': types_condition,
                                                      'sprint': self.sprint.name})
            if not self.estimated:
                stories = [s for s in stories if s[Key.STATUS] == Status.CLOSED]
            # Sum up the story points of all the stories
            return sum([float(s[Key.STORY_POINTS] or 0) for s in stories])
Esempio n. 14
0
    def process_request(self, req):
        # Check if it has been called with 'src' and 'dest' arguments or abort
        if not req.args.has_key('src') or not req.args.has_key(
                'dest') or not req.args.has_key('cmd'):
            raise TracError(
                "Links should be called with 'cmd', 'src' and 'dest' parameters",
                "Links: Source and/or Destination are Missing!")
        else:
            # Flag for ticket update
            update_ticket = False
            # Avoid recursive imports
            from agilo.ticket.model import AgiloTicketModelManager
            tm = AgiloTicketModelManager(self.env)
            try:
                src = int(req.args.get('src'))
                # Now that we have the ticket we can check permission to link or edit
                ticket_perm = req.perm('ticket', src)
                if Action.TICKET_EDIT not in ticket_perm or \
                        Action.LINK_EDIT not in ticket_perm:
                    raise TracError("You (%s) are not authorized to edit this ticket" % \
                                    req.authname)
                dest = int(req.args.get('dest'))
                cmd = req.args.get('cmd')
                url = req.args.get('url_orig') or None
            except:
                raise TracError("Source is not valid: src=%s" %
                                req.args.get('src'))
            # Create the LinkEndPoint for the source and destination if not existing
            sle = tm.get(tkt_id=src)
            dle = tm.get(tkt_id=dest)
            src_type = sle.get_type()
            dest_type = dle.get_type()

            if cmd == 'create link':
                if not sle.link_to(dle):
                    raise TracError("Links not allowed between %s->%s! The types are incompatible or" \
                                    " the link already exists" % (src_type, dest_type))
                else:
                    req.args[Key.OUTGOING_LINKS] = 'created link %s(#%s)->%s(#%s)' % \
                                                    (src_type, src, dest_type, dest)
                    req.args['comment'] = 'Added link to %s(#%s)' % \
                                           (dest_type, dest)
                    update_ticket = True
            elif cmd == 'delete link':
                if not sle.del_link_to(dle):
                    raise TracError("Link not existing! %s(#%s)->%s(#%s)" % \
                                    (src_type, src, dest_type, dest))
                else:
                    req.args[Key.OUTGOING_LINKS] = 'deleted link %s(#%s)->%s(#%s)' % \
                                                    (src_type, src, dest_type, dest)
                    req.args['comment'] = 'Deleted link to %s(#%s)' % (
                        dest_type, dest)
                    update_ticket = True
            else:
                raise TracError("ERROR: Unknown Command %s!" % cmd)

            #set the link into the request and let TicketWrapper update the custom field
            if update_ticket:
                req.args['id'] = src
                req.args['summary'] = sle[Key.SUMMARY]
                req.args['ts'] = sle.time_changed
                req.args['action'] = 'leave'

            # Redirect to original /ticket url to avoid any change in existing view
            req.redirect(url or req.base_url)
Esempio n. 15
0
 def __init__(self, env, number_rows_for_preview=20):
     self.do_preview = False
     self.rows = []
     self.number_rows_for_preview = number_rows_for_preview
     self.env = env
     self.tm = AgiloTicketModelManager(self.env)
Esempio n. 16
0
 def setUp(self):
     self.super()
     self.manager = AgiloTicketModelManager(self.env)
Esempio n. 17
0
 def __init__(self):
     """Initialize taking a reference to the ticket model manager"""
     self.manager = AgiloTicketModelManager(self.env)