Edgewall Software

Ticket #1890: authen.diff

File authen.diff, 5.1 kB (added by maxb1@…, 3 years ago)

Patch vs. 0.9.3 showing possible fix

  • ./wiki/web_ui.py

    old new  
    2525from trac.perm import IPermissionRequestor 
    2626from trac.Search import ISearchSource, query_to_sql, shorten_result 
    2727from trac.Timeline import ITimelineEventProvider 
    28 from trac.util import enum, format_datetime, get_reporter_id, \ 
     28from trac.util import enum, format_datetime, get_reporter_id, get_authentic_id, \ 
    2929                      pretty_timedelta, shorten_line, Markup 
    3030from trac.versioncontrol.diff import get_diff_options, hdf_diff 
    3131from trac.web.chrome import add_link, add_stylesheet, INavigationContributor 
     
    183183            # WIKI_ADMIN 
    184184            page.readonly = int(req.args.has_key('readonly')) 
    185185 
    186         page.save(req.args.get('author'), req.args.get('comment'), 
     186        page.save(get_authentic_id(req, 'author'), req.args.get('comment'), 
    187187                  req.remote_addr) 
    188188        req.redirect(self.env.href.wiki(page.name)) 
    189189 
     
    283283        if preview: 
    284284            page.readonly = req.args.has_key('readonly') 
    285285 
    286         author = req.args.get('author', get_reporter_id(req)) 
     286        author = get_reporter_id(req, 'author') 
    287287        comment = req.args.get('comment', '') 
    288288        editrows = req.args.get('editrows') 
    289289        if editrows: 
  • ./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) 
     185        reporter_id = util.get_reporter_id(req, 'author') 
    186186 
    187187        if req.method == 'POST': 
    188188            if not req.args.has_key('preview'): 
     
    195195                req.hdf['ticket.reassign_owner'] = req.args.get('reassign_owner') \ 
    196196                                                   or req.authname 
    197197                req.hdf['ticket.resolve_resolution'] = req.args.get('resolve_resolution') 
    198                 reporter_id = req.args.get('author') 
    199198                comment = req.args.get('comment') 
    200199                if comment: 
    201200                    req.hdf['ticket.comment'] = comment 
     
    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 
  • ./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        } 
  • ./util.py

    old new  
    334334                raise Exception('Failed to create unique name: ' + path) 
    335335            path = '%s.%d%s' % (parts[0], idx, parts[1]) 
    336336 
    337 def get_reporter_id(req): 
     337def get_reporter_id(req, argname=None): 
    338338    name = req.session.get('name', None) 
    339339    email = req.session.get('email', None) 
    340340     
     341    if argname: 
     342        r = req.args.get(argname) 
     343        if r: 
     344            return r 
     345     
    341346    if req.authname != 'anonymous': 
    342347        return req.authname 
    343348    elif name and email: 
     
    347352    else: 
    348353        return req.authname 
    349354 
     355def get_authentic_id(req, argname): 
     356    r = get_reporter_id(req, argname) 
     357    if req.authname == 'anonymous': 
     358        return r + ' [unauthenticated]' 
     359    else: 
     360        if r == req.authname: 
     361            return r 
     362        else: 
     363            return '%s (%s)' % (req.authname, r) 
     364 
    350365# Date/time utilities 
    351366 
    352367def format_datetime(t=None, format='%x %X', gmt=False):