Changeset 4264
- Timestamp:
- 09/11/08 08:06:53 (2 months ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
timingandestimationplugin/branches/trac0.11-Permissions/timingandestimationplugin/blackmagic.py
r4261 r4264 91 91 self.log.debug('Not a ticket returning') 92 92 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) 97 97 disabled = False 98 98 hidden = False … … 100 100 remove = False 101 101 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)) 103 103 for (perm, denial) in [s.split(":") for s in perms] : 104 104 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' % 106 106 (field, perm, (not req.perm.has_permission(perm) or perm == "ALWAYS"))) 107 107 if (not req.perm.has_permission(perm) or perm == "ALWAYS"): … … 120 120 121 121 if disabled or istrue(self.config.get(csection, '%s.disable' % field, False)): 122 self.log.debug(' BlackMagicdisabling: %s' % field)122 self.log.debug('disabling: %s' % field) 123 123 stream = disable_field(stream, field) 124 124 125 125 if self.config.get(csection, '%s.label' % field, None): 126 self.log.debug(' BlackMagiclabeling: %s' % field)126 self.log.debug('labeling: %s' % field) 127 127 stream = stream | Transformer('//label[@for="field-%s"]' % field).replace( 128 128 self.config.get(csection, '%s.label' % field) … … 130 130 131 131 if self.config.get(csection, '%s.notice' % field, None): 132 self.log.debug(' BlackMagicnoticing: %s' % field)132 self.log.debug('noticing: %s' % field) 133 133 stream = stream | Transformer('//*[@id="field-%s"]' % field).after( 134 134 tag.br() + tag.small()( … … 141 141 tip = self.config.get(csection, '%s.tip' % field, None) 142 142 if tip: 143 self.log.debug(' BlackMagictipping: %s' % field)143 self.log.debug('tipping: %s' % field) 144 144 stream = stream | Transformer('//div[@id="banner"]').before( 145 145 tag.script(type="text/javascript", … … 152 152 153 153 if remove or istrue(self.config.get(csection, '%s.remove' % field, None)): 154 self.log.debug(' BlackMagicremoving: %s' % field)154 self.log.debug('removing: %s' % field) 155 155 stream = remove_field(stream, field) 156 156 157 157 if hidden or istrue(self.config.get(csection, '%s.hide' % field, None)): 158 self.log.debug(' BlackMagichiding: %s' % field)158 self.log.debug('hiding: %s' % field) 159 159 stream = hide_field(stream, field) 160 160 timingandestimationplugin/branches/trac0.11-Permissions/timingandestimationplugin/tande_filters.py
r4260 r4264 8 8 from blackmagic import * 9 9 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"])] 10 class 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 16 24 17 25 26 class 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 18 43 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') 22 47 return stream 23 24 self.log.debug("TimePermissionFilter Always disabling totalhours")25 stream = disable_field(stream, "totalhours")26 stream = remove_header(stream, "hours")27 48 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 37 58 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
