Skip to content

Commit

Permalink
fix: wrong group creation in mutate UserCreation (#1762)
Browse files Browse the repository at this point in the history
Backported-from: main
Backported-to: 23.09
  • Loading branch information
fregataa committed Dec 13, 2023
1 parent 031bee9 commit c919d9b
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/ai/backend/manager/models/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import sqlalchemy as sa
from dateutil.parser import parse as dtparse
from graphene.types.datetime import DateTime as GQLDateTime
from graphql import Undefined
from passlib.hash import bcrypt
from sqlalchemy.dialects import postgresql as pgsql
from sqlalchemy.engine.result import Result
Expand Down Expand Up @@ -590,6 +591,8 @@ async def mutate(
_status = UserStatus.ACTIVE if props.is_active else UserStatus.INACTIVE
else:
_status = UserStatus(props.status)
group_ids = [] if props.group_ids is Undefined else props.group_ids

user_data = {
"username": username,
"email": email,
Expand Down Expand Up @@ -641,14 +644,14 @@ async def _post_func(conn: SAConnection, result: Result) -> Row:
await conn.execute(update_query)

# Add user to groups if group_ids parameter is provided.
if props.group_ids:
if group_ids:
from .group import association_groups_users, groups

query = (
sa.select([groups.c.id])
.select_from(groups)
.where(groups.c.domain_name == props.domain_name)
.where(groups.c.id.in_(props.group_ids))
.where(groups.c.id.in_(group_ids))
)
grps = (await conn.execute(query)).all()
if grps:
Expand Down

0 comments on commit c919d9b

Please sign in to comment.