当前位置: 首页>>代码示例>>Python>>正文


Python PermissionSystem.grant_permission方法代码示例

本文整理汇总了Python中trac.perm.PermissionSystem.grant_permission方法的典型用法代码示例。如果您正苦于以下问题:Python PermissionSystem.grant_permission方法的具体用法?Python PermissionSystem.grant_permission怎么用?Python PermissionSystem.grant_permission使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在trac.perm.PermissionSystem的用法示例。


在下文中一共展示了PermissionSystem.grant_permission方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: create_user_and_grant_permissions

# 需要导入模块: from trac.perm import PermissionSystem [as 别名]
# 或者: from trac.perm.PermissionSystem import grant_permission [as 别名]
 def create_user_and_grant_permissions(self, req, team_member):
     if self.use_account_manager_integration(team_member.name):
         password = team_member.name
         AccountManager(self.env).set_password(team_member.name, password)
     permission_system = PermissionSystem(self.env)
     if not permission_system.check_permission(Role.TEAM_MEMBER, team_member.name):
         permission_system.grant_permission(team_member.name, Role.TEAM_MEMBER)
开发者ID:djangsters,项目名称:agilo,代码行数:9,代码来源:admin.py

示例2: _BaseTestCase

# 需要导入模块: from trac.perm import PermissionSystem [as 别名]
# 或者: from trac.perm.PermissionSystem import grant_permission [as 别名]
class _BaseTestCase(unittest.TestCase):
    def setUp(self):
        self.env = EnvironmentStub(enable=[
            'trac.*', 'acct_mgr.api.*', 'acct_mgr.admin.*',
            'acct_mgr.db.*', 'acct_mgr.register.*',
            'acct_mgr.pwhash.HtDigestHashMethod',
            'acct_mgr.tests.admin.BadCheck',
            'acct_mgr.tests.admin.DummyCheck'
        ])
        self.env.path = tempfile.mkdtemp()
        self.perm = PermissionSystem(self.env)

        # Create a user reference in the permission system.
        self.perm.grant_permission('admin', 'ACCTMGR_ADMIN')
        # Prepare a generic request object for admin actions.
        self.req = Mock(authname='admin', method='GET',
                        args=dict(), abs_href=self.env.abs_href,
                        chrome=dict(notices=[], warnings=[]),
                        href=self.env.abs_href, locale='',
                        redirect=lambda x: None, session=dict(), tz=''
                        )
        self.req.perm = PermissionCache(self.env, 'admin')

        self.acctmgr = AccountManager(self.env)

    def tearDown(self):
        shutil.rmtree(self.env.path)
开发者ID:t-kenji,项目名称:trac-account-manager-plugin,代码行数:29,代码来源:admin.py

示例3: import_perms

# 需要导入模块: from trac.perm import PermissionSystem [as 别名]
# 或者: from trac.perm.PermissionSystem import grant_permission [as 别名]
    def import_perms(self, template_path):
        """Creates permissions from data stored in groups.xml.

        Parses this XML file to get the data we need to insert into the 
        permissions table. If we have this data we clear the existing
        permission data, and then insert the template data using the 
        PermissionSystem API.

        If we don't create a perm_data list, we exit the function and 
        continue to use default data.
        """

        # parse the tree to get username, action data
        # we know the file exists as we check that in import_groups()
        tree = ET.ElementTree(file=template_path)
        perm_data = [(subelement.attrib['name'], subelement.attrib['action']) 
                     for perm in tree.getroot() for subelement in perm
                     if subelement.attrib['name'].strip()]

        @self.env.with_transaction()
        def clear_perms(db):
            """Clears the whole permissions table of default data."""

            cursor = db.cursor()
            self.log.info("Clearing permissions table")
            # cant pass the table name as an arg so its hard coded
            cursor.execute("DELETE FROM permission")

        self.log.info("Inserting template data into permissions table")
        perm_system = PermissionSystem(self.env).store
        for username, action in perm_data:
            perm_system.grant_permission(username, action)
开发者ID:CGI-define-and-primeportal,项目名称:trac-plugin-createtemplate,代码行数:34,代码来源:importer.py

示例4: add_permissions

# 需要导入模块: from trac.perm import PermissionSystem [as 别名]
# 或者: from trac.perm.PermissionSystem import grant_permission [as 别名]
 def add_permissions(self, permissions):
     perm = PermissionSystem(self.env)
     for agent, p in permissions.items():
         for permission in p:
             try:
                 perm.grant_permission(agent, permission)
             except:
                 continue
开发者ID:nyuhuhuu,项目名称:trachacks,代码行数:10,代码来源:admin.py

示例5: ResetActionTestCase

# 需要导入模块: from trac.perm import PermissionSystem [as 别名]
# 或者: from trac.perm.PermissionSystem import grant_permission [as 别名]
class ResetActionTestCase(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.req1 = Mock(authname='user1', args={},
                         perm=PermissionCache(self.env, 'user1'))
        self.req2 = Mock(authname='user2', args={},
                         perm=PermissionCache(self.env, 'user2'))
        self.ticket = Ticket(self.env)
        self.ticket['status'] = 'invalid'
        self.ticket.insert()

    def tearDown(self):
        self.env.reset_db()

    def _reload_workflow(self):
        self.ctlr.actions = self.ctlr.get_all_actions()

    def test_default_reset_action(self):
        """Default reset action."""
        self.perm_sys.grant_permission('user2', 'TICKET_ADMIN')
        self._reload_workflow()

        actions1 = self.ctlr.get_ticket_actions(self.req1, self.ticket)
        actions2 = self.ctlr.get_ticket_actions(self.req2, self.ticket)
        chgs2 = self.ctlr.get_ticket_changes(self.req2, self.ticket, '_reset')

        self.assertEqual(1, len(actions1))
        self.assertNotIn((0, '_reset'), actions1)
        self.assertEqual(2, len(actions2))
        self.assertIn((0, '_reset'), actions2)
        self.assertEqual('new', chgs2['status'])

    def test_custom_reset_action(self):
        """Custom reset action in [ticket-workflow] section."""
        config = self.env.config['ticket-workflow']
        config.set('_reset', '-> review')
        config.set('_reset.operations', 'reset_workflow')
        config.set('_reset.permissions', 'TICKET_BATCH_MODIFY')
        config.set('_reset.default', 2)
        self.perm_sys.grant_permission('user2', 'TICKET_BATCH_MODIFY')
        self._reload_workflow()

        actions1 = self.ctlr.get_ticket_actions(self.req1, self.ticket)
        actions2 = self.ctlr.get_ticket_actions(self.req2, self.ticket)
        chgs2 = self.ctlr.get_ticket_changes(self.req2, self.ticket, '_reset')

        self.assertEqual(1, len(actions1))
        self.assertNotIn((2, '_reset'), actions1)
        self.assertEqual(2, len(actions2))
        self.assertIn((2, '_reset'), actions2)
        self.assertEqual('review', chgs2['status'])
开发者ID:pkdevbox,项目名称:trac,代码行数:56,代码来源:default_workflow.py

示例6: ProductTicketSystemTestCase

# 需要导入模块: from trac.perm import PermissionSystem [as 别名]
# 或者: from trac.perm.PermissionSystem import grant_permission [as 别名]
class ProductTicketSystemTestCase(TicketSystemTestCase, MultiproductTestCase):

    def setUp(self):
        self.global_env = self._setup_test_env(create_folder=False)
        self._upgrade_mp(self.global_env)
        self._setup_test_log(self.global_env)
        self._load_product_from_data(self.global_env, self.default_product)
        self.env = ProductEnvironment(self.global_env, self.default_product)

        self.perm = PermissionSystem(self.env)
        self.ticket_system = TicketSystem(self.env)
        self.req = Mock()

    def tearDown(self):
        self.global_env.reset_db()

    def test_custom_field_isolation(self):
        self.env.config.set('ticket-custom', 'test', 'select')
        self.env.config.set('ticket-custom', 'test.label', 'Test')
        self.env.config.set('ticket-custom', 'test.value', '1')
        self.env.config.set('ticket-custom', 'test.options', 'option1|option2')

        self.global_env.config.set('ticket-custom', 'test', 'text')
        self.global_env.config.set('ticket-custom', 'test.label', 'Test')
        self.global_env.config.set('ticket-custom', 'test.value', 'Foo bar')
        self.global_env.config.set('ticket-custom', 'test.format', 'wiki')

        product_fields = TicketSystem(self.env).get_custom_fields()
        global_fields = TicketSystem(self.global_env).get_custom_fields()

        self.assertEqual({'name': 'test', 'type': 'select', 'label': 'Test',
                          'value': '1', 'options': ['option1', 'option2'],
                          'order': 0},
                         product_fields[0])
        self.assertEqual({'name': 'test', 'type': 'text', 'label': 'Test',
                          'value': 'Foo bar', 'order': 0, 'format': 'wiki'},
                         global_fields[0])

    def test_available_actions_isolation(self):
        # Grant TICKET_CREATE in product environment ...
        self.perm.grant_permission('anonymous', 'TICKET_CREATE')
        self.req.perm = PermissionCache(self.env)
        self.assertEqual(['leave', 'reopen'],
                         self._get_actions({'status': 'closed'}))

        # ... but no perms in global environment
        self.req.perm = PermissionCache(self.global_env)
        product_env = self.env
        try:
            self.env = self.global_env
            self.assertEqual(['leave'], self._get_actions({'status': 'closed'}))
        finally:
            self.env = product_env
开发者ID:thimalk,项目名称:bloodhound,代码行数:55,代码来源:api.py

示例7: test_tag_query_save

# 需要导入模块: from trac.perm import PermissionSystem [as 别名]
# 或者: from trac.perm.PermissionSystem import grant_permission [as 别名]
    def test_tag_query_save(self):
        """Save timeline tag query string in session."""
        self.assertEqual('tag_query', self.tef.key)

        from trac.timeline.web_ui import TimelineModule
        TimelineModule(self.env)
        perms = PermissionSystem(self.env)
        perms.grant_permission('anonymous', 'TAGS_VIEW')
        perms.grant_permission('anonymous', 'TIMELINE_VIEW')

        req = self._create_request(args=dict(tag_query='query_str'),
                                   path_info='/timeline', method='GET')
        dispatcher = RequestDispatcher(self.env)
        self.assertRaises(RequestDone, dispatcher.dispatch, req)
        self.assertEqual('query_str', req.session['timeline.tag_query'])
开发者ID:kzhamaji,项目名称:TracTagsPlugin,代码行数:17,代码来源:web_ui.py

示例8: _BaseTestCase

# 需要导入模块: from trac.perm import PermissionSystem [as 别名]
# 或者: from trac.perm.PermissionSystem import grant_permission [as 别名]
class _BaseTestCase(unittest.TestCase):
    def setUp(self):
        self.env = EnvironmentStub(
                enable=['trac.*', 'acct_mgr.api.*'])
        self.env.path = tempfile.mkdtemp()
        self.perm = PermissionSystem(self.env)

        # Create a user reference in the permission system.
        self.perm.grant_permission('admin', 'ACCTMGR_USER_ADMIN')
        # Prepare a generic registration request.
        args = dict(username='', name='', email='')
        self.req = Mock(authname='anonymous', args=args)
        self.req.perm = PermissionCache(self.env)

    def tearDown(self):
        shutil.rmtree(self.env.path)
开发者ID:51reboot,项目名称:huangweiyi,代码行数:18,代码来源:register.py

示例9: setUp

# 需要导入模块: from trac.perm import PermissionSystem [as 别名]
# 或者: from trac.perm.PermissionSystem import grant_permission [as 别名]
    def setUp(self):
        BaseProductAdminPanelTestCase.setUp(self)
        self.global_env.config.set('multiproduct', 'admin_blacklist',
                                   'testcat1:panel1,testcat3:panel2')
        self.env.config.set('multiproduct', 'admin_blacklist',
                            'testcat1:panel3,testcat3:panel1,testcat2:*')
        global_permsys = PermissionSystem(self.global_env)
        permsys = PermissionSystem(self.env)

        global_permsys.grant_permission('adminuser', 'TRAC_ADMIN')
        global_permsys.grant_permission('prodadmin', 'PRODUCT_ADMIN')
        global_permsys.grant_permission('testuser', 'TEST_ADMIN')
        permsys.grant_permission('prodadmin', 'PRODUCT_ADMIN')
        permsys.grant_permission('testuser', 'TEST_ADMIN')

        self.req = self._get_request_obj()
开发者ID:thimalk,项目名称:bloodhound,代码行数:18,代码来源:product_admin.py

示例10: VoteSystemTestCase

# 需要导入模块: from trac.perm import PermissionSystem [as 别名]
# 或者: from trac.perm.PermissionSystem import grant_permission [as 别名]
class VoteSystemTestCase(unittest.TestCase):

    def setUp(self):
        self.env = EnvironmentStub(default_data=True,
                                   enable=['trac.*', 'tracvote.*'])
        self.env.path = tempfile.mkdtemp()
        self.perm = PermissionSystem(self.env)
        self.req = Mock()

        self.db = self.env.get_db_cnx()
        self.votes = VoteSystem(self.env)
        # Current tracvotes schema is setup with enabled component anyway.
        #   Revert these changes for getting default permissions inserted.
        self._revert_schema_init()
        self.votes.upgrade_environment(self.db)

    def tearDown(self):
        self.db.close()
        # Really close db connections.
        self.env.shutdown()
        shutil.rmtree(self.env.path)

    # Helpers

    def _revert_schema_init(self):
        cursor = self.db.cursor()
        cursor.execute("DROP TABLE IF EXISTS votes")
        cursor.execute("DELETE FROM system WHERE name='vote_version'")
        cursor.execute("DELETE FROM permission WHERE action %s"
                       % self.db.like(), ('VOTE_%',))

    # Tests

    def test_available_actions_no_perms(self):
        self.assertTrue(_ACTIONS['view'] in PermissionCache(self.env))
        self.assertFalse(_ACTIONS['modify'] in PermissionCache(self.env))

    def test_available_actions_full_perms(self):
        perm_map = dict(voter='VOTE_MODIFY', admin='TRAC_ADMIN')
        for user in perm_map:
            self.perm.grant_permission(user, perm_map[user])
            for action in _ACTIONS.values():
                self.assertTrue(action in PermissionCache(self.env,
                                                          username=user))

    def test_resource_provider(self):
        self.assertTrue(self.votes in Chrome(self.env).template_providers)
开发者ID:nyuhuhuu,项目名称:trachacks,代码行数:49,代码来源:main.py

示例11: test_save_page_with_valid_patterns

# 需要导入模块: from trac.perm import PermissionSystem [as 别名]
# 或者: from trac.perm.PermissionSystem import grant_permission [as 别名]
    def test_save_page_with_valid_patterns(self):
        """Page with valid patterns can be saved."""
        perm = PermissionSystem(self.env)
        perm.grant_permission('user', 'authenticated')
        text = """{{{
        (?i)eventbrite\.com
        (?i)sneaker(?:supplier|nice)\.com
        }}}"""
        req = MockRequest(self.env, authname='user', args={
            'action': 'edit',
            'text': text,
            'version': 0,
        }, method='POST', path_info='/wiki/BadContent')

        self._dispatch_request(req)

        self.assertIn('Your changes have been saved in version 1',
                      unicode(req.chrome['notices']))
开发者ID:Puppet-Finland,项目名称:trac,代码行数:20,代码来源:regex.py

示例12: test_save_page_with_invalid_pattern

# 需要导入模块: from trac.perm import PermissionSystem [as 别名]
# 或者: from trac.perm.PermissionSystem import grant_permission [as 别名]
    def test_save_page_with_invalid_pattern(self):
        """Page cannot be saved with an invalid pattern."""
        perm = PermissionSystem(self.env)
        perm.grant_permission('user', 'authenticated')
        text = """{{{
        (?i)eventbrite\.com
        (?i)sneaker(?:supplier|nice\.com
        }}}"""
        req = MockRequest(self.env, authname='user', args={
            'action': 'edit',
            'text': text,
            'version': 0,
        }, method='POST', path_info='/wiki/BadContent')

        self._dispatch_request(req)

        self.assertIn('Invalid Wiki page: Error in pattern '
                      '<tt>(?i)sneaker(?:supplier|nice\\.com</tt>: '
                      '<i>unbalanced parenthesis</i>.',
                      req.chrome['warnings'])
开发者ID:Puppet-Finland,项目名称:trac,代码行数:22,代码来源:regex.py

示例13: OpenPgpFactoryTestCase

# 需要导入模块: from trac.perm import PermissionSystem [as 别名]
# 或者: from trac.perm.PermissionSystem import grant_permission [as 别名]
class OpenPgpFactoryTestCase(unittest.TestCase):

    def setUp(self):
        self.env = EnvironmentStub(enable=['trac.*', 'crypto.*'])
        self.env.path = tempfile.mkdtemp()

        self.perm = PermissionSystem(self.env)
        self.req = Mock()

        self.base = CryptoBase(self.env)
        self.factory = OpenPgpFactory(self.env)

    def tearDown(self):
        shutil.rmtree(self.env.path)

    def test_openpgp_create_key(self):
        factory = self.factory
        self.assertEqual(factory.keys(), [])
        self.assertEqual(factory.keys(private=True), [])
        key = factory.create_key(name_real='John', name_email='[email protected]')
        fp = key.fingerprint
        # Check for both, private and public key.
        self.assertEqual(factory.keys(id_only=True), [fp])
        self.assertEqual(factory.keys(True, True), [fp])

    def test_openpgp_delete_key_no_perms(self):
        factory = self.factory
        key = factory.create_key()
        self.req.perm = PermissionCache(self.env)
        self.assertRaises(PermissionError, factory.delete_key,
                          key.fingerprint, self.req.perm)

    def test_openpgp_delete_key_full_perms(self):
        factory = self.factory
        key = factory.create_key()
        self.perm.grant_permission('anonymous', 'CRYPTO_DELETE')
        self.req.perm = PermissionCache(self.env)
        # Shouldn't raise an error with appropriate permission.
        factory.delete_key(key.fingerprint, self.req.perm)
        self.assertEqual(factory.keys(), [])
        self.assertEqual(factory.keys(private=True), [])
开发者ID:nyuhuhuu,项目名称:trachacks,代码行数:43,代码来源:openpgp.py

示例14: CryptoAdminPanelTestCase

# 需要导入模块: from trac.perm import PermissionSystem [as 别名]
# 或者: from trac.perm.PermissionSystem import grant_permission [as 别名]
class CryptoAdminPanelTestCase(unittest.TestCase):

    def setUp(self):
        self.env = EnvironmentStub(enable=['trac.*', 'crypto.*'])
        self.env.path = tempfile.mkdtemp()
        self.perm = PermissionSystem(self.env)
        self.req = Mock()

        self.crypto_ap = CryptoAdminPanel(self.env)

    def tearDown(self):
        shutil.rmtree(self.env.path)

    def test_available_actions(self):
        self.failIf('CRYPTO_ADMIN' not in self.perm.get_actions())
        self.failIf('CRYPTO_DELETE' not in self.perm.get_actions())

    def test_available_actions_no_perms(self):
        self.perm.grant_permission('admin', 'authenticated')
        self.assertFalse(self.perm.check_permission('CRYPTO_ADMIN', 'admin'))
        self.assertFalse(self.perm.check_permission('CRYPTO_DELETE', 'admin'))

    def test_available_actions_delete_only(self):
        self.perm.grant_permission('admin', 'CRYPTO_DELETE')
        self.assertFalse(self.perm.check_permission('CRYPTO_ADMIN', 'admin'))
        self.assertTrue(self.perm.check_permission('CRYPTO_DELETE', 'admin'))

    def test_available_actions_full_perms(self):
        self.perm.grant_permission('admin', 'TRAC_ADMIN')
        self.assertTrue(self.perm.check_permission('CRYPTO_ADMIN', 'admin'))
        self.assertTrue(self.perm.check_permission('CRYPTO_DELETE', 'admin'))
开发者ID:nyuhuhuu,项目名称:trachacks,代码行数:33,代码来源:admin.py

示例15: setUp

# 需要导入模块: from trac.perm import PermissionSystem [as 别名]
# 或者: from trac.perm.PermissionSystem import grant_permission [as 别名]
    def setUp(self):
        self.env = EnvironmentStub(
                enable=['trac.*', 'tractags.*'])
        self.env.path = tempfile.mkdtemp()

        self.tag_s = TagSystem(self.env)
        self.tag_rh = TagRequestHandler(self.env)

        self.db = self.env.get_db_cnx()
        setup = TagSetup(self.env)
        # Current tractags schema is setup with enabled component anyway.
        #   Revert these changes for getting a clean setup.
        self._revert_tractags_schema_init()
        setup.upgrade_environment(self.db)

        perms = PermissionSystem(self.env)
        # Revoke default permissions, because more diversity is required here.
        perms.revoke_permission('anonymous', 'TAGS_VIEW')
        perms.revoke_permission('authenticated', 'TAGS_MODIFY')
        perms.grant_permission('reader', 'TAGS_VIEW')
        perms.grant_permission('writer', 'TAGS_MODIFY')
        perms.grant_permission('admin', 'TAGS_ADMIN')
        self.anonymous = PermissionCache(self.env)
        self.reader = PermissionCache(self.env, 'reader')
        self.writer = PermissionCache(self.env, 'writer')
        self.admin = PermissionCache(self.env, 'admin')

        self.href = Href('/trac')
        self.abs_href = Href('http://example.org/trac')
开发者ID:nyuhuhuu,项目名称:trachacks,代码行数:31,代码来源:web_ui.py


注:本文中的trac.perm.PermissionSystem.grant_permission方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。