Compare commits

...

1 Commits

Author SHA1 Message Date
pablonyx
76ac0243f5 k 2025-03-30 13:10:55 -07:00
3 changed files with 5 additions and 7 deletions

View File

@@ -36,9 +36,6 @@ from onyx.utils.logger import setup_logger
logger = setup_logger()
router = APIRouter(prefix="/auth/saml")
# Define non-authenticated user roles that should be re-created during SAML login
NON_AUTHENTICATED_ROLES = {UserRole.SLACK_USER, UserRole.EXT_PERM_USER}
async def upsert_saml_user(email: str) -> User:
logger.debug(f"Attempting to upsert SAML user with email: {email}")
@@ -54,7 +51,7 @@ async def upsert_saml_user(email: str) -> User:
try:
user = await user_manager.get_by_email(email)
# If user has a non-authenticated role, treat as non-existent
if user.role in NON_AUTHENTICATED_ROLES:
if not user.role.is_web_login:
raise exceptions.UserNotExists()
return user
except exceptions.UserNotExists:

View File

@@ -26,6 +26,7 @@ class UserRole(str, Enum):
SLACK_USER = "slack_user"
EXT_PERM_USER = "ext_perm_user"
@property
def is_web_login(self) -> bool:
return self not in [
UserRole.SLACK_USER,

View File

@@ -319,7 +319,7 @@ class UserManager(UUIDIDMixin, BaseUserManager[User, uuid.UUID]):
except exceptions.UserAlreadyExists:
user = await self.get_by_email(user_create.email)
# Handle case where user has used product outside of web and is now creating an account through web
if not user.role.is_web_login() and user_create.role.is_web_login():
if not user.role.is_web_login and user_create.role.is_web_login:
user_update = UserUpdateWithRole(
password=user_create.password,
is_verified=user_create.is_verified,
@@ -490,7 +490,7 @@ class UserManager(UUIDIDMixin, BaseUserManager[User, uuid.UUID]):
)
# Handle case where user has used product outside of web and is now creating an account through web
if not user.role.is_web_login():
if not user.role.is_web_login:
await self.user_db.update(
user,
{
@@ -629,7 +629,7 @@ class UserManager(UUIDIDMixin, BaseUserManager[User, uuid.UUID]):
self.password_helper.hash(credentials.password)
return None
if not user.role.is_web_login():
if not user.role.is_web_login:
raise BasicAuthenticationError(
detail="NO_WEB_LOGIN_AND_HAS_NO_PASSWORD",
)