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


Python UserApi.allowed_to_invite_new_user方法代码示例

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


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

示例1: create_workspaces_members_role

# 需要导入模块: from tracim_backend.lib.core.user import UserApi [as 别名]
# 或者: from tracim_backend.lib.core.user.UserApi import allowed_to_invite_new_user [as 别名]
    def create_workspaces_members_role(
            self,
            context,
            request: TracimRequest,
            hapic_data=None
    ) -> UserRoleWorkspaceInContext:
        """
        Add a member to this workspace.
        This feature is for workspace managers and administrators.
        """
        newly_created = False
        email_sent = False
        app_config = request.registry.settings['CFG'] # type: CFG
        rapi = RoleApi(
            current_user=request.current_user,
            session=request.dbsession,
            config=app_config,
        )
        uapi = UserApi(
            current_user=request.current_user,
            session=request.dbsession,
            config=app_config,
            show_deactivated=True,
            show_deleted=True,
        )
        try:
            _, user = uapi.find(
                user_id=hapic_data.body.user_id,
                email=hapic_data.body.user_email,
                public_name=hapic_data.body.user_public_name
            )
            if user.is_deleted:
                raise UserIsDeleted('This user has been deleted. Unable to invite him.')  # nopep8
            if not user.is_active:
                raise UserIsNotActive('This user is not activated. Unable to invite him')  # nopep8
        except UserDoesNotExist as exc:
            if not uapi.allowed_to_invite_new_user(hapic_data.body.user_email):
                raise exc

            if app_config.NEW_USER_INVITATION_DO_NOTIFY:
                user = uapi.create_user(
                    auth_type=AuthType.UNKNOWN,
                    email=hapic_data.body.user_email,
                    password=password_generator(),
                    do_notify=True
                )
                if app_config.EMAIL_NOTIFICATION_ACTIVATED and \
                    app_config.NEW_USER_INVITATION_DO_NOTIFY and \
                    app_config.EMAIL_NOTIFICATION_PROCESSING_MODE.lower() == 'sync':
                    email_sent = True
            else:
                user = uapi.create_user(
                    auth_type=AuthType.UNKNOWN,
                    email=hapic_data.body.user_email,
                    password=None,
                    do_notify=False
                )

            newly_created = True

        role = rapi.create_one(
            user=user,
            workspace=request.current_workspace,
            role_level=WorkspaceRoles.get_role_from_slug(hapic_data.body.role).level,  # nopep8
            with_notif=app_config.EMAIl_NOTIFICATION_ENABLED_ON_INVITATION,
            flush=True,
        )
        return rapi.get_user_role_workspace_with_context(
            role,
            newly_created=newly_created,
            email_sent=email_sent,
        )
开发者ID:tracim,项目名称:tracim,代码行数:74,代码来源:workspace_controller.py


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