Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(gql): indicate whether user password needs reset #4514

Merged
merged 2 commits into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -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!
Expand Down
32 changes: 4 additions & 28 deletions src/phoenix/server/api/mutations/user_mutations.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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=[
Expand Down Expand Up @@ -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=[
Expand Down Expand Up @@ -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]]:
Expand Down
11 changes: 1 addition & 10 deletions src/phoenix/server/api/queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/phoenix/server/api/types/User.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
Loading