def process_request(self, req): if req.args.has_key('batchmod'): req.perm.assert_permission('TICKET_BATCH_MODIFY') self._batch_modify(req) QueryModule(self.env).process_request(req) self._add_ticket_fields(req) return 'batchmod.cs', None
def test_csv_escape(self): query = Mock(get_columns=lambda: ['col1'], execute=lambda r: [{'id': 1, 'col1': 'value, needs escaped'}], time_fields=['time', 'changetime']) content, mimetype = QueryModule(self.env).export_csv( Mock(href=self.env.href, perm=MockPerm()), query) self.assertEqual('\xef\xbb\xbfcol1\r\n"value, needs escaped"\r\n', content)
def test_csv_obfuscation(self): class NoEmailView(MockPerm): def has_permission(self, action, realm_or_resource=None, id=False, version=False): return action != 'EMAIL_VIEW' __contains__ = has_permission query = Mock(get_columns=lambda: ['owner', 'reporter', 'cc'], execute=lambda r: [{ 'id': 1, 'owner': '*****@*****.**', 'reporter': '*****@*****.**', 'cc': '[email protected], cc2' }], time_fields=['time', 'changetime']) req = Mock(href=self.env.href, perm=NoEmailView()) content, mimetype = QueryModule(self.env).export_csv(req, query) self.assertEqual( u'\uFEFFowner,reporter,cc\r\n' u'joe@…,foo@…,"cc1@…, cc2"\r\n', content.decode('utf-8')) req = Mock(href=self.env.href, perm=MockPerm()) content, mimetype = QueryModule(self.env).export_csv(req, query) self.assertEqual( u'\uFEFFowner,reporter,cc\r\n' u'[email protected],[email protected],"[email protected], cc2"\r\n', content.decode('utf-8'))
class QueryLinksTestCase(unittest.TestCase): def setUp(self): self.env = EnvironmentStub(default_data=True) self.query_module = QueryModule(self.env) self.formatter = LinkFormatter(self.env) def _format_link(self, query, label): return str(self.query_module._format_link(self.formatter, 'query', query, label)) def test_empty_query(self): self.assertEqual(self._format_link('', 'label'), '<em class="error">[Error: Query filter requires ' 'field and constraints separated by a "="]</em>')
def get_ticket_list(self, request): # Some data (which report is being used, sorting, verbosity...) is # pulled directly from request.GET. query_module = QueryModule(self.env) req = FakeTracRequest(request) constraints = query_module._get_constraints(req) qd = request.GET kwargs = { 'cols': qd.getlist('col'), 'rows': qd.getlist('row'), 'constraints': constraints } kwargs.update(dict([ (k, qd.get(k)) for k in ('format', 'max', 'report', 'order', 'group', 'page') ])) kwargs.update(dict([ (k, k in qd) for k in 'desc', 'groupdesc', 'verbose' ]))
def setUp(self): self.report_module = ReportModule(self.env) self.query_module = QueryModule(self.env) self.chrome_module = Chrome(self.env) self.perm_sys = PermissionSystem(self.env) if self.env.is_component_enabled(ReportModule): self.perm_sys.grant_permission('has_report_view', 'REPORT_VIEW') self.perm_sys.grant_permission('has_both', 'REPORT_VIEW') self.perm_sys.grant_permission('has_ticket_view', 'TICKET_VIEW') self.perm_sys.grant_permission('has_both', 'TICKET_VIEW') self.tickets_link = lambda href: '<a href="%s">View Tickets</a>' \ % href
class QueryLinksTestCase(unittest.TestCase): def setUp(self): self.env = EnvironmentStub(default_data=True) self.query_module = QueryModule(self.env) self.formatter = LinkFormatter(self.env) def _format_link(self, query, label): return str( self.query_module._format_link(self.formatter, 'query', query, label)) def test_empty_query(self): self.assertEqual( self._format_link('', 'label'), '<em class="error">[Error: Query filter requires ' 'field and constraints separated by a "="]</em>')
class QueryLinksTestCase(unittest.TestCase): def setUp(self): self.env = EnvironmentStub(default_data=True) self.query_module = QueryModule(self.env) req = Mock(perm=MockPerm(), args={}, href=Href("/")) self.formatter = LinkFormatter(self.env, web_context(req)) def tearDown(self): self.env.reset_db() def _format_link(self, query, label): return str(self.query_module._format_link(self.formatter, "query", query, label)) def test_empty_query(self): self.assertEqual( self._format_link("", "label"), '<em class="error">[Error: Query filter requires ' 'field and constraints separated by a "="]</em>', )
class QueryLinksTestCase(unittest.TestCase): def setUp(self): self.env = EnvironmentStub(default_data=True) self.query_module = QueryModule(self.env) req = Mock(perm=MockPerm(), args={}, href=Href('/')) self.formatter = LinkFormatter(self.env, web_context(req)) def tearDown(self): self.env.reset_db() def _format_link(self, query, label): return str(self.query_module._format_link(self.formatter, 'query', query, label)) def test_empty_query(self): self.assertEqual(self._format_link('', 'label'), '<em class="error">[Error: Query filter requires ' 'field and constraints separated by a "="]</em>')
def get_navigation_items(self, req): # Don't allow this to be exposed if 'DO_PRIVATETICKETS_FILTER' in req.args.keys(): del req.args['DO_PRIVATETICKETS_FILTER'] # Various ways to allow access if not req.perm.has_permission('TICKET_VIEW') and \ (req.perm.has_permission('TICKET_VIEW_REPORTER') or \ req.perm.has_permission('TICKET_VIEW_OWNER') or \ req.perm.has_permission('TICKET_VIEW_CC') or \ req.perm.has_permission('TICKET_VIEW_REPORTER_GROUP') or \ req.perm.has_permission('TICKET_VIEW_OWNER_GROUP') or \ req.perm.has_permission('TICKET_VIEW_CC_GROUP')): if TicketModule(self.env).match_request(req): if PrivateTicketsSystem(self.env).check_ticket_access( req, req.args['id']): self._grant_view(req) elif AttachmentModule(self.env).match_request(req): if req.args['type'] == 'ticket' and PrivateTicketsSystem( self.env).check_ticket_access( req, req.args['path'].split('/')[0]): self._grant_view(req) elif QueryModule(self.env).match_request(req): req.args['DO_PRIVATETICKETS_FILTER'] = 'query' self._grant_view(req) # Further filtering in query.py elif SearchModule(self.env).match_request(req): if 'ticket' in req.args.keys(): req.args['pticket'] = req.args['ticket'] del req.args['ticket'] elif ReportModule(self.env).match_request(req): self._grant_view(req) # So they can see the query page link if req.args.get('id'): req.args['DO_PRIVATETICKETS_FILTER'] = 'report' # NOTE: Send this back here because the button would be hidden otherwise. <NPK t:1129> if not self.env.is_component_enabled( ReportModule) or not req.perm.has_permission( 'REPORT_VIEW'): return [('mainnav', 'tickets', html.A('View Tickets', href=req.href.query()))] return []
def process_request(self, req): constraints = QueryModule(self.env)._get_constraints(req) if not constraints and not req.args.has_key('order'): # avoid displaying all tickets when the query module is invoked # with no parameters. Instead show only open tickets, possibly # associated with the user constraints = {'status': ('new', 'assigned', 'reopened')} if req.authname and req.authname != 'anonymous': constraints['owner'] = (req.authname,) else: email = req.session.get('email') name = req.session.get('name') if email or name: constraints['cc'] = ('~%s' % email or name,) query = Query(self.env, constraints, req.args.get('order'), req.args.has_key('desc'), req.args.get('group'), req.args.has_key('groupdesc'), req.args.has_key('verbose')) format = req.args.get('format') self.send_converted(req, 'trac.ticket.Query', query, format, 'query')
def setUp(self): self.env = EnvironmentStub(default_data=True) self.query_module = QueryModule(self.env) req = Mock(perm=MockPerm(), args={}, href=Href("/")) self.formatter = LinkFormatter(self.env, web_context(req))
def match_request(self, req): return QueryModule(self.env).match_request(req)
def __init__(self): QueryModule.__init__(self, self.compmgr)
def get_supported_conversions(self): return QueryModule(self.env).get_supported_conversions()
def setUp(self): self.env = EnvironmentStub(default_data=True) self.query_module = QueryModule(self.env) req = Mock(perm=MockPerm(), args={}, href=Href('/')) self.formatter = LinkFormatter(self.env, web_context(req))
def setUp(self): self.env = EnvironmentStub(default_data=True) self.query_module = QueryModule(self.env) self.formatter = LinkFormatter(self.env)
def convert_content(self, req, mimetype, query, key): return QueryModule(self.env).convert_content(req, mimetype, query, key)
def get_wiki_syntax(self): return QueryModule(self.env).get_wiki_syntax()
def process_request(self, req): args = req.args qm = QueryModule(self.env) template, data, _whatever = qm.process_request(req) return 'select_tickets.html', data, None
def get_active_navigation_item(self, req): return QueryModule(self.env).get_active_navigation_item(req)
def get_link_resolvers(self): return QueryModule(self.env).get_link_resolvers()
def get_constraints(self, arg_list=[]): return QueryModule(self.env)._get_constraints(self.req, arg_list)