本文整理汇总了Python中ziggurat_foundations.models.services.user.UserService.resources_with_perms方法的典型用法代码示例。如果您正苦于以下问题:Python UserService.resources_with_perms方法的具体用法?Python UserService.resources_with_perms怎么用?Python UserService.resources_with_perms使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ziggurat_foundations.models.services.user.UserService
的用法示例。
在下文中一共展示了UserService.resources_with_perms方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_resources_ids_with_perm
# 需要导入模块: from ziggurat_foundations.models.services.user import UserService [as 别名]
# 或者: from ziggurat_foundations.models.services.user.UserService import resources_with_perms [as 别名]
def test_resources_ids_with_perm(self, db_session):
created_user = add_user(db_session)
resource1 = add_resource(db_session, 1, "test_resource1")
resource2 = add_resource(db_session, 2, "test_resource2")
resource3 = add_resource(db_session, 3, "test_resource3")
permission1 = UserResourcePermission(
perm_name="test_perm",
user_id=created_user.id,
resource_id=resource1.resource_id,
)
permission2 = UserResourcePermission(
perm_name="test_perm",
user_id=created_user.id,
resource_id=resource2.resource_id,
)
permission3 = UserResourcePermission(
perm_name="test_perm",
user_id=created_user.id,
resource_id=resource3.resource_id,
)
resource1.user_permissions.append(permission1)
resource2.user_permissions.append(permission2)
resource3.user_permissions.append(permission3)
db_session.flush()
resources = UserService.resources_with_perms(
created_user, ["test_perm"], resource_ids=[1, 3], db_session=db_session
).all()
assert resources == [resource1, resource3]
示例2: test_owned_permissions
# 需要导入模块: from ziggurat_foundations.models.services.user import UserService [as 别名]
# 或者: from ziggurat_foundations.models.services.user.UserService import resources_with_perms [as 别名]
def test_owned_permissions(self, db_session):
created_user = add_user(db_session)
resource = add_resource(db_session, 1, "test_resource")
created_user.resources.append(resource)
db_session.flush()
resources = UserService.resources_with_perms(
created_user, ["test_perm"], db_session=db_session
).all()
assert resources[0] == resource
示例3: test_resources_with_perm
# 需要导入模块: from ziggurat_foundations.models.services.user import UserService [as 别名]
# 或者: from ziggurat_foundations.models.services.user.UserService import resources_with_perms [as 别名]
def test_resources_with_perm(self, db_session):
created_user = add_user(db_session)
resource = add_resource(db_session, 1, "test_resource")
permission = UserResourcePermission(
perm_name="test_perm",
user_id=created_user.id,
resource_id=resource.resource_id,
)
resource.user_permissions.append(permission)
db_session.flush()
resources = UserService.resources_with_perms(
created_user, ["test_perm"], db_session=db_session
).all()
assert resources[0] == resource
示例4: resources_with_perms
# 需要导入模块: from ziggurat_foundations.models.services.user import UserService [as 别名]
# 或者: from ziggurat_foundations.models.services.user.UserService import resources_with_perms [as 别名]
def resources_with_perms(self, perms, resource_ids=None,
resource_types=None,
db_session=None):
"""
.. deprecated:: 0.8
:param perms:
:param resource_ids:
:param resource_types:
:param db_session:
:return:
"""
db_session = get_db_session(db_session, self)
return UserService.resources_with_perms(
self, perms=perms, resource_ids=resource_ids,
resource_types=resource_types, db_session=db_session)
示例5: test_mixed_perms
# 需要导入模块: from ziggurat_foundations.models.services.user import UserService [as 别名]
# 或者: from ziggurat_foundations.models.services.user.UserService import resources_with_perms [as 别名]
def test_mixed_perms(self, db_session):
created_user = add_user(db_session)
resource = add_resource(db_session, 1, "test_resource")
permission = UserResourcePermission(
perm_name="test_perm",
user_id=created_user.id,
resource_id=resource.resource_id,
)
resource.user_permissions.append(permission)
resource2 = add_resource(db_session, 2, "test_resource")
created_user.resources.append(resource2)
add_resource(db_session, 3, "test_resource")
add_resource_b(db_session, 4, "test_resource")
db_session.flush()
resources = UserService.resources_with_perms(
created_user, ["test_perm"], db_session=db_session
).all()
found_ids = [r.resource_id for r in resources]
assert sorted(found_ids) == [1, 2]
示例6: test_resources_with_group_permission
# 需要导入模块: from ziggurat_foundations.models.services.user import UserService [as 别名]
# 或者: from ziggurat_foundations.models.services.user.UserService import resources_with_perms [as 别名]
def test_resources_with_group_permission(self, db_session):
created_user = add_user(db_session)
resource = add_resource(db_session, 1, "test_resource")
resource2 = add_resource(db_session, 2, "test_resource2")
add_resource(db_session, 3, "test_resource3")
group = add_group(db_session)
group.users.append(created_user)
group_permission = GroupResourcePermission(
perm_name="test_perm", group_id=1, resource_id=resource.resource_id
)
group_permission2 = GroupResourcePermission(
perm_name="foo_perm", group_id=1, resource_id=resource2.resource_id
)
resource.group_permissions.append(group_permission)
resource2.group_permissions.append(group_permission2)
db_session.flush()
resources = UserService.resources_with_perms(
created_user, ["foo_perm"], db_session=db_session
).all()
assert resources[0] == resource2
示例7: test_multiple_resources_with_perm
# 需要导入模块: from ziggurat_foundations.models.services.user import UserService [as 别名]
# 或者: from ziggurat_foundations.models.services.user.UserService import resources_with_perms [as 别名]
def test_multiple_resources_with_perm(self, db_session):
created_user = add_user(db_session)
resource = add_resource(db_session, 1, "test_resource")
permission = UserResourcePermission(
perm_name="test_perm",
user_id=created_user.id,
resource_id=resource.resource_id,
)
resource.user_permissions.append(permission)
resource2 = add_resource(db_session, 2, "test_resource2")
permission2 = UserResourcePermission(
perm_name="test_perm",
user_id=created_user.id,
resource_id=resource2.resource_id,
)
resource2.user_permissions.append(permission2)
resources = UserService.resources_with_perms(
created_user, ["test_perm"], db_session=db_session
).all()
assert resources == [resource, resource2]
示例8: test_resources_with_perm_type_other_found
# 需要导入模块: from ziggurat_foundations.models.services.user import UserService [as 别名]
# 或者: from ziggurat_foundations.models.services.user.UserService import resources_with_perms [as 别名]
def test_resources_with_perm_type_other_found(self, db_session):
created_user = add_user(db_session)
resource = add_resource(db_session, 1, "test_resource")
resource2 = add_resource_b(db_session, 2, "test_resource")
resource3 = add_resource(db_session, 3, "test_resource")
resource4 = add_resource_b(db_session, 4, "test_resource")
db_session.flush()
permission = UserResourcePermission(
perm_name="test_perm",
user_id=created_user.id,
resource_id=resource.resource_id,
)
resource.user_permissions.append(permission)
permission2 = UserResourcePermission(
perm_name="test_perm",
user_id=created_user.id,
resource_id=resource2.resource_id,
)
resource2.user_permissions.append(permission2)
permission3 = UserResourcePermission(
perm_name="test_perm",
user_id=created_user.id,
resource_id=resource3.resource_id,
)
resource3.user_permissions.append(permission3)
permission4 = UserResourcePermission(
perm_name="test_perm",
user_id=created_user.id,
resource_id=resource4.resource_id,
)
resource4.user_permissions.append(permission4)
db_session.flush()
resources = UserService.resources_with_perms(
created_user,
["test_perm"],
resource_types=["test_resource_b"],
db_session=db_session,
).all()
assert len(resources) == 2