def _get_candidate_user_id(self) -> int: exception_if_none = UserNotFoundInTracimRequest( "No candidate user has been found in the context") exception_if_invalid_id = InvalidUserId( "user_id is not a correct integer") return self._get_path_id("user_id", exception_if_none, exception_if_invalid_id)
def _get_current_user_email(self) -> str: try: if not self.environ["http_authenticator.username"]: raise UserNotFoundInTracimRequest("No current user has been found in the context") except UserNotFoundInTracimRequest as exc: raise NotAuthenticated("User not found") from exc return self.environ["http_authenticator.username"]
def _get_candidate_user( self, request: 'TracimRequest', ) -> User: """ Get candidate user :param request: pyramid request :return: user found from header/body """ app_config = request.registry.settings['CFG'] uapi = UserApi(None, show_deleted=True, session=request.dbsession, config=app_config) login = '' try: login = None if 'user_id' in request.matchdict: user_id_str = request.matchdict['user_id'] if not isinstance(user_id_str, str) or not user_id_str.isdecimal(): raise InvalidUserId('user_id is not a correct integer') # nopep8 login = int(request.matchdict['user_id']) if not login: raise UserNotFoundInTracimRequest('You request a candidate user but the context not permit to found one') # nopep8 user = uapi.get_one(login) except UserNotFoundInTracimRequest as exc: raise UserDoesNotExist('User {} not found'.format(login)) from exc return user
def _get_candidate_user_id(self) -> int: exception_if_none = UserNotFoundInTracimRequest( "You request a candidate user but the " "context not permit to found one") exception_if_invalid_id = InvalidUserId( "user_id is not a correct integer") return self._get_path_id("user_id", exception_if_none, exception_if_invalid_id)
def _get_current_user_email(self) -> str: try: if not self.environ["http_authenticator.username"]: raise UserNotFoundInTracimRequest( "You request a current user " "but the context not permit to found one") except UserNotFoundInTracimRequest as exc: raise NotAuthenticated("User not found") from exc return self.environ["http_authenticator.username"]
def _get_current_user_id(self) -> int: try: if not self.authenticated_userid: raise UserNotFoundInTracimRequest( "You request a current user " "but the context not permit to found one") except UserNotFoundInTracimRequest as exc: raise NotAuthenticated("User not found") from exc return self.authenticated_userid
def current_user(self) -> User: # INFO - G.M - 24-03-2020 - load authenticate mecanism by calling authenticated_userid. # this will prefetch self._current_user value. try: if not self.authenticated_userid: raise UserNotFoundInTracimRequest( "No current user has been found in the context") except UserNotFoundInTracimRequest as exc: raise NotAuthenticated("User not found") from exc current_user = self._current_user return current_user
def _get_auth_safe_user( self, request: 'TracimRequest', ) -> User: """ Get current pyramid authenticated user from request :param request: pyramid request :return: current authenticated user """ app_config = request.registry.settings['CFG'] uapi = UserApi(None, session=request.dbsession, config=app_config) login = '' try: login = request.authenticated_userid if not login: raise UserNotFoundInTracimRequest('You request a current user but the context not permit to found one') # nopep8 user = uapi.get_one(login) if not user.is_active: raise UserAuthenticatedIsNotActive('User {} is not active'.format(login)) except (UserDoesNotExist, UserNotFoundInTracimRequest) as exc: raise NotAuthenticated('User {} not found'.format(login)) from exc return user