diff --git a/app/schema.graphql b/app/schema.graphql index 4985e997c2..a28241bb2c 100644 --- a/app/schema.graphql +++ b/app/schema.graphql @@ -1456,6 +1456,7 @@ type UMAPPoints { type User implements Node { """The Globally Unique ID of this object""" id: GlobalID! + passwordNeedsReset: Boolean! email: String! username: String createdAt: DateTime! diff --git a/src/phoenix/server/api/mutations/user_mutations.py b/src/phoenix/server/api/mutations/user_mutations.py index 1c7ef0a868..71e71d1d61 100644 --- a/src/phoenix/server/api/mutations/user_mutations.py +++ b/src/phoenix/server/api/mutations/user_mutations.py @@ -22,7 +22,7 @@ from phoenix.server.api.context import Context from phoenix.server.api.input_types.UserRoleInput import UserRoleInput from phoenix.server.api.types.node import from_global_id_with_expected_type -from phoenix.server.api.types.User import User +from phoenix.server.api.types.User import User, to_gql_user from phoenix.server.bearer_auth import PhoenixUser @@ -107,15 +107,7 @@ async def create_user( await session.flush() except IntegrityError as error: raise ValueError(_user_operation_error_message(error)) - return UserMutationPayload( - user=User( - id_attr=user.id, - email=user.email, - username=user.username, - created_at=user.created_at, - user_role_id=user.user_role_id, - ) - ) + return UserMutationPayload(user=to_gql_user(user)) @strawberry.mutation( permission_classes=[ @@ -163,15 +155,7 @@ async def patch_user( assert user if input.new_password: await info.context.log_out(user.id) - return UserMutationPayload( - user=User( - id_attr=user.id, - email=user.email, - username=user.username, - created_at=user.created_at, - user_role_id=user.user_role_id, - ) - ) + return UserMutationPayload(user=to_gql_user(user)) @strawberry.mutation( permission_classes=[ @@ -215,15 +199,7 @@ async def patch_viewer( assert user if input.new_password: await info.context.log_out(user.id) - return UserMutationPayload( - user=User( - id_attr=user.id, - email=user.email, - username=user.username, - created_at=user.created_at, - user_role_id=user.user_role_id, - ) - ) + return UserMutationPayload(user=to_gql_user(user)) def _select_role_id_by_name(role_name: str) -> Select[Tuple[int]]: diff --git a/src/phoenix/server/api/queries.py b/src/phoenix/server/api/queries.py index 872fb59ec9..2fa9c776a3 100644 --- a/src/phoenix/server/api/queries.py +++ b/src/phoenix/server/api/queries.py @@ -101,16 +101,7 @@ async def users( ) async with info.context.db() as session: users = await session.stream_scalars(stmt) - data = [ - User( - id_attr=user.id, - email=user.email, - username=user.username, - created_at=user.created_at, - user_role_id=user.user_role_id, - ) - async for user in users - ] + data = [to_gql_user(user) async for user in users] return connection_from_list(data=data, args=args) @strawberry.field diff --git a/src/phoenix/server/api/types/User.py b/src/phoenix/server/api/types/User.py index 307732aa06..c6b8971490 100644 --- a/src/phoenix/server/api/types/User.py +++ b/src/phoenix/server/api/types/User.py @@ -18,6 +18,7 @@ @strawberry.type class User(Node): id_attr: NodeID[int] + password_needs_reset: bool email: str username: Optional[str] created_at: datetime @@ -45,6 +46,7 @@ def to_gql_user(user: models.User, api_keys: Optional[List[models.ApiKey]] = Non """ return User( id_attr=user.id, + password_needs_reset=user.reset_password, username=user.username, email=user.email, created_at=user.created_at,