Edgewall Software

Ticket #4964: trac-with-userfilter-2.diff

File trac-with-userfilter-2.diff, 2.7 KB (added by francois_at_granade.com, 5 years ago)

The first patch attached to this bug was slightly buggy (it would break the other types of filters). This new patch doesn't break anything.

  • templates/timeline.cs

    diff -ru mytrac/templates/timeline.cs mytrac-with-userfilter/templates/timeline.cs
    old new  
    11<?cs include "header.cs"?> 
     2<?cs include "macros.cs" ?> 
    23 
    34<div id="ctxtnav" class="nav"></div> 
    45 
     
    1213  <label><input type="text" size="3" name="daysback" value="<?cs 
    1314    var:timeline.daysback ?>" /> days back</label>. 
    1415 </div> 
     16 <?cs if:len(timeline.known_users) ?> 
     17 <div> 
     18 
     19  <label>View changes made by user: </label> 
     20         <?cs call:hdf_select(timeline.known_users, 'username', timeline.username, 1) ?> 
     21 </div> 
     22 <?cs /if ?> 
     23 
    1524 <fieldset><?cs 
    1625  each:filter = timeline.filters ?> 
    1726   <label><input type="checkbox" name="<?cs var:filter.name ?>"<?cs 
  • trac/Timeline.py

    diff -ru mytrac/trac/Timeline.py mytrac-with-userfilter/trac/Timeline.py
    old new  
    8989    def match_request(self, req): 
    9090        return re.match(r'/timeline/?', req.path_info) is not None 
    9191 
     92    def _add_known_users_to_request(self, req): 
     93        user_list = list(self.env.get_known_users()) 
     94 
     95        for index, (username, name, email) in enumerate(user_list): 
     96           req.hdf["timeline.known_users.%d" % (index,)] = username 
     97 
     98       req.hdf['timeline.username'] = '' 
     99 
     100        if req.args.has_key('username'): 
     101           req.hdf['timeline.username'] = req.args.get('username') 
     102            
    92103    def process_request(self, req): 
    93104        req.perm.assert_permission('TIMELINE_VIEW') 
    94105 
     
    112123        req.hdf['timeline.from'] = format_date(fromdate) 
    113124        req.hdf['timeline.daysback'] = daysback 
    114125 
     126        self._add_known_users_to_request(req) 
     127 
    115128        available_filters = [] 
    116129        for event_provider in self.event_providers: 
    117130            available_filters += event_provider.get_timeline_filters(req) 
     
    135148                elif req.session.has_key(key): 
    136149                    del req.session[key] 
    137150 
     151        user_filter = req.args.get("username") 
     152 
    138153        stop = fromdate 
    139154        start = stop - (daysback + 1) * 86400 
    140155 
     
    161176 
    162177        idx = 0 
    163178        for kind, href, title, date, author, message in events: 
     179            # Do not display the event if the user is not explicitly mentioned in the filter 
     180            if user_filter and author not in user_filter: 
     181                continue 
     182            
    164183            event = {'kind': kind, 'title': title, 'href': href, 
    165184                     'author': author or 'anonymous', 
    166185                     'date': format_date(date),