Changeset 4261
- Timestamp:
- 09/11/08 07:06:56 (2 months ago)
- Files:
-
- timingandestimationplugin/branches/trac0.11-Permissions/timingandestimationplugin/api.py (modified) (1 diff)
- timingandestimationplugin/branches/trac0.11-Permissions/timingandestimationplugin/blackmagic.py (modified) (7 diffs)
- timingandestimationplugin/branches/trac0.11-Permissions/timingandestimationplugin/htdocs/ticket.js (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
timingandestimationplugin/branches/trac0.11-Permissions/timingandestimationplugin/api.py
r4260 r4261 6 6 from blackmagic import * 7 7 from ticket_daemon import * 8 from ticket_webui import * 8 9 from usermanual import * 9 10 from trac.log import logger_factory timingandestimationplugin/branches/trac0.11-Permissions/timingandestimationplugin/blackmagic.py
r4260 r4261 24 24 def remove_header(stream, field): 25 25 """ Removes the display from the ticket properties """ 26 stream = stream | Transformer('//th[@id="h_%s"]' % field).replace(tag.th(id="h_%s" % field)) 27 stream = stream | Transformer('//td[@headers="h_%s"]' % field).replace(tag.th(id="h_%s" % field)) 26 stream = stream | \ 27 Transformer('//th[@id="h_%s"]' % field).replace(tag.th(id="h_%s" % field)) 28 stream = stream | \ 29 Transformer('//td[@headers="h_%s"]' % field).replace(tag.th(id="h_%s" % field)) 28 30 return stream 31 32 def remove_changelog(stream, field): 33 """ Removes entries from the visible changelog""" 34 def helper(field_stream): 35 s = Stream(field_stream) 36 f = s.select('//strong/text()').render() 37 if field != f: #if we are the field just skip it 38 #identity stream filter 39 for kind, data, pos in s: 40 yield kind, data, pos 41 stream = stream | Transformer('//ul[@class="changes"]/li').filter(helper) 42 return stream 43 44 45 def hide_field(stream , field): 46 """ Replaces a field from the form area with an input type=hidden""" 47 def helper (field_stream): 48 value = Stream(field_stream).select('@value').render() 49 name = Stream(field_stream).select('@name').render() 50 for kind,data,pos in tag.input( value=value, id=("field-%s"%field), 51 type="hidden", name=name).generate(): 52 yield kind,data,pos 53 stream = stream | Transformer('//label[@for="field-%s"]' % field).replace(" ") 54 stream = stream | Transformer('//input[@id="field-%s"]' % field).replace(" ") 55 56 return remove_changelog(remove_header(stream , field), field) 29 57 30 58 def remove_field(stream , field): 31 59 """ Removes a field from the form area""" 32 60 stream = stream | Transformer('//label[@for="field-%s"]' % field).replace(" ") 33 stream = stream | Transformer('//*[@id="field-%s"]' % field).replace(" ") 34 return remove_header(stream , field) 35 61 stream = stream | Transformer('//input[@id="field-%s"]' % field).replace(" ") 62 return remove_changelog(remove_header(stream , field), field) 36 63 37 64 def istrue(v, otherwise=None): … … 44 71 return otherwise 45 72 73 csection = 'field settings' 74 46 75 class TicketTweaks(Component): 47 implements(ITemplateStreamFilter, ITemplateProvider, IPermissionRequestor) 48 49 permissions = ListOption('blackmagic', 'permissions', []) 50 gray_disabled = Option('blackmagic', 'gray_disabled', '', 76 implements(ITemplateStreamFilter, ITemplateProvider, IPermissionRequestor) 77 permissions = ListOption(csection, 'permissions', []) 78 gray_disabled = Option(csection, 'gray_disabled', '', 51 79 doc="""If not set, disabled items will have their label striked through. 52 80 Otherwise, this color will be used to gray them out. Suggested #cccccc.""") … … 59 87 60 88 def filter_stream(self, req, method, filename, stream, data): 89 self.log.debug('IN BlackMagic') 61 90 if not filename == "ticket.html": 91 self.log.debug('Not a ticket returning') 62 92 return stream 63 enchants = self.config.getlist('field settings', 'fields', '') 93 enchants = self.config.getlist(csection, 'fields', []) 94 self.log.debug('read enchants = %r' % enchants) 64 95 for field in enchants: 65 96 self.log.debug('BlackMagicing: %s' % field) … … 67 98 hidden = False 68 99 hide_summary = False 69 perms = self.config.getlist('field settings', '%s.permission' % field, []) 100 remove = False 101 perms = self.config.getlist(csection, '%s.permission' % field, []) 70 102 self.log.debug('BlackMagicing - read permission config: %s has %s' % (field, perms)) 71 103 for (perm, denial) in [s.split(":") for s in perms] : 72 104 perm = perm.upper() 73 self.log.debug('BlackMagicing - testing permission: %s has %s = %s' % (field, perm, (perm not in req.perm or perm == "ALWAYS"))) 74 if (perm not in req.perm or perm == "ALWAYS"): 105 self.log.debug('BlackMagicing - testing permission: %s:%s should act= %s' % 106 (field, perm, (not req.perm.has_permission(perm) or perm == "ALWAYS"))) 107 if (not req.perm.has_permission(perm) or perm == "ALWAYS"): 75 108 if denial: 76 109 denial = denial.lower() … … 79 112 elif denial == "hide": 80 113 hidden = True 114 elif denial == "remove": 115 remove = True 81 116 else: 82 117 disabled = True … … 84 119 disabled = True 85 120 86 if disabled or istrue(self.config.get( 'field settings', '%s.disable' % field, False)):121 if disabled or istrue(self.config.get(csection, '%s.disable' % field, False)): 87 122 self.log.debug('BlackMagic disabling: %s' % field) 88 stream = stream | Transformer('//*[@id="field-%s"]' % field).attr("disabled", "disabled") 89 if not self.gray_disabled: 90 stream = stream | Transformer('//label[@for="field-%s"]' % field).replace( 91 tag.strike()('%s:' % field.capitalize()) 92 ) 93 else: 94 stream = stream | Transformer('//label[@for="field-%s"]' % field).replace( 95 tag.span(style="color:%s" % self.gray_disabled)('%s:' % field.capitalize()) 96 ) 123 stream = disable_field(stream, field) 97 124 98 if self.config.get( 'field settings', '%s.label' % field, None):125 if self.config.get(csection, '%s.label' % field, None): 99 126 self.log.debug('BlackMagic labeling: %s' % field) 100 127 stream = stream | Transformer('//label[@for="field-%s"]' % field).replace( 101 self.config.get( 'field settings', '%s.label' % field)128 self.config.get(csection, '%s.label' % field) 102 129 ) 103 130 104 if self.config.get( 'field settings', '%s.notice' % field, None):131 if self.config.get(csection, '%s.notice' % field, None): 105 132 self.log.debug('BlackMagic noticing: %s' % field) 106 133 stream = stream | Transformer('//*[@id="field-%s"]' % field).after( 107 134 tag.br() + tag.small()( 108 135 tag.em()( 109 Markup(self.config.get( 'field settings', '%s.notice' % field))136 Markup(self.config.get(csection, '%s.notice' % field)) 110 137 ) 111 138 ) 112 139 ) 113 140 114 tip = self.config.get( 'field settings', '%s.tip' % field, None)141 tip = self.config.get(csection, '%s.tip' % field, None) 115 142 if tip: 116 143 self.log.debug('BlackMagic tipping: %s' % field) … … 124 151 ) 125 152 126 if hidden or istrue(self.config.get('field settings', '%s.hide' % field, None)): 153 if remove or istrue(self.config.get(csection, '%s.remove' % field, None)): 154 self.log.debug('BlackMagic removing: %s' % field) 155 stream = remove_field(stream, field) 156 157 if hidden or istrue(self.config.get(csection, '%s.hide' % field, None)): 127 158 self.log.debug('BlackMagic hiding: %s' % field) 128 stream = remove_field(field)159 stream = hide_field(stream, field) 129 160 130 161 return stream timingandestimationplugin/branches/trac0.11-Permissions/timingandestimationplugin/htdocs/ticket.js
r2786 r4261 86 86 catch (er) {} 87 87 88 88 /* 89 89 // Hide the Add Hours in the title table 90 90 // if we fail, then no harm done. … … 97 97 } 98 98 catch (er) {} 99 99 */ 100 100 101 101 // Convert hours from float to hours minutes seconds
