本文整理匯總了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