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


Python user.UserService类代码示例

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


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

示例1: main

def main(argv=sys.argv):
    if len(argv) < 2:
        usage(argv)
    config_uri = argv[1]
    options = parse_vars(argv[2:])
    setup_logging(config_uri)
    settings = get_appsettings(config_uri, name="testscaffold", options=options)

    engine = get_engine(settings)

    session_factory = get_session_factory(engine)
    dbsession = get_tm_session(session_factory, transaction.manager)

    with transaction.manager:
        user = User(user_name="admin", email="[email protected]")
        UserService.set_password(user, "admin")
        admin_object = Group(group_name="Administrators")
        group_permission = GroupPermission(perm_name="root_administration")
        dbsession.add(admin_object)
        admin_object.permissions.append(group_permission)
        admin_object.users.append(user)

        test_group = Group(group_name="Other group")
        dbsession.add(test_group)
        for x in range(1, 25):
            user = User(user_name="test{}".format(x), email="foo{}@localhost".format(x))
            UserService.set_password(user, "test")
            test_group.users.append(user)
开发者ID:ergo,项目名称:testscaffold,代码行数:28,代码来源:initializedb.py

示例2: test_users_for_perms

 def test_users_for_perms(self, db_session):
     user = User(user_name="aaa", email="aaa", status=0)
     UserService.set_password(user, "password")
     aaa_perm = UserPermission(perm_name="aaa")
     bbb_perm = UserPermission(perm_name="bbb")
     bbb2_perm = UserPermission(perm_name="bbb")
     user.user_permissions.append(aaa_perm)
     user.user_permissions.append(bbb_perm)
     user2 = User(user_name="bbb", email="bbb", status=0)
     UserService.set_password(user2, "password")
     user2.user_permissions.append(bbb2_perm)
     user3 = User(user_name="ccc", email="ccc", status=0)
     UserService.set_password(user3, "password")
     group = add_group(db_session)
     group.users.append(user3)
     db_session.add(user)
     db_session.add(user2)
     db_session.flush()
     users = UserService.users_for_perms(["aaa"], db_session=db_session)
     assert len(users.all()) == 1
     assert users[0].user_name == "aaa"
     users = UserService.users_for_perms(["bbb"], db_session=db_session).all()
     assert len(users) == 2
     assert ["aaa", "bbb"] == sorted([u.user_name for u in users])
     users = UserService.users_for_perms(
         ["aaa", "bbb", "manage_apps"], db_session=db_session
     )
     assert ["aaa", "bbb", "ccc"] == sorted([u.user_name for u in users])
开发者ID:ergo,项目名称:ziggurat_foundations,代码行数:28,代码来源:test_permissions.py

示例3: add_user

def add_user(
    db_session,
    user_name="username",
    email="email",
    perms=["root", "alter_users"],
    password="password",
):
    user = User(user_name=user_name, email=email, status=0)
    UserService.set_password(user, password)
    for perm in perms:
        u_perm = UserPermission(perm_name=perm)
        user.user_permissions.append(u_perm)
    db_session.add(user)
    db_session.flush()
    return user
开发者ID:ergo,项目名称:ziggurat_foundations,代码行数:15,代码来源:__init__.py

示例4: test_resources_with_possible_perms

    def test_resources_with_possible_perms(self, db_session):
        self.set_up_user_group_and_perms(db_session)
        resource = TestResourceB(
            resource_id=3, resource_name="other", owner_user_id=self.user.id
        )
        self.user.resources.append(resource)
        resource_g = TestResourceB(resource_id=4, resource_name="group owned")
        self.group.resources.append(resource_g)
        db_session.flush()
        perms = UserService.resources_with_possible_perms(
            self.user, db_session=db_session
        )
        second = [
            PermissionTuple(
                self.user, "foo_perm", "user", None, self.resource, False, True
            ),
            PermissionTuple(
                self.user, "group_perm", "group", self.group, self.resource, False, True
            ),
            PermissionTuple(
                self.user, "test_perm2", "user", None, self.resource, False, True
            ),
            PermissionTuple(
                self.user, ALL_PERMISSIONS, "user", None, resource, True, True
            ),
            PermissionTuple(
                self.user, ALL_PERMISSIONS, "group", self.group, resource_g, True, True
            ),
        ]

        check_one_in_other(perms, second)
开发者ID:ergo,项目名称:ziggurat_foundations,代码行数:31,代码来源:test_permissions.py

示例5: test_resources_ids_with_perm

    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]
开发者ID:ergo,项目名称:ziggurat_foundations,代码行数:31,代码来源:test_permissions.py

示例6: groups_with_resources

    def groups_with_resources(self):
        """

        .. deprecated:: 0.8

        :return:
        """
        return UserService.groups_with_resources(self)
开发者ID:stevepiercy,项目名称:ziggurat_foundations,代码行数:8,代码来源:user.py

示例7: regenerate_security_code

    def regenerate_security_code(self):
        """

        .. deprecated:: 0.8

        :return:
        """
        return UserService.regenerate_security_code(self)
开发者ID:stevepiercy,项目名称:ziggurat_foundations,代码行数:8,代码来源:user.py

示例8: check_password

    def check_password(self, raw_password):
        """

        .. deprecated:: 0.8

        :param raw_password:
        :return:
        """
        return UserService.check_password(self, raw_password=raw_password)
开发者ID:stevepiercy,项目名称:ziggurat_foundations,代码行数:9,代码来源:user.py

示例9: test_owned_permissions

 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
开发者ID:ergo,项目名称:ziggurat_foundations,代码行数:9,代码来源:test_permissions.py

示例10: generate_random_string

    def generate_random_string(chars=7):
        """

        .. deprecated:: 0.8

        :param chars:
        :return:
        """
        return UserService.generate_random_pass(chars=chars)
开发者ID:stevepiercy,项目名称:ziggurat_foundations,代码行数:9,代码来源:user.py

示例11: permissions

    def permissions(self):
        """

        .. deprecated:: 0.8

        :return:
        """
        db_session = get_db_session(None, self)
        return UserService.permissions(self, db_session=db_session)
开发者ID:stevepiercy,项目名称:ziggurat_foundations,代码行数:9,代码来源:user.py

示例12: get_user

 def get_user(request):
     userid = request.unauthenticated_userid
     if try_global_session:
         # set db_session to none to pass to the UserModel.by_id so it can try to autodiscover
         db_session = None
     else:
         # Else assign the request.session
         db_session = session_provider_callable(request)
     if userid is not None:
         return UserService.by_id(userid, db_session=db_session)
开发者ID:ergo,项目名称:ziggurat_foundations,代码行数:10,代码来源:get_user.py

示例13: gravatar_url

    def gravatar_url(self, default='mm', **kwargs):
        """

        .. deprecated:: 0.8

        :param default:
        :param kwargs:
        :return:
        """
        return UserService.gravatar_url(self, default, **kwargs)
开发者ID:stevepiercy,项目名称:ziggurat_foundations,代码行数:10,代码来源:user.py

示例14: test_permission_add

    def test_permission_add(self, full_app, sqla_session):
        from ziggurat_foundations.models.services.user import UserService

        with session_context(sqla_session) as session:
            admin, token = create_admin(session)
            user = create_user(
                {"user_name": "testX", "email": "[email protected]"},
                sqla_session=session,
            )

        url_path = "/api/0.1/users/{}/permissions".format(user.id)
        headers = {str("x-testscaffold-auth-token"): str(token)}
        permission = {"perm_name": "root_administration"}
        permissions = UserService.permissions(user)
        assert not list(permissions)
        full_app.post_json(url_path, permission, status=200, headers=headers)
        sqla_session.expire_all()
        permissions = UserService.permissions(user)
        assert permissions[0].perm_name == "root_administration"
开发者ID:ergo,项目名称:testscaffold,代码行数:19,代码来源:test_users_api.py

示例15: test_user_permissions

 def test_user_permissions(self, db_session):
     created_user = add_user(db_session)
     permissions = UserService.permissions(created_user, db_session=db_session)
     expected = [
         PermissionTuple(
             created_user, "alter_users", "user", None, None, False, True
         ),
         PermissionTuple(created_user, "root", "user", None, None, False, True),
     ]
     check_one_in_other(permissions, expected)
开发者ID:ergo,项目名称:ziggurat_foundations,代码行数:10,代码来源:test_permissions.py


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