def __init__(self): self._fetch_tkt_tags() cfg = self.config cfg_key = 'permission_policies' default_policies = cfg.defaults().get('trac', {}).get(cfg_key) self.fast_permcheck = all(p in default_policies for p in cfg.get('trac', cfg_key))
def sort(self): """Do an in-place topological sort of this prototype.""" from api import TracForgeAdminSystem steps = TracForgeAdminSystem(self.env).get_project_setup_participants() all_provides = set() for action, args in self: all_provides |= set(steps[action].get('provides', ())) effective_depends = {} for action, args in self: # All real deps are always used effective_depends.setdefault(action, []).extend(steps[action].get('depends', ())) for tag in steps[action].get('optional_depends', ()): # Any optional dep that is provided by something else is used if tag in all_provides: effective_depends[action].append(tag) old = set([action for action, args in self]) new = [] tags = set() for i in xrange(len(self)): for action in old: self.env.log.debug('TracForge: %s %s %s %s %s', i, action, old, new, tags) if all([tag in tags for tag in effective_depends[action]]): new.append(action) tags |= set(steps[action].get('provides', [])) old.remove(action) break if not old: break if old: raise ValueError('Cant solve') action_map = dict(self) self[:] = [(action, action_map[action]) for action in new]
def test_option_doc_nonascii_ticket4179(self): option = Option('iniadmin-test', 'name', '', doc='résumé') template, data = self.iniadmin.render_admin_panel( self.req, 'tracini', 'iniadmin-test', '') self.assertTrue(all(type(opt['doc']) is unicode for opt in data['iniadmin']['options'] if opt['name'] == 'name'))
def test_option_doc_nonascii_ticket4179(self): option = Option('iniadmin-test', 'name', '', doc='résumé') template, data = self.iniadmin.render_admin_panel( self.req, 'tracini', 'iniadmin-test', '') self.assertTrue( all( type(opt['doc']) is unicode for opt in data['iniadmin']['options'] if opt['name'] == 'name'))
def __call__(self, stream): """Apply the transform filter to the marked stream. :param stream: The marked event stream to filter """ found_first_th = False if self.data['xhr']: in_dirlist = True # XHR rows are only the interesting table else: in_dirlist = False in_repoindex = in_name_td = False idx = 0 rows_seen = 0 for kind, data, pos in stream: if kind == START: if all((data[0] == QName("http://www.w3.org/1999/xhtml}table"), data[1].get('id') == 'dirlist', self.data['dir'])): in_dirlist = True in_repoindex = data[1].get('id') == 'repoindex' if all((in_dirlist, not found_first_th, data[0] == QName("http://www.w3.org/1999/xhtml}th"))): for event in _ensure(tag.th(Markup(' '))): yield event found_first_th = True yield kind, data, pos continue if in_dirlist and data[0] == QName("http://www.w3.org/1999/xhtml}td"): rows_seen = rows_seen + 1 if rows_seen == 1 and ('up' in self.data['chrome']['links'] or \ (self.data['dir'] and not self.data['dir']['entries'])): data = data[0], data[1] - 'colspan' | [(QName('colspan'), '7')] yield kind, data, pos continue # don't mess with the "parent link" and "No files found" row if data[1].get('class') == 'name': # would be nice to get this static for any particular # item. We can't use a simple offset count due # to the XHR requests uid = uuid.uuid4() for event in _ensure(tag.td(tag.input(type='checkbox', id="cb-%s" % uid, class_='fileselect'))): yield event in_name_td = True elif in_dirlist and kind == END and data == QName("http://www.w3.org/1999/xhtml}table"): # we're leaving the current table; reset markers in_dirlist = False rows_seen = 0 found_first_th = False idx = 0 elif in_name_td and kind == END: if data == QName("http://www.w3.org/1999/xhtml}td"): in_name_td = False elif data == QName("http://www.w3.org/1999/xhtml}a"): yield kind, data, pos if idx == 0 and in_repoindex: # Don't yield a context menu for the repos since they don't have a dir entry continue entry = self.data['dir']['entries'][idx] menu = tag.div(tag.a(class_="ctx-expander fa fa-angle-down"), tag.div( tag.ul(tag.li(tag.span("%s (version %d)" % (entry.name, entry.rev), class_="plain-text")), class_="styled-dropdown"), class_="bottom-fix" ), id="ctx-%s" % uid, class_="inline-block margin-left-small dropdown-toggle") for provider in sorted(self.context_menu_providers, key=lambda x: x.get_order(self.req)): content = provider.get_content(self.req, entry, self.data) if content: menu.children[1].children[0].append(tag.li(content)) if len(menu.children[1].children[0].children) > 1: for event in _ensure(menu): yield event idx = idx + 1 continue yield kind, data, pos
def __init__(self): db = self.env.get_db_cnx() try: self._fetch_tkt_tags(db) db.commit() except get_db_exc(self.env).IntegrityError, e: self.log.warn('tags for ticket already exist: %s', to_unicode(e)) db.rollback() except: db.rollback() raise cfg = self.config cfg_key = 'permission_policies' default_policies = cfg.defaults().get('trac', {}).get(cfg_key) self.fast_permcheck = all(p in default_policies for p in cfg.get('trac', cfg_key)) def _check_permission(self, req, resource, action): """Optionally coarse-grained permission check.""" if self.fast_permcheck or not (resource and resource.id): perm = req.perm('ticket') else: perm = req.perm(resource) return self.check_permission(perm, action) and \ self.map[action] in perm def get_tagged_resources(self, req, tags=None, filter=None): if not self._check_permission(req, None, 'view'): return if not tags: