Edgewall Software

Ticket #222: trac.ticket.222.diff

File trac.ticket.222.diff, 5.9 kB (added by ivanoe@…, 4 years ago)

patch: solution to the ticket using both apache password or trac 'permission' table's 'username'

  • templates/header.cs

     
    3939<form id="search" action="<?cs var:trac.href.search ?>" method="get"> 
    4040 <?cs if:trac.acl.SEARCH_VIEW ?><div> 
    4141  <label for="proj-search">Search:</label> 
    42   <input type="text" id="proj-search" name="q" size="10" value="" /> 
     42  <input type="text" id="proj-search" name="q" size="25" value="" /> 
    4343  <input type="submit" value="Search" /> 
    4444  <input type="hidden" name="wiki" value="on" /> 
    4545  <input type="hidden" name="changeset" value="on" /> 
  • templates/newticket.cs

     
    5959   <label for="milestone">Milestone:</label><?cs 
    6060   call:hdf_select(newticket.milestones, "milestone", newticket.milestone) ?><br /> 
    6161   <label for="owner">Assign to:</label> 
    62    <input type="text" id="owner" name="owner" size="20" value="<?cs 
    63      var:newticket.owner ?>" /><br /> 
     62   <?cs call:hdf_select(newticket.owners, "owner", newticket.owner) ?><br /> 
    6463   <label for="cc">Cc:</label> 
    6564   <input type="text" id="cc" name="cc" size="30" value="<?cs var:newticket.cc ?>" /> 
    6665  </div> 
  • templates/ticket.cs

     
    235235   <?cs call:action_radio('reassign') ?> 
    236236   <label for="reassign">reassign</label> 
    237237   <label for="reassign_owner">to:</label> 
    238    <input type="text" id="reassign_owner" name="reassign_owner" size="40" value="<?cs 
    239      if:args.reassign_to ?><?cs var:args.reassign_to ?><?cs 
    240      else ?><?cs var:trac.authname ?><?cs /if ?>" /><?cs 
     238   <?cs call:hdf_select(ticket.owners, "reassign_owner", args.reassign_to) ?><?cs 
    241239  /if ?><?cs 
    242240  if $ticket.status == "new" || $ticket.status == "assigned" || $ticket.status == "reopened" ?> 
    243241   <script type="text/javascript"> 
  • trac/Ticket.py

     
    1919# 
    2020# Author: Jonas Borgstr�jonas@edgewall.com> 
    2121 
     22import os 
    2223import re 
    2324import time 
    2425import string 
     
    263264            hdf.setValue('%s.height' % pfx, f['height']) 
    264265        i += 1 
    265266 
     267class TicketModuleBase(Module): 
     268    """ 
     269    Contains common members for Ticket and NewTicket 
     270    """ 
     271    def _add_users_to_hdf(self, key): 
     272        """ 
     273        Adds list of configured users to hdf. The list of users is taken from apache password file, 
     274        if one is configured using environment value 'TRAC_PWDFILE' in httpd.conf. 
     275        Otherwise the list of users is retrieved from the 'permission' table. 
     276        Anonymous user is excluded. Empty user is added. 
     277        """ 
     278        passwordfile = os.getenv( 'TRAC_PWDFILE' ) 
     279        if passwordfile: 
     280            pwdfile = None 
     281            # Get list of users from the configured apache password file 
     282            try: 
     283                pwdfile = open( passwordfile, 'r' ) 
     284                for line in pwdfile: 
     285                    pos = string.find(line, ':') 
     286                    if ( pos == -1 ): 
     287                        self.log.warn( 'corrupted passwordfile or unknown file format' ) 
     288                    else: 
     289                        util.hdf_add_if_missing(self.req.hdf, key, line[:pos]) 
     290            finally: 
     291                if pwdfile: 
     292                    pwdfile.close() 
     293        else: 
     294            # Get list of users from trac 'permission' table 
     295            util.sql_to_hdf(self.db, 'SELECT distinct username FROM permission WHERE username NOT IN ' 
     296                        '(SELECT DISTINCT action FROM permission) AND username <> \'anonymous\' ORDER BY username', 
     297                        self.req.hdf, key) 
    266298 
    267 class NewticketModule(Module): 
     299        util.hdf_add_if_missing(self.req.hdf, key, '') 
     300        util.hdf_sort(self.req.hdf, key) 
     301 
     302 
     303class NewticketModule(TicketModuleBase): 
    268304    template_name = 'newticket.cs' 
    269305 
    270306    def create_ticket(self): 
     
    327363                        self.req.hdf, 'newticket.milestones') 
    328364        util.sql_to_hdf(self.db, 'SELECT name FROM version ORDER BY name', 
    329365                        self.req.hdf, 'newticket.versions') 
    330  
    331366        insert_custom_fields(self.env, self.req.hdf, ticket) 
     367        self._add_users_to_hdf( 'newticket.owners' ) 
    332368 
    333369 
    334 class TicketModule (Module): 
     370class TicketModule (TicketModuleBase): 
    335371    template_name = 'ticket.cs' 
    336372 
    337373    def save_changes (self, id): 
     
    390426        util.sql_to_hdf(self.db, "SELECT name FROM enum WHERE type='resolution'" 
    391427                                 " ORDER BY value", 
    392428                        self.req.hdf, 'enums.resolution') 
     429        self._add_users_to_hdf( 'ticket.owners' ) 
    393430        util.hdf_add_if_missing(self.req.hdf, 'ticket.components', ticket['component']) 
    394431        util.hdf_add_if_missing(self.req.hdf, 'ticket.milestones', ticket['milestone']) 
    395432        util.hdf_add_if_missing(self.req.hdf, 'ticket.versions', ticket['version']) 
  • trac/util.py

     
    173173        hdf.setValue('%s.%d.name' % (prefix, idx), row[0]) 
    174174        idx = idx + 1 
    175175 
     176def hdf_sort (hdf, prefix): 
     177    """ 
     178    sorts all the values found in hdf for given prefix 
     179    """ 
     180    node = hdf.getObj(prefix + '.0') 
     181    values = [] 
     182    while node: 
     183        child = node.child() 
     184        if child: 
     185          values.append( child.value() ) 
     186        node = node.next() 
     187 
     188    values.sort() 
     189    for i in range(len(values)): 
     190        add_to_hdf(values[i], hdf, '%s.%d.name' % (prefix, i)) 
     191 
    176192def hdf_add_if_missing(hdf, prefix, value): 
    177193    """Loop through the hdf values and add @value if id doesn't exist""" 
    178194    node = hdf.getObj(prefix + '.0')