Beispiel #1
0
    def filter_stream(self, req, method, filename, stream, data):
        #remove matches from custom queries due to the fact ticket permissions are checked after this stream is manipulated so the count cannot be updated.
        if filename == "query.html":
            stream |= Transformer('//div[@class="query"]/h1/span[@class="numrows"]/text()').replace("")

        if filename == "ticket.html":
            for field,e in self.enchants.items():
                disabled = e["disable"]
                hidden = e["hide"]
                #permissions are set for field
                if e["permission"] != "" and not hidden and not (disabled or disabled and e["ondenial"]=="hide"):
                    self.env.log.debug("Permissions %s" % e["permission"])
                    #default set to denied
                    denied = True
                    #iterate through permissions
                    for perm in (x.strip() for x in e["permission"].split(',')):
                        self.env.log.debug("Checking permission %s" % perm)
                        #user has permission no denied
                        if perm and perm in req.perm(data.get("ticket").resource):
                            self.env.log.debug("Has %s permission" % perm)
                            denied = False
                    #if denied is true hide/disable dpending on denial setting
                    if denied:
                        denial = self.config.get('blackmagic', '%s.ondenial' % field, None)
                        if denial:
                            if denial == "disable":
                                disabled = True
                            elif denial == "hide":
                                hidden = True
                            else:
                                disabled = True
                        else:
                                disabled = True

                #hide fields
                if hidden:
                    #replace th and td in previews with empty tags
                    stream = stream | Transformer('//th[@id="h_%s"]' % field).replace(tag.th(" "))
                    stream = stream | Transformer('//td[@headers="h_%s"]' % field).replace(tag.td(" "))
                    #replace labels and fields with blank space
                    stream = stream | Transformer('//label[@for="field-%s"]' % field).replace(" ")
                    stream = stream | Transformer('//*[@id="field-%s"]' % field).replace(" ")

                #change label
                if e["label"] is not None:
                    stream |= Transformer('//th[@id="h_%s"]/text()' % field).replace(e["label"] + ":")
                    stream = stream | Transformer('//label[@for="field-%s"]/text()' % field).replace(e["label"] + ":")

                if disabled:
                    buffer = StreamBuffer()
                    #copy input to buffer then disable original
                    stream |= Transformer('//*[@id="field-%s" and (@checked) and @type="checkbox"]' % field).copy(buffer).after(buffer).attr("disabled","disabled")
                    #change new element to hidden field instead of checkbox and remove check
                    stream |= Transformer('//*[@id="field-%s" and not (@disabled) and (@checked) and @type="checkbox"]' % field).attr("type","hidden").attr("checked",None).attr("id",None)
                    #disable non-check boxes / unchecked check boxes
                    stream = stream | Transformer('//*[@id="field-%s" and not (@checked)]' % field).attr("disabled", "disabled")

                    if not self.gray_disabled:
                        #cut label content into buffer then append it into the label with a strike tag around it
                        stream = stream | Transformer('//label[@for="field-%s"]/text()' % field).cut(buffer).end().select('//label[@for="field-%s"]/' % field).append(tag.strike(buffer))
                    else:
                        #cut label and replace with coloured span
                        stream = stream | Transformer('//label[@for="field-%s"]/text()' % field).cut(buffer).end().select('//label[@for="field-%s"]/' % field).append(tag.span(buffer, style="color:%s" % self.gray_disabled))

                if self.config.get('blackmagic', '%s.notice' % field, None):
                    stream = stream | Transformer('//*[@id="field-%s"]' % field).after(
                        tag.br() + tag.small()(
                            tag.em()(
                                Markup(self.config.get('blackmagic', '%s.notice' % field))
                            )
                        )
                    )

                tip = self.config.get('blackmagic', '%s.tip' % field, None)
                if tip:
                    stream = stream | Transformer('//div[@id="banner"]').before(
                        tag.script(type="text/javascript",
                        src=req.href.chrome("blackmagic", "js", "wz_tooltip.js"))()
                    )

                    stream = stream | Transformer('//*[@id="field-%s"]' % field).attr(
                        "onmouseover", "Tip('%s')" % tip.replace(r"'", r"\'")
                    )


        return stream
    def filter_stream(self, req, method, filename, stream, data):
        if filename == "ticket.html":
            ##Check Permissions
            enchants = self.config.get('blackmagic', 'tweaks', '')
            for field in (x.strip() for x in enchants.split(',')):
                self.env.log.debug("Checking %s:" % field)
                disabled = False
                hidden = False
                #Get a list of the permissions from the config, split them on commas and remove spaces
                perms = self.config.get('blackmagic', '%s.permission' % field, '').upper()
                #Default to not having permissions
                hasPerm = True
                if perms:
                    hasPerm = False
                    #If there are permissions
                    self.env.log.debug("perm: %s" % len(perms))
                    perms = perms.split(',')
                    #walk the list we got back and check the request for the permission
                    for perm in perms:
                        perm = perm.strip()
                        self.env.log.debug("Checking perm: %s" % perm)
                        if perm in req.perm:
                            self.env.log.debug("User has perm: %s" % perm)
                            hasPerm = True
                    if hasPerm == False:
                        denial = self.config.get('blackmagic', '%s.ondenial' % field, None)
                        if denial:
                            if denial == "disable":
                                disabled = True
                            elif denial == "hide":
                                hidden = True
                            else:
                                disabled = True
                        else:
                            disabled = True

                self.env.log.debug('hasPerm: %s' % hasPerm)
                if hidden == False:
                    if self.config.get('blackmagic', '%s.label' % field, None):
                        labelTXT = self.config.get('blackmagic', '%s.label' % field)
                        label = tag.label("%s:" %labelTXT, for_="field-%s" % field)
                        stream = stream | Transformer('//label[@for="field-%s"]' % field).replace(label)

                if hasPerm == False:   
                    if istrue(self.config.get('blackmagic', '%s.hide' % field, None)):
                        hidden = True
                        
                    if disabled or istrue(self.config.get('blackmagic', '%s.disable' % field, False)):
                        stream = stream | Transformer('//*[@id="field-%s"]' % field).attr("disabled", "disabled")
                        label = self.config.get('blackmagic', '%s.label' % field)
                        if not label:
                            label = field.capitalize()
                        if not self.gray_disabled:
                            stream = stream | Transformer('//label[@for="field-%s"]' % field).replace(
                                tag.strike()('%s:' % label)
                            )
                        else:
                            stream = stream | Transformer('//label[@for="field-%s"]' % field).replace(
                                tag.span(style="color:%s" % self.gray_disabled)('%s:' % label)
                            )
                    
                    if hidden or istrue(self.config.get('blackmagic', '%s.hide' % field, None)):
                        stream = stream | Transformer('//th[@id="h_%s"]' % field).replace(" ") 
                        stream = stream | Transformer('//td[@headers="h_%s"]' % field).replace(" ")
                        stream = stream | Transformer('//label[@for="field-%s"]' % field).replace(" ")
                        stream = stream | Transformer('//*[@id="field-%s"]' % field).replace(" ")

                    
                if hidden == False:
                    if self.config.get('blackmagic', '%s.notice' % field, None):
                        stream = stream | Transformer('//*[@id="field-%s"]' % field).after(
                            tag.br() + tag.small(class_="notice-%s" %field)(
                                tag.em()(
                                    Markup(self.config.get('blackmagic', '%s.notice' % field))
                                )
                            )
                        )
                    
                tip = self.config.get('blackmagic', '%s.tip' % field, None)
                if tip:
                    stream = stream | Transformer('//div[@id="banner"]').before(
                        tag.script(type="text/javascript", 
                        src=req.href.chrome("blackmagic", "js", "wz_tooltip.js"))()
                    )
                    
                    stream = stream | Transformer('//*[@id="field-%s"]' % field).attr(
                        "onmouseover", "Tip('%s')" % tip.replace(r"'", r"\'")
                    )
                        
                    
        return stream
Beispiel #3
0
    def filter_stream(self, req, method, filename, stream, data):
        #remove matches from custom queries due to the fact ticket permissions are checked after this stream is manipulated so the count cannot be updated.
        if filename == "query.html":
            stream |= Transformer(
                '//div[@class="query"]/h1/span[@class="numrows"]/text()'
            ).replace("")

        if filename == "ticket.html":
            for field, e in self.enchants.items():
                disabled = e["disable"]
                hidden = e["hide"]
                #permissions are set for field
                if e["permission"] != "" and not hidden and not (
                        disabled or disabled and e["ondenial"] == "hide"):
                    self.env.log.debug("Permissions %s" % e["permission"])
                    #default set to denied
                    denied = True
                    #iterate through permissions
                    for perm in (x.strip()
                                 for x in e["permission"].split(',')):
                        self.env.log.debug("Checking permission %s" % perm)
                        #user has permission no denied
                        if perm and perm in req.perm(
                                data.get("ticket").resource):
                            self.env.log.debug("Has %s permission" % perm)
                            denied = False
                    #if denied is true hide/disable dpending on denial setting
                    if denied:
                        denial = self.config.get('blackmagic',
                                                 '%s.ondenial' % field, None)
                        if denial:
                            if denial == "disable":
                                disabled = True
                            elif denial == "hide":
                                hidden = True
                            else:
                                disabled = True
                        else:
                            disabled = True

                #hide fields
                if hidden:
                    #replace th and td in previews with empty tags
                    stream = stream | Transformer(
                        '//th[@id="h_%s"]' % field).replace(tag.th(" "))
                    stream = stream | Transformer(
                        '//td[@headers="h_%s"]' % field).replace(tag.td(" "))
                    #replace labels and fields with blank space
                    stream = stream | Transformer(
                        '//label[@for="field-%s"]' % field).replace(" ")
                    stream = stream | Transformer(
                        '//*[@id="field-%s"]' % field).replace(" ")

                #change label
                if e["label"] is not None:
                    stream |= Transformer('//th[@id="h_%s"]/text()' %
                                          field).replace(e["label"] + ":")
                    stream = stream | Transformer(
                        '//label[@for="field-%s"]/text()' %
                        field).replace(e["label"] + ":")

                if disabled:
                    buffer = StreamBuffer()
                    #copy input to buffer then disable original
                    stream |= Transformer(
                        '//*[@id="field-%s" and (@checked) and @type="checkbox"]'
                        % field).copy(buffer).after(buffer).attr(
                            "disabled", "disabled")
                    #change new element to hidden field instead of checkbox and remove check
                    stream |= Transformer(
                        '//*[@id="field-%s" and not (@disabled) and (@checked) and @type="checkbox"]'
                        % field).attr("type",
                                      "hidden").attr("checked",
                                                     None).attr("id", None)
                    #disable non-check boxes / unchecked check boxes
                    stream = stream | Transformer(
                        '//*[@id="field-%s" and not (@checked)]' % field).attr(
                            "disabled", "disabled")

                    if not self.gray_disabled:
                        #cut label content into buffer then append it into the label with a strike tag around it
                        stream = stream | Transformer(
                            '//label[@for="field-%s"]/text()' %
                            field).cut(buffer).end().select(
                                '//label[@for="field-%s"]/' % field).append(
                                    tag.strike(buffer))
                    else:
                        #cut label and replace with coloured span
                        stream = stream | Transformer(
                            '//label[@for="field-%s"]/text()' %
                            field).cut(buffer).end().select(
                                '//label[@for="field-%s"]/' % field).append(
                                    tag.span(
                                        buffer,
                                        style="color:%s" % self.gray_disabled))

                if self.config.get('blackmagic', '%s.notice' % field, None):
                    stream = stream | Transformer(
                        '//*[@id="field-%s"]' % field
                    ).after(tag.br() + tag.small()(tag.em()(Markup(
                        self.config.get('blackmagic', '%s.notice' % field)))))

                tip = self.config.get('blackmagic', '%s.tip' % field, None)
                if tip:
                    stream = stream | Transformer(
                        '//div[@id="banner"]').before(
                            tag.script(type="text/javascript",
                                       src=req.href.chrome(
                                           "blackmagic", "js",
                                           "wz_tooltip.js"))())

                    stream = stream | Transformer(
                        '//*[@id="field-%s"]' % field).attr(
                            "onmouseover",
                            "Tip('%s')" % tip.replace(r"'", r"\'"))

        return stream