Edgewall Software

Ticket #1890: authentic.patch

File authentic.patch, 11.1 kB (added by maxb1@…, 2 years ago)

Patch vs. 0.9.5 (implementing the crufty solution) that I am currently using as a workaround on my production installation. [OBSOLETES: authen.diff]

  • templates/attachment.cs

    * trac/attachment.py
      (AttachmentModule._do_save):
        Use util.get_authentic_id() instead of just req.args.get().
      (AttachmentModule._render_form):
        Add fieldname argument to util.get_reporter_id() call.
    
    * trac/ticket/web_ui.py:
      (NewticketModule.process_request): No effective behaviour change, but use
        code more consistent in style with similar operations elsewhere.
      (NewticketModule._do_create): Use util.get_authentic_id(). Logic is
        unchanged except for the addition of authentic-making the username,
        but the code is simplified.
      (TicketModule.process_request): Simplify code, with inconsequential
        logic changes.
      (TicketModule._do_save):
        Use util.get_authentic_id() instead of just req.args.get().
    
    * trac/util.py (get_reporter_id):
        Always return req.authname if the request is authenticated.
        Add capability to fetch a value from a form field if one was specified.
      (get_authentic_id): New function - return req.authname if the request is
        authenticated, otherwise call get_reporter_id and mangle the return
        value to indicate its unauthenticated nature.
    
    * trac/wiki/web_ui.py: Import util.get_authentic_id.
      (WikiModule._do_save):
        Use util.get_authentic_id() instead of just req.args.get().
      (WikiModule._render_editor): Logic unchanged. Code simplified by making
        use of the new behaviour of get_reporter_id.
    
    * templates/attachment.cs, templates/newticket.cs, templates/ticket.cs,
      templates/wiki.cs: Only show "Your email or username:" field if not
        authenticated.
    diff -ru trac-0.9.5.orig/templates/attachment.cs trac-0.9.5/templates/attachment.cs
    old new  
    1414  </div> 
    1515  <fieldset> 
    1616   <legend>Attachment Info</legend> 
    17    <div class="field"> 
    18     <label>Your email or username:<br /> 
    19     <input type="text" name="author" size="30" value="<?cs 
    20       var:attachment.author?>" /></label> 
    21    </div> 
     17   <?cs if:trac.authname == "anonymous" ?> 
     18    <div class="field"> 
     19     <label>Your email or username:<br /> 
     20     <input type="text" name="author" size="30" value="<?cs 
     21       var:attachment.author?>" /></label> 
     22    </div> 
     23   <?cs /if ?> 
    2224   <div class="field"> 
    2325    <label>Description of the file (optional):<br /> 
    2426    <input type="text" name="description" size="60" /></label> 
  • templates/newticket.cs

    diff -ru trac-0.9.5.orig/templates/newticket.cs trac-0.9.5/templates/newticket.cs
    old new  
    1111<?cs include:"site_newticket.cs" ?> 
    1212<form id="newticket" method="post" action="<?cs 
    1313  var:trac.href.newticket ?>#preview"> 
    14  <div class="field"> 
    15   <label for="reporter">Your email or username:</label><br /> 
    16   <input type="text" id="reporter" name="reporter" size="40" value="<?cs 
    17     var:newticket.reporter ?>" /><br /> 
    18  </div> 
     14 <?cs if:trac.authname == "anonymous" ?> 
     15  <div class="field"> 
     16   <label for="reporter">Your email or username:</label><br /> 
     17   <input type="text" id="reporter" name="reporter" size="40" value="<?cs 
     18     var:newticket.reporter ?>" /><br /> 
     19  </div> 
     20 <?cs /if ?> 
    1921 <div class="field"> 
    2022  <label for="summary">Short summary:</label><br /> 
    2123  <input id="summary" type="text" name="summary" size="80" value="<?cs 
  • templates/ticket.cs

    diff -ru trac-0.9.5.orig/templates/ticket.cs trac-0.9.5/templates/ticket.cs
    old new  
    126126 <hr /> 
    127127 <h3><a name="edit" onfocus="document.getElementById('comment').focus()">Add/Change #<?cs 
    128128   var:ticket.id ?> (<?cs var:ticket.summary ?>)</a></h3> 
    129  <div class="field"> 
    130   <label for="author">Your email or username:</label><br /> 
    131   <input type="text" id="author" name="author" size="40" 
    132     value="<?cs var:ticket.reporter_id ?>" /><br /> 
    133  </div> 
     129 <?cs if:trac.authname == "anonymous" ?> 
     130  <div class="field"> 
     131   <label for="author">Your email or username:</label><br /> 
     132   <input type="text" id="author" name="author" size="40" 
     133     value="<?cs var:ticket.reporter_id ?>" /><br /> 
     134  </div> 
     135 <?cs /if ?> 
    134136 <div class="field"> 
    135137  <fieldset class="iefix"> 
    136138   <label for="comment">Comment (you may use <a tabindex="42" href="<?cs 
  • templates/wiki.cs

    diff -ru trac-0.9.5.orig/templates/wiki.cs trac-0.9.5/templates/wiki.cs
    old new  
    235235    </div> 
    236236    <fieldset id="changeinfo"> 
    237237     <legend>Change information</legend> 
    238      <div class="field"> 
    239       <label>Your email or username:<br /> 
    240       <input id="author" type="text" name="author" size="30" value="<?cs 
    241         var:wiki.author ?>" /></label> 
    242      </div> 
     238     <?cs if:trac.authname == "anonymous" ?> 
     239      <div class="field"> 
     240       <label>Your email or username:<br /> 
     241       <input id="author" type="text" name="author" size="30" value="<?cs 
     242         var:wiki.author ?>" /></label> 
     243      </div> 
     244     <?cs /if ?> 
    243245     <div class="field"> 
    244246      <label>Comment about this change (optional):<br /> 
    245247      <input id="comment" type="text" name="comment" size="60" value="<?cs 
  • trac/attachment.py

    diff -ru trac-0.9.5.orig/trac/attachment.py trac-0.9.5/trac/attachment.py
    old new  
    318318                                                    'utf-8')).encode('utf-8') 
    319319 
    320320        attachment.description = req.args.get('description', '') 
    321         attachment.author = req.args.get('author', '') 
     321        attachment.author = util.get_authentic_id(req, 'author') 
    322322        attachment.ipnr = req.remote_addr 
    323323        if req.args.get('replace'): 
    324324            try: 
     
    376376        text, link = self._get_parent_link(attachment) 
    377377        req.hdf['attachment'] = { 
    378378            'mode': 'new', 
    379             'author': util.get_reporter_id(req), 
     379            'author': util.get_reporter_id(req, 'author'), 
    380380            'parent': {'type': attachment.parent_type, 
    381381                       'id': attachment.parent_id, 'name': text, 'href': link} 
    382382        } 
  • trac/ticket/web_ui.py

    diff -ru trac-0.9.5.orig/trac/ticket/web_ui.py trac-0.9.5/trac/ticket/web_ui.py
    old new  
    8484 
    8585        ticket = Ticket(self.env, db=db) 
    8686        ticket.populate(req.args) 
    87         ticket.values.setdefault('reporter', util.get_reporter_id(req)) 
     87        ticket.values['reporter'] = util.get_reporter_id(req, 'reporter') 
    8888 
    8989        if ticket.values.has_key('description'): 
    9090            description = wiki_to_html(ticket['description'], self.env, req, db) 
     
    133133            raise TracError('Tickets must contain a summary.') 
    134134 
    135135        ticket = Ticket(self.env, db=db) 
    136         ticket.values.setdefault('reporter', util.get_reporter_id(req)) 
    137136        ticket.populate(req.args) 
     137        ticket.values['reporter'] = util.get_authentic_id(req, 'reporter') 
    138138        ticket.insert(db=db) 
    139139        db.commit() 
    140140 
     
    182182        id = int(req.args.get('id')) 
    183183 
    184184        ticket = Ticket(self.env, id, db=db) 
    185         reporter_id = util.get_reporter_id(req) 
    186185 
    187186        if req.method == 'POST': 
    188187            if not req.args.has_key('preview'): 
     
    195194                req.hdf['ticket.reassign_owner'] = req.args.get('reassign_owner') \ 
    196195                                                   or req.authname 
    197196                req.hdf['ticket.resolve_resolution'] = req.args.get('resolve_resolution') 
    198                 reporter_id = req.args.get('author') 
    199197                comment = req.args.get('comment') 
    200198                if comment: 
    201199                    req.hdf['ticket.comment'] = comment 
     
    208206            # Store a timestamp in order to detect "mid air collisions" 
    209207            req.hdf['ticket.ts'] = ticket.time_changed 
    210208 
    211         self._insert_ticket_data(req, db, ticket, reporter_id) 
     209        self._insert_ticket_data(req, db, ticket, 
     210                                 util.get_reporter_id(req, 'author')) 
    212211 
    213212        # If the ticket is being shown in the context of a query, add 
    214213        # links to help navigate in the query result set 
     
    343342            ticket['resolution'] = '' 
    344343 
    345344        now = int(time.time()) 
    346         ticket.save_changes(req.args.get('author', req.authname), 
     345        ticket.save_changes(util.get_authentic_id(req, 'author'), 
    347346                            req.args.get('comment'), when=now, db=db) 
    348347        db.commit() 
    349348 
  • trac/util.py

    diff -ru trac-0.9.5.orig/trac/util.py trac-0.9.5/trac/util.py
    old new  
    381381                raise Exception('Failed to create unique name: ' + path) 
    382382            path = '%s.%d%s' % (parts[0], idx, parts[1]) 
    383383 
    384 def get_reporter_id(req): 
    385     name = req.session.get('name', None) 
    386     email = req.session.get('email', None) 
    387      
     384def get_reporter_id(req, argname): 
    388385    if req.authname != 'anonymous': 
    389386        return req.authname 
    390     elif name and email: 
     387 
     388    r = req.args.get(argname) 
     389    if r: 
     390        return r 
     391    name = req.session.get('name', None) 
     392    email = req.session.get('email', None) 
     393    if name and email: 
    391394        return '%s <%s>' % (name, email) 
    392395    elif not name and email: 
    393396        return email 
    394397    else: 
    395398        return req.authname 
    396399 
     400def get_authentic_id(req, argname): 
     401    if req.authname != 'anonymous': 
     402        return req.authname 
     403    r = get_reporter_id(req, argname) 
     404    if r == 'anonymous': 
     405        return r 
     406    return r + ' [unauthenticated]' 
     407 
    397408# Date/time utilities 
    398409 
    399410def format_datetime(t=None, format='%x %X', gmt=False): 
  • trac/wiki/web_ui.py

    diff -ru trac-0.9.5.orig/trac/wiki/web_ui.py trac-0.9.5/trac/wiki/web_ui.py
    old new  
    2626from trac.Search import ISearchSource, query_to_sql, shorten_result 
    2727from trac.Timeline import ITimelineEventProvider 
    2828from trac.util import enum, format_datetime, get_reporter_id, \ 
     29                      get_authentic_id, \ 
    2930                      pretty_timedelta, shorten_line, Markup 
    3031from trac.versioncontrol.diff import get_diff_options, hdf_diff 
    3132from trac.web.chrome import add_link, add_stylesheet, INavigationContributor 
     
    183184            # WIKI_ADMIN 
    184185            page.readonly = int(req.args.has_key('readonly')) 
    185186 
    186         page.save(req.args.get('author'), req.args.get('comment'), 
     187        page.save(get_authentic_id(req, 'author'), req.args.get('comment'), 
    187188                  req.remote_addr) 
    188189        req.redirect(self.env.href.wiki(page.name)) 
    189190 
     
    283284        if preview: 
    284285            page.readonly = req.args.has_key('readonly') 
    285286 
    286         author = req.args.get('author', get_reporter_id(req)) 
     287        author = get_reporter_id(req, 'author') 
    287288        comment = req.args.get('comment', '') 
    288289        editrows = req.args.get('editrows') 
    289290        if editrows: