本文整理汇总了Python中trac.ticket.api.TicketSystem.render_ticket_action_control方法的典型用法代码示例。如果您正苦于以下问题:Python TicketSystem.render_ticket_action_control方法的具体用法?Python TicketSystem.render_ticket_action_control怎么用?Python TicketSystem.render_ticket_action_control使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类trac.ticket.api.TicketSystem
的用法示例。
在下文中一共展示了TicketSystem.render_ticket_action_control方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: RestrictOwnerTestCase
# 需要导入模块: from trac.ticket.api import TicketSystem [as 别名]
# 或者: from trac.ticket.api.TicketSystem import render_ticket_action_control [as 别名]
class RestrictOwnerTestCase(unittest.TestCase):
def setUp(self):
tmpdir = os.path.realpath(tempfile.gettempdir())
self.env = EnvironmentStub(enable=['trac.*', AuthzPolicy], path=tmpdir)
self.env.config.set('trac', 'permission_policies',
'AuthzPolicy, DefaultPermissionPolicy')
self.env.config.set('ticket', 'restrict_owner', True)
self.perm_sys = PermissionSystem(self.env)
self.env.insert_known_users([
('user1', '', ''), ('user2', '', ''),
('user3', '', ''), ('user4', '', '')
])
self.perm_sys.grant_permission('user1', 'TICKET_MODIFY')
self.perm_sys.grant_permission('user2', 'TICKET_VIEW')
self.perm_sys.grant_permission('user3', 'TICKET_MODIFY')
self.perm_sys.grant_permission('user4', 'TICKET_MODIFY')
self.authz_file = os.path.join(tmpdir, 'trac-authz-policy')
create_file(self.authz_file)
self.env.config.set('authz_policy', 'authz_file', self.authz_file)
self.ctlr = TicketSystem(self.env).action_controllers[0]
self.req1 = Mock(authname='user1', args={},
perm=PermissionCache(self.env, 'user1'))
self.ticket = Ticket(self.env)
self.ticket['status'] = 'new'
self.ticket.insert()
def tearDown(self):
self.env.reset_db()
os.remove(self.authz_file)
def _reload_workflow(self):
self.ctlr.actions = self.ctlr.get_all_actions()
def test_set_owner(self):
"""Restricted owners list contains users with TICKET_MODIFY.
"""
ctrl = self.ctlr.render_ticket_action_control(self.req1, self.ticket,
'reassign')
self.assertEqual('reassign', ctrl[0])
self.assertIn('value="user1">user1</option>', str(ctrl[1]))
self.assertNotIn('value="user2">user2</option>', str(ctrl[1]))
self.assertIn('value="user3">user3</option>', str(ctrl[1]))
self.assertIn('value="user4">user4</option>', str(ctrl[1]))
def test_set_owner_fine_grained_permissions(self):
"""Fine-grained permission checks when populating the restricted
owners list (#10833).
"""
create_file(self.authz_file, """\
[ticket:1]
user4 = !TICKET_MODIFY
""")
ctrl = self.ctlr.render_ticket_action_control(self.req1, self.ticket,
'reassign')
self.assertEqual('reassign', ctrl[0])
self.assertIn('value="user1">user1</option>', str(ctrl[1]))
self.assertNotIn('value="user2">user2</option>', str(ctrl[1]))
self.assertIn('value="user3">user3</option>', str(ctrl[1]))
self.assertNotIn('value="user4">user4</option>', str(ctrl[1]))
示例2: SetOwnerAttributeTestCase
# 需要导入模块: from trac.ticket.api import TicketSystem [as 别名]
# 或者: from trac.ticket.api.TicketSystem import render_ticket_action_control [as 别名]
class SetOwnerAttributeTestCase(unittest.TestCase):
def setUp(self):
self.env = EnvironmentStub(default_data=True)
self.perm_sys = PermissionSystem(self.env)
self.ctlr = TicketSystem(self.env).action_controllers[0]
self.ticket = Ticket(self.env)
self.ticket['status'] = 'new'
self.ticket.insert()
with self.env.db_transaction as db:
for user in ('user1', 'user2', 'user3', 'user4'):
db("INSERT INTO session VALUES (%s, %s, %s)", (user, 1, 0))
permissions = [
('user1', 'TICKET_EDIT_CC'),
('user2', 'TICKET_EDIT_CC'),
('user2', 'TICKET_BATCH_MODIFY'),
('user3', 'TICKET_ADMIN'),
('user4', 'TICKET_VIEW'),
('user1', 'group1'),
('user2', 'group1'),
('user2', 'group2'),
('user3', 'group2'),
('user4', 'group3')
]
for perm in permissions:
self.perm_sys.grant_permission(*perm)
self.req = Mock(authname='user1', args={},
perm=PermissionCache(self.env, 'user0'))
self.expected = """\
to <select name="action_reassign_reassign_owner" \
id="action_reassign_reassign_owner"><option selected="True" \
value="user1">user1</option><option value="user2">user2</option>\
<option value="user3">user3</option></select>"""
def _reload_workflow(self):
self.ctlr.actions = self.ctlr.get_all_actions()
def tearDown(self):
self.env.reset_db()
def test_users(self):
self.env.config.set('ticket-workflow', 'reassign.set_owner',
'user1, user2, user3')
self._reload_workflow()
args = self.req, self.ticket, 'reassign'
label, control, hints = self.ctlr.render_ticket_action_control(*args)
self.assertEqual(self.expected, str(control))
def test_groups(self):
self.env.config.set('ticket-workflow', 'reassign.set_owner',
'group1, group2')
self._reload_workflow()
args = self.req, self.ticket, 'reassign'
label, control, hints = self.ctlr.render_ticket_action_control(*args)
self.assertEqual(self.expected, str(control))
def test_permission(self):
self.env.config.set('ticket-workflow', 'reassign.set_owner',
'TICKET_EDIT_CC, TICKET_BATCH_MODIFY')
self._reload_workflow()
args = self.req, self.ticket, 'reassign'
label, control, hints = self.ctlr.render_ticket_action_control(*args)
self.assertEqual(self.expected, str(control))