Changeset 4261

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

finished the ticket permissions
Commented out the javascript that hid the hours in the header now that I can do that from python
(based on additions to blackmagic plugin: http://trac-hacks.org/wiki/BlackMagicTicketTweaksPlugin)

Files:

Legend:

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

    r4260 r4261  
    66from blackmagic import * 
    77from ticket_daemon import * 
     8from ticket_webui import * 
    89from usermanual import * 
    910from trac.log import logger_factory 
  • timingandestimationplugin/branches/trac0.11-Permissions/timingandestimationplugin/blackmagic.py

    r4260 r4261  
    2424def remove_header(stream, field): 
    2525    """ 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)) 
    2830    return stream 
     31 
     32def 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 
     45def 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) 
    2957 
    3058def remove_field(stream , field): 
    3159    """ Removes a field from the form area""" 
    3260    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) 
    3663 
    3764def istrue(v, otherwise=None): 
     
    4471            return otherwise    
    4572 
     73csection = 'field settings' 
     74 
    4675class 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', '',  
    5179        doc="""If not set, disabled items will have their label striked through.  
    5280        Otherwise, this color will be used to gray them out. Suggested #cccccc.""") 
     
    5987     
    6088    def filter_stream(self, req, method, filename, stream, data): 
     89        self.log.debug('IN BlackMagic') 
    6190        if not filename == "ticket.html": 
     91            self.log.debug('Not a ticket returning') 
    6292            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) 
    6495        for field in enchants: 
    6596            self.log.debug('BlackMagicing: %s' % field) 
     
    6798            hidden = False 
    6899            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, []) 
    70102            self.log.debug('BlackMagicing - read permission config: %s has %s' % (field, perms)) 
    71103            for (perm, denial) in [s.split(":") for s in perms] : 
    72104                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"):  
    75108                    if denial: 
    76109                        denial = denial.lower() 
     
    79112                        elif denial == "hide": 
    80113                            hidden = True 
     114                        elif denial == "remove": 
     115                            remove = True 
    81116                        else: 
    82117                            disabled = True 
     
    84119                        disabled = True 
    85120                     
    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)): 
    87122                    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) 
    97124 
    98                 if self.config.get('field settings', '%s.label' % field, None): 
     125                if self.config.get(csection, '%s.label' % field, None): 
    99126                    self.log.debug('BlackMagic labeling: %s' % field) 
    100127                    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) 
    102129                    ) 
    103130                     
    104                 if self.config.get('field settings', '%s.notice' % field, None): 
     131                if self.config.get(csection, '%s.notice' % field, None): 
    105132                    self.log.debug('BlackMagic noticing: %s' % field) 
    106133                    stream = stream | Transformer('//*[@id="field-%s"]' % field).after( 
    107134                        tag.br() + tag.small()( 
    108135                            tag.em()( 
    109                                 Markup(self.config.get('field settings', '%s.notice' % field)) 
     136                                Markup(self.config.get(csection, '%s.notice' % field)) 
    110137                            ) 
    111138                        ) 
    112139                    ) 
    113140                     
    114                 tip = self.config.get('field settings', '%s.tip' % field, None) 
     141                tip = self.config.get(csection, '%s.tip' % field, None) 
    115142                if tip: 
    116143                    self.log.debug('BlackMagic tipping: %s' % field) 
     
    124151                    ) 
    125152                     
    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)): 
    127158                    self.log.debug('BlackMagic hiding: %s' % field) 
    128                     stream = remove_field(field) 
     159                    stream = hide_field(stream, field) 
    129160                     
    130161        return stream 
  • timingandestimationplugin/branches/trac0.11-Permissions/timingandestimationplugin/htdocs/ticket.js

    r2786 r4261  
    8686      catch (er) {} 
    8787   
    88    
     88      /* 
    8989      // Hide the Add Hours in the title table 
    9090      // if we fail, then no harm done. 
     
    9797      } 
    9898      catch (er) {} 
    99        
     99      */ 
    100100       
    101101      // Convert hours from float to hours minutes seconds