Changeset 4264

Show
Ignore:
Timestamp:
09/11/08 08:06:53 (2 months ago)
Author:
bobbysmith007
Message:

improved logging

added a filter for the query screen that enforces permissions

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • timingandestimationplugin/branches/trac0.11-Permissions/timingandestimationplugin/blackmagic.py

    r4261 r4264  
    9191            self.log.debug('Not a ticket returning') 
    9292            return stream 
    93         enchants = self.config.getlist(csection, 'fields', []) 
    94         self.log.debug('read enchants = %r' % enchants) 
    95         for field in enchants: 
    96             self.log.debug('BlackMagicing: %s' % field) 
     93        fields = self.config.getlist(csection, 'fields', []) 
     94        self.log.debug('read enchants = %r' % fields) 
     95        for field in fields: 
     96            self.log.debug('starting : %s' % field) 
    9797            disabled = False 
    9898            hidden = False 
     
    100100            remove = False 
    101101            perms = self.config.getlist(csection, '%s.permission' % field, []) 
    102             self.log.debug('BlackMagicing - read permission config: %s has %s' % (field, perms)) 
     102            self.log.debug('read permission config: %s has %s' % (field, perms)) 
    103103            for (perm, denial) in [s.split(":") for s in perms] : 
    104104                perm = perm.upper() 
    105                 self.log.debug('BlackMagicing - testing permission: %s:%s should act= %s' % 
     105                self.log.debug('testing permission: %s:%s should act= %s' % 
    106106                               (field, perm, (not req.perm.has_permission(perm) or perm == "ALWAYS"))) 
    107107                if (not req.perm.has_permission(perm) or perm == "ALWAYS"):  
     
    120120                     
    121121                if disabled or istrue(self.config.get(csection, '%s.disable' % field, False)): 
    122                     self.log.debug('BlackMagic disabling: %s' % field) 
     122                    self.log.debug('disabling: %s' % field) 
    123123                    stream = disable_field(stream, field) 
    124124 
    125125                if self.config.get(csection, '%s.label' % field, None): 
    126                     self.log.debug('BlackMagic labeling: %s' % field) 
     126                    self.log.debug('labeling: %s' % field) 
    127127                    stream = stream | Transformer('//label[@for="field-%s"]' % field).replace( 
    128128                        self.config.get(csection, '%s.label' % field) 
     
    130130                     
    131131                if self.config.get(csection, '%s.notice' % field, None): 
    132                     self.log.debug('BlackMagic noticing: %s' % field) 
     132                    self.log.debug('noticing: %s' % field) 
    133133                    stream = stream | Transformer('//*[@id="field-%s"]' % field).after( 
    134134                        tag.br() + tag.small()( 
     
    141141                tip = self.config.get(csection, '%s.tip' % field, None) 
    142142                if tip: 
    143                     self.log.debug('BlackMagic tipping: %s' % field) 
     143                    self.log.debug('tipping: %s' % field) 
    144144                    stream = stream | Transformer('//div[@id="banner"]').before( 
    145145                        tag.script(type="text/javascript",  
     
    152152                     
    153153                if remove or istrue(self.config.get(csection, '%s.remove' % field, None)): 
    154                     self.log.debug('BlackMagic removing: %s' % field) 
     154                    self.log.debug('removing: %s' % field) 
    155155                    stream = remove_field(stream, field) 
    156156 
    157157                if hidden or istrue(self.config.get(csection, '%s.hide' % field, None)): 
    158                     self.log.debug('BlackMagic hiding: %s' % field) 
     158                    self.log.debug('hiding: %s' % field) 
    159159                    stream = hide_field(stream, field) 
    160160                     
  • timingandestimationplugin/branches/trac0.11-Permissions/timingandestimationplugin/tande_filters.py

    r4260 r4264  
    88from blackmagic import * 
    99 
    10 class TimePermissionFilter(Component): 
    11     """Filtering the streams based on permissions to edit touch various fields""" 
    12     implements(ITemplateStreamFilter, IPermissionRequestor) 
    13     # IPermissionRequestor methods  
    14     def get_permission_actions(self):  
    15         return ["TIME_VIEW", "TIME_RECORD", ("TIME_ADMIN", ["TIME_RECORD", "TIME_VIEW"])]  
     10class TicketFormatFilter(Component): 
     11    """Filtering the streams to alter the base format of the ticket""" 
     12    implements(ITemplateStreamFilter) 
     13 
     14    def filter_stream(self, req, method, filename, stream, data): 
     15        self.log.debug("TicketFormatFilter executing")  
     16        if not filename == 'ticket.html': 
     17            self.log.debug("TicketFormatFilter not the correct template") 
     18            return stream 
     19         
     20        self.log.debug("TicketFormatFilter disabling totalhours and removing header hours") 
     21        stream = disable_field(stream, "totalhours") 
     22        stream = remove_header(stream, "hours") 
     23        return stream  
    1624 
    1725 
     26class QueryColumnPermissionFilter(Component): 
     27    """ Filtering the stream to remove """ 
     28    implements(ITemplateStreamFilter, IPermissionRequestor)     
     29    ## IPermissionRequestor methods 
     30     
     31    def get_permission_actions(self): 
     32        fields = self.config.getlist(csection, 'fields', []) 
     33        permissions = self.config.getlist(csection, 'permissions', []) 
     34        perms = [] 
     35        for field in fields: 
     36            perms.extend(self.config.getlist(csection, '%s.permission' % field, [])) 
     37        for (perm, denial) in [s.split(":") for s in perms]: 
     38            permissions.append(perm) 
     39        return (x.upper() for x in permissions) 
     40     
     41    ## ITemplateStreamFilter 
     42     
    1843    def filter_stream(self, req, method, filename, stream, data): 
    19         self.log.debug("TimePermissionFilter executing")  
    20         if not filename == 'ticket.html'
    21             self.log.debug("TimePermissionFilter not the correct template"
     44        self.log.debug('IN QueryColumn') 
     45        if not filename == "query.html"
     46            self.log.debug('Not a query returning'
    2247            return stream 
    23          
    24         self.log.debug("TimePermissionFilter Always disabling totalhours") 
    25         stream = disable_field(stream, "totalhours") 
    26         stream = remove_header(stream, "hours") 
    2748 
    28 #         if not req.perm.has_permission("TIME_VIEW"): 
    29 #             self.log.debug("TimePermissionFilter: No TIME_VIEW! removing billable and total hours") 
    30 #             stream = remove_field(stream, "billable"
    31 #             stream = remove_field(stream, "totalhours"
    32 #         if not req.perm.has_permission("TIME_RECORD"): 
    33 #             self.log.debug("TimePermissionFilter matching: No TIME_RECORD removing hours making billable and estimatedhours disabled") 
    34 #             stream = remove_field(stream, "hours") 
    35 #             stream = disable_field(stream, "billable") 
    36 #             stream = disable_field(stream, "estimatedhours") 
     49        def make_col_helper(field): 
     50            def column_helper (column_stream): 
     51                s =  Stream(column_stream
     52                val = s.select('//input/@value').render(
     53                if val.lower() != field.lower(): #if we are the field just skip it 
     54                    #identity stream filter 
     55                    for kind, data, pos in s: 
     56                        yield kind, data, pos         
     57            return column_helper 
    3758 
    38         return stream  
     59        fields = self.config.getlist(csection, 'fields', []) 
     60        for field in fields: 
     61            self.log.debug('found : %s' % field) 
     62            perms = self.config.getlist(csection, '%s.permission' % field, []) 
     63            self.log.debug('read permission config: %s has %s' % (field, perms)) 
     64            for (perm, denial) in [s.split(":") for s in perms] : 
     65                perm = perm.upper() 
     66                self.log.debug('testing permission: %s:%s should act= %s' % 
     67                               (field, perm, (not req.perm.has_permission(perm) or perm == "ALWAYS"))) 
     68                if (not req.perm.has_permission(perm) or perm == "ALWAYS"): 
     69                    # remove from the list of addable  
     70                    stream = stream | Transformer( 
     71                        '//select[@id="add_filter"]/option[@value="%s"]' % field 
     72                        ).replace(" ") 
     73 
     74                    # remove from the list of columns 
     75                    stream = stream | Transformer( 
     76                        '//fieldset[@id="columns"]/div/label' 
     77                        ).filter(make_col_helper(field)) 
     78                     
     79                    #remove from the results table 
     80                    stream = stream | Transformer( 
     81                        '//th[@class="%s"]' % field 
     82                        ).replace(" ") 
     83                    stream = stream | Transformer( 
     84                        '//td[@class="%s"]' % field 
     85                        ).replace(" ") 
     86 
     87                    # remove from the filters 
     88                    stream = stream | Transformer( 
     89                        '//tr[@class="%s"]' % field 
     90                        ).replace(" ") 
     91 
     92                     
     93        return stream