本文整理汇总了Python中tracim_backend.lib.core.user.UserApi.find方法的典型用法代码示例。如果您正苦于以下问题:Python UserApi.find方法的具体用法?Python UserApi.find怎么用?Python UserApi.find使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tracim_backend.lib.core.user.UserApi
的用法示例。
在下文中一共展示了UserApi.find方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _get_auth_unsafe_user
# 需要导入模块: from tracim_backend.lib.core.user import UserApi [as 别名]
# 或者: from tracim_backend.lib.core.user.UserApi import find [as 别名]
def _get_auth_unsafe_user(
self,
request: Request,
email: typing.Optional[str]=None,
user_id: typing.Optional[int]=None,
) -> typing.Optional[User]:
"""
Helper to get user from email or user_id in pyramid request
(process check user_id first)
:param request: pyramid request
:param email: email of the user, optional
:param user_id: user_id of the user, optional
:return: User or None
"""
app_config = request.registry.settings['CFG']
uapi = UserApi(None, session=request.dbsession, config=app_config)
try:
_, user = uapi.find(user_id=user_id, email=email)
return user
except UserDoesNotExist:
return None
示例2: create_workspaces_members_role
# 需要导入模块: from tracim_backend.lib.core.user import UserApi [as 别名]
# 或者: from tracim_backend.lib.core.user.UserApi import find [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,
)