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


Python sm.find_role函数代码示例

本文整理汇总了Python中superset.sm.find_role函数的典型用法代码示例。如果您正苦于以下问题:Python find_role函数的具体用法?Python find_role怎么用?Python find_role使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: test_clean_requests_after_alpha_grant

    def test_clean_requests_after_alpha_grant(self):
        session = db.session

        # Case 2. Two access requests from gamma and gamma2
        # Gamma becomes alpha, gamma2 gets granted
        # Check if request by gamma has been deleted

        access_request1 = create_access_request(
            session, 'table', 'birth_names', TEST_ROLE_1, 'gamma')
        create_access_request(
            session, 'table', 'birth_names', TEST_ROLE_2, 'gamma2')
        ds_1_id = access_request1.datasource_id
        # gamma becomes alpha
        alpha_role = sm.find_role('Alpha')
        gamma_user = sm.find_user(username='gamma')
        gamma_user.roles.append(alpha_role)
        session.commit()
        access_requests = self.get_access_requests('gamma', 'table', ds_1_id)
        self.assertTrue(access_requests)
        self.client.get(EXTEND_ROLE_REQUEST.format(
            'table', ds_1_id, 'gamma2', TEST_ROLE_2))
        access_requests = self.get_access_requests('gamma', 'table', ds_1_id)
        self.assertFalse(access_requests)

        gamma_user = sm.find_user(username='gamma')
        gamma_user.roles.remove(sm.find_role('Alpha'))
        session.commit()
开发者ID:johnsonc,项目名称:caravel,代码行数:27,代码来源:access_tests.py

示例2: test_clean_requests_after_db_grant

    def test_clean_requests_after_db_grant(self):
        session = db.session

        # Case 3. Two access requests from gamma and gamma2
        # Gamma gets database access, gamma2 access request granted
        # Check if request by gamma has been deleted

        gamma_user = sm.find_user(username='gamma')
        access_request1 = create_access_request(
            session, 'table', 'long_lat', TEST_ROLE_1, 'gamma')
        create_access_request(
            session, 'table', 'long_lat', TEST_ROLE_2, 'gamma2')
        ds_1_id = access_request1.datasource_id
        # gamma gets granted database access
        database = session.query(models.Database).first()

        security.merge_perm(
            sm, 'database_access', database.perm)
        ds_perm_view = sm.find_permission_view_menu(
            'database_access', database.perm)
        sm.add_permission_role(
            sm.find_role(DB_ACCESS_ROLE), ds_perm_view)
        gamma_user.roles.append(sm.find_role(DB_ACCESS_ROLE))
        session.commit()
        access_requests = self.get_access_requests('gamma', 'table', ds_1_id)
        self.assertTrue(access_requests)
        # gamma2 request gets fulfilled
        self.client.get(EXTEND_ROLE_REQUEST.format(
            'table', ds_1_id, 'gamma2', TEST_ROLE_2))
        access_requests = self.get_access_requests('gamma', 'table', ds_1_id)

        self.assertFalse(access_requests)
        gamma_user = sm.find_user(username='gamma')
        gamma_user.roles.remove(sm.find_role(DB_ACCESS_ROLE))
        session.commit()
开发者ID:johnsonc,项目名称:caravel,代码行数:35,代码来源:access_tests.py

示例3: test_update_role

    def test_update_role(self):
        update_role_str = 'update_me'
        sm.add_role(update_role_str)
        db.session.commit()
        resp = self.client.post(
            '/superset/update_role/',
            data=json.dumps({
                'user_emails': ['[email protected]'],
                'role_name': update_role_str
            }),
            follow_redirects=True
        )
        update_role = sm.find_role(update_role_str)
        self.assertEquals(
            update_role.user, [sm.find_user(email='[email protected]')])
        self.assertEquals(resp.status_code, 201)

        resp = self.client.post(
            '/superset/update_role/',
            data=json.dumps({
                'user_emails': ['[email protected]', '[email protected]'],
                'role_name': update_role_str
            }),
            follow_redirects=True
        )
        self.assertEquals(resp.status_code, 201)
        update_role = sm.find_role(update_role_str)
        self.assertEquals(
            update_role.user, [sm.find_user(email='[email protected]')])

        db.session.delete(update_role)
        db.session.commit()
开发者ID:the-dcruz,项目名称:caravel,代码行数:32,代码来源:access_tests.py

示例4: test_sql_json_has_access

    def test_sql_json_has_access(self):
        main_db = self.get_main_database(db.session)
        sm.add_permission_view_menu('database_access', main_db.perm)
        db.session.commit()
        main_db_permission_view = (
            db.session.query(ab_models.PermissionView)
            .join(ab_models.ViewMenu)
            .filter(ab_models.ViewMenu.name == '[main].(id:1)')
            .first()
        )
        astronaut = sm.add_role("Astronaut")
        sm.add_permission_role(astronaut, main_db_permission_view)
        # Astronaut role is Gamma + sqllab +  main db permissions
        for perm in sm.find_role('Gamma').permissions:
            sm.add_permission_role(astronaut, perm)
        for perm in sm.find_role('sql_lab').permissions:
            sm.add_permission_role(astronaut, perm)

        gagarin = appbuilder.sm.find_user('gagarin')
        if not gagarin:
            appbuilder.sm.add_user(
                'gagarin', 'Iurii', 'Gagarin', '[email protected]',
                astronaut,
                password='general')
        data = self.run_sql('SELECT * FROM ab_user', "3", user_name='gagarin')
        db.session.query(models.Query).delete()
        db.session.commit()
        self.assertLess(0, len(data['data']))
开发者ID:the-dcruz,项目名称:caravel,代码行数:28,代码来源:sqllab_tests.py

示例5: tearDownClass

 def tearDownClass(cls):
     override_me = sm.find_role('override_me')
     db.session.delete(override_me)
     db.session.delete(sm.find_role(TEST_ROLE_1))
     db.session.delete(sm.find_role(TEST_ROLE_2))
     db.session.delete(sm.find_role(DB_ACCESS_ROLE))
     db.session.delete(sm.find_role(SCHEMA_ACCESS_ROLE))
     db.session.commit()
开发者ID:johnsonc,项目名称:caravel,代码行数:8,代码来源:access_tests.py

示例6: test_update_role

    def test_update_role(self):
        update_role_str = 'update_me'
        sm.add_role(update_role_str)
        db.session.commit()
        resp = self.client.post(
            '/superset/update_role/',
            data=json.dumps({
                'users': [{
                        'username': 'gamma',
                        'first_name': 'Gamma',
                        'last_name': 'Gamma',
                        'email': '[email protected]'
                    }],
                'role_name': update_role_str
            }),
            follow_redirects=True
        )
        update_role = sm.find_role(update_role_str)
        self.assertEquals(
            update_role.user, [sm.find_user(username='gamma')])
        self.assertEquals(resp.status_code, 201)

        resp = self.client.post(
            '/superset/update_role/',
            data=json.dumps({
                'users': [{
                    'username': 'alpha',
                    'first_name': 'Alpha',
                    'last_name': 'Alpha',
                    'email': '[email protected]'
                }, {
                    'username': 'unknown',
                    'first_name': 'Unknown1',
                    'last_name': 'Unknown2',
                    'email': '[email protected]'
                }],
                'role_name': update_role_str
            }),
            follow_redirects=True
        )
        self.assertEquals(resp.status_code, 201)
        update_role = sm.find_role(update_role_str)
        self.assertEquals(
            update_role.user, [
                sm.find_user(username='alpha'),
                sm.find_user(username='unknown'),
            ])
        unknown = sm.find_user(username='unknown')
        self.assertEquals('Unknown2', unknown.last_name)
        self.assertEquals('Unknown1', unknown.first_name)
        self.assertEquals('[email protected]', unknown.email)
        db.session.delete(update_role)
        db.session.delete(unknown)
        db.session.commit()
开发者ID:aaronyangzju,项目名称:caravel,代码行数:54,代码来源:access_tests.py

示例7: test_filter_druid_datasource

    def test_filter_druid_datasource(self):
        CLUSTER_NAME = 'new_druid'
        cluster = self.get_or_create(
            DruidCluster,
            {'cluster_name': CLUSTER_NAME},
            db.session)
        db.session.merge(cluster)

        gamma_ds = self.get_or_create(
            DruidDatasource, {'datasource_name': 'datasource_for_gamma'},
            db.session)
        gamma_ds.cluster = cluster
        db.session.merge(gamma_ds)

        no_gamma_ds = self.get_or_create(
            DruidDatasource, {'datasource_name': 'datasource_not_for_gamma'},
            db.session)
        no_gamma_ds.cluster = cluster
        db.session.merge(no_gamma_ds)
        db.session.commit()

        security.merge_perm(sm, 'datasource_access', gamma_ds.perm)
        security.merge_perm(sm, 'datasource_access', no_gamma_ds.perm)

        perm = sm.find_permission_view_menu(
            'datasource_access', gamma_ds.get_perm())
        sm.add_permission_role(sm.find_role('Gamma'), perm)
        sm.get_session.commit()

        self.login(username='gamma')
        url = '/druiddatasourcemodelview/list/'
        resp = self.get_resp(url)
        self.assertIn('datasource_for_gamma', resp)
        self.assertNotIn('datasource_not_for_gamma', resp)
开发者ID:johnsonc,项目名称:caravel,代码行数:34,代码来源:druid_tests.py

示例8: test_clean_requests_after_role_extend

    def test_clean_requests_after_role_extend(self):
        session = db.session

        # Case 1. Gamma and gamma2 requested test_role1 on energy_usage access
        # Gamma already has role test_role1
        # Extend test_role1 with energy_usage access for gamma2
        # Check if access request for gamma at energy_usage was deleted

        # gamma2 and gamma request table_role on energy usage
        if app.config.get('ENABLE_ACCESS_REQUEST'):
            access_request1 = create_access_request(
                session, 'table', 'random_time_series', TEST_ROLE_1, 'gamma2')
            ds_1_id = access_request1.datasource_id
            create_access_request(
                session, 'table', 'random_time_series', TEST_ROLE_1, 'gamma')
            access_requests = self.get_access_requests('gamma', 'table', ds_1_id)
            self.assertTrue(access_requests)
            # gamma gets test_role1
            self.get_resp(GRANT_ROLE_REQUEST.format(
                'table', ds_1_id, 'gamma', TEST_ROLE_1))
            # extend test_role1 with access on energy usage
            self.client.get(EXTEND_ROLE_REQUEST.format(
                'table', ds_1_id, 'gamma2', TEST_ROLE_1))
            access_requests = self.get_access_requests('gamma', 'table', ds_1_id)
            self.assertFalse(access_requests)

            gamma_user = sm.find_user(username='gamma')
            gamma_user.roles.remove(sm.find_role('test_role1'))
开发者ID:johnsonc,项目名称:caravel,代码行数:28,代码来源:access_tests.py

示例9: assert_admin_view_menus_in

 def assert_admin_view_menus_in(role_name, assert_func):
     role = sm.find_role(role_name)
     view_menus = [p.view_menu.name for p in role.permissions]
     assert_func('ResetPasswordView', view_menus)
     assert_func('RoleModelView', view_menus)
     assert_func('Security', view_menus)
     assert_func('UserDBModelView', view_menus)
     assert_func('SQL Lab',
                 view_menus)
开发者ID:johnsonc,项目名称:caravel,代码行数:9,代码来源:core_tests.py

示例10: test_clean_requests_after_schema_grant

    def test_clean_requests_after_schema_grant(self):
        session = db.session

        # Case 4. Two access requests from gamma and gamma2
        # Gamma gets schema access, gamma2 access request granted
        # Check if request by gamma has been deleted

        gamma_user = sm.find_user(username='gamma')
        access_request1 = create_access_request(
            session, 'table', 'wb_health_population', TEST_ROLE_1, 'gamma')
        access_request2 = create_access_request(
            session, 'table', 'wb_health_population', TEST_ROLE_2, 'gamma2')
        ds_1_id = access_request1.datasource_id
        ds = session.query(SqlaTable).filter_by(
            table_name='wb_health_population').first()


        ds.schema = 'temp_schema'
        security.merge_perm(
            sm, 'schema_access', ds.schema_perm)
        schema_perm_view = sm.find_permission_view_menu(
            'schema_access', ds.schema_perm)
        sm.add_permission_role(
            sm.find_role(SCHEMA_ACCESS_ROLE) , schema_perm_view)
        gamma_user.roles.append(sm.find_role(SCHEMA_ACCESS_ROLE))
        session.commit()
        # gamma2 request gets fulfilled
        self.client.get(EXTEND_ROLE_REQUEST.format(
            'table', ds_1_id, 'gamma2', TEST_ROLE_2))
        access_requests = self.get_access_requests('gamma', 'table', ds_1_id)
        self.assertFalse(access_requests)
        gamma_user = sm.find_user(username='gamma')
        gamma_user.roles.remove(sm.find_role(SCHEMA_ACCESS_ROLE))

        ds = session.query(SqlaTable).filter_by(
            table_name='wb_health_population').first()
        ds.schema = None

        session.commit()
开发者ID:avsolatorio,项目名称:caravel,代码行数:39,代码来源:access_tests.py

示例11: test_update_role_do_not_exist

 def test_update_role_do_not_exist(self):
     update_role_str = 'update_me'
     update_role = sm.find_role(update_role_str)
     if update_role:
         db.session.delete(update_role)
     db.session.commit()
     with self.assertRaises(AttributeError):
         self.get_resp(
             '/superset/update_role/',
             data=json.dumps({
                 'user_emails': ['[email protected]'],
                 'role_name': update_role_str,
             })
         )
开发者ID:the-dcruz,项目名称:caravel,代码行数:14,代码来源:access_tests.py

示例12: test_override_role_permissions_drops_absent_perms

    def test_override_role_permissions_drops_absent_perms(self):
        override_me = sm.find_role('override_me')
        override_me.permissions.append(
            sm.find_permission_view_menu(
                view_menu_name=self.get_table_by_name('long_lat').perm,
                permission_name='datasource_access')
        )
        db.session.flush()

        response = self.client.post(
            '/superset/override_role_permissions/',
            data=json.dumps(ROLE_TABLES_PERM_DATA),
            content_type='application/json')
        self.assertEquals(201, response.status_code)
        updated_override_me = sm.find_role('override_me')
        self.assertEquals(1, len(updated_override_me.permissions))
        birth_names = self.get_table_by_name('birth_names')
        self.assertEquals(
            birth_names.perm,
            updated_override_me.permissions[0].view_menu.name)
        self.assertEquals(
            'datasource_access',
            updated_override_me.permissions[0].permission.name)
开发者ID:aaronyangzju,项目名称:caravel,代码行数:23,代码来源:access_tests.py

示例13: test_gamma_permissions

    def test_gamma_permissions(self):
        def assert_can_read(view_menu):
            self.assertIn(('can_show', view_menu), gamma_perm_set)
            self.assertIn(('can_list', view_menu), gamma_perm_set)

        def assert_can_write(view_menu):
            self.assertIn(('can_add', view_menu), gamma_perm_set)
            self.assertIn(('can_download', view_menu), gamma_perm_set)
            self.assertIn(('can_delete', view_menu), gamma_perm_set)
            self.assertIn(('can_edit', view_menu), gamma_perm_set)

        def assert_cannot_write(view_menu):
            self.assertNotIn(('can_add', view_menu), gamma_perm_set)
            self.assertNotIn(('can_download', view_menu), gamma_perm_set)
            self.assertNotIn(('can_delete', view_menu), gamma_perm_set)
            self.assertNotIn(('can_edit', view_menu), gamma_perm_set)
            self.assertNotIn(('can_save', view_menu), gamma_perm_set)

        def assert_can_all(view_menu):
            assert_can_read(view_menu)
            assert_can_write(view_menu)

        gamma_perm_set = set()
        for perm in sm.find_role('Gamma').permissions:
            gamma_perm_set.add((perm.permission.name, perm.view_menu.name))

        # check read only perms
        assert_can_read('TableModelView')
        assert_cannot_write('DruidColumnInlineView')

        # make sure that user can create slices and dashboards
        assert_can_all('SliceModelView')
        assert_can_all('DashboardModelView')

        self.assertIn(('can_add_slices', 'Superset'), gamma_perm_set)
        self.assertIn(('can_copy_dash', 'Superset'), gamma_perm_set)
        self.assertIn(('can_activity_per_day', 'Superset'), gamma_perm_set)
        self.assertIn(('can_created_dashboards', 'Superset'), gamma_perm_set)
        self.assertIn(('can_created_slices', 'Superset'), gamma_perm_set)
        self.assertIn(('can_csv', 'Superset'), gamma_perm_set)
        self.assertIn(('can_dashboard', 'Superset'), gamma_perm_set)
        self.assertIn(('can_explore', 'Superset'), gamma_perm_set)
        self.assertIn(('can_explore_json', 'Superset'), gamma_perm_set)
        self.assertIn(('can_fave_dashboards', 'Superset'), gamma_perm_set)
        self.assertIn(('can_fave_slices', 'Superset'), gamma_perm_set)
        self.assertIn(('can_save_dash', 'Superset'), gamma_perm_set)
        self.assertIn(('can_slice', 'Superset'), gamma_perm_set)
        self.assertIn(('can_update_explore', 'Superset'), gamma_perm_set)
开发者ID:aaronyangzju,项目名称:caravel,代码行数:48,代码来源:base_tests.py

示例14: test_override_role_permissions_1_table

    def test_override_role_permissions_1_table(self):
        response = self.client.post(
            '/superset/override_role_permissions/',
            data=json.dumps(ROLE_TABLES_PERM_DATA),
            content_type='application/json')
        self.assertEquals(201, response.status_code)

        updated_override_me = sm.find_role('override_me')
        self.assertEquals(1, len(updated_override_me.permissions))
        birth_names = self.get_table_by_name('birth_names')
        self.assertEquals(
            birth_names.perm,
            updated_override_me.permissions[0].view_menu.name)
        self.assertEquals(
            'datasource_access',
            updated_override_me.permissions[0].permission.name)
开发者ID:aaronyangzju,项目名称:caravel,代码行数:16,代码来源:access_tests.py

示例15: test_gamma_permissions

    def test_gamma_permissions(self):
        def assert_can_read(view_menu):
            self.assertIn(("can_show", view_menu), gamma_perm_set)
            self.assertIn(("can_list", view_menu), gamma_perm_set)

        def assert_can_write(view_menu):
            self.assertIn(("can_add", view_menu), gamma_perm_set)
            self.assertIn(("can_download", view_menu), gamma_perm_set)
            self.assertIn(("can_delete", view_menu), gamma_perm_set)
            self.assertIn(("can_edit", view_menu), gamma_perm_set)

        def assert_cannot_write(view_menu):
            self.assertNotIn(("can_add", view_menu), gamma_perm_set)
            self.assertNotIn(("can_download", view_menu), gamma_perm_set)
            self.assertNotIn(("can_delete", view_menu), gamma_perm_set)
            self.assertNotIn(("can_edit", view_menu), gamma_perm_set)
            self.assertNotIn(("can_save", view_menu), gamma_perm_set)

        def assert_can_all(view_menu):
            assert_can_read(view_menu)
            assert_can_write(view_menu)

        gamma_perm_set = set()
        for perm in sm.find_role("Gamma").permissions:
            gamma_perm_set.add((perm.permission.name, perm.view_menu.name))

        # check read only perms
        assert_can_read("TableModelView")
        assert_cannot_write("DruidColumnInlineView")

        # make sure that user can create slices and dashboards
        assert_can_all("SliceModelView")
        assert_can_all("DashboardModelView")

        self.assertIn(("can_add_slices", "Superset"), gamma_perm_set)
        self.assertIn(("can_copy_dash", "Superset"), gamma_perm_set)
        self.assertIn(("can_activity_per_day", "Superset"), gamma_perm_set)
        self.assertIn(("can_created_dashboards", "Superset"), gamma_perm_set)
        self.assertIn(("can_created_slices", "Superset"), gamma_perm_set)
        self.assertIn(("can_csv", "Superset"), gamma_perm_set)
        self.assertIn(("can_dashboard", "Superset"), gamma_perm_set)
        self.assertIn(("can_explore", "Superset"), gamma_perm_set)
        self.assertIn(("can_explore_json", "Superset"), gamma_perm_set)
        self.assertIn(("can_fave_dashboards", "Superset"), gamma_perm_set)
        self.assertIn(("can_fave_slices", "Superset"), gamma_perm_set)
        self.assertIn(("can_save_dash", "Superset"), gamma_perm_set)
        self.assertIn(("can_slice", "Superset"), gamma_perm_set)
开发者ID:airbnb,项目名称:caravel,代码行数:47,代码来源:base_tests.py


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