Skip to content

Commit

Permalink
return user from mutations
Browse files Browse the repository at this point in the history
  • Loading branch information
sir-sigurd committed Jun 14, 2024
1 parent 4107668 commit 11a4fe0
Show file tree
Hide file tree
Showing 8 changed files with 169 additions and 21 deletions.
4 changes: 4 additions & 0 deletions api/python/quilt3-admin/queries.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ mutation createUser($input: UserInput!) {
admin {
user {
create(input: $input) {
...UserSelection
...InvalidInputSelection
...OperationErrorSelection
}
Expand Down Expand Up @@ -98,6 +99,7 @@ mutation setRole($name: String!, $role: String!, $extraRoles: [String!], $append
user {
mutate(name: $name) {
setRole(role: $role, extraRoles: $extraRoles, append: $append) {
...UserSelection
...InvalidInputSelection
...OperationErrorSelection
}
Expand All @@ -111,6 +113,7 @@ mutation addRoles($name: String!, $roles: [String!]!) {
user {
mutate(name: $name) {
addRoles(roles: $roles) {
...UserSelection
...InvalidInputSelection
...OperationErrorSelection
}
Expand All @@ -124,6 +127,7 @@ mutation removeRoles($name: String!, $roles: [String!]!, $fallback: String) {
user {
mutate(name: $name) {
removeRoles(roles: $roles, fallback: $fallback) {
...UserSelection
...InvalidInputSelection
...OperationErrorSelection
}
Expand Down
18 changes: 9 additions & 9 deletions api/python/quilt3/admin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def get_users() -> List[User]:
return [User(**u.model_dump()) for u in _get_client().get_users()]


def create_user(name: str, email: str, role: str, extra_roles: Optional[List[str]] = None) -> None:
def create_user(name: str, email: str, role: str, extra_roles: Optional[List[str]] = None) -> User:
"""
Create a new user in the registry.
Expand All @@ -98,11 +98,11 @@ def create_user(name: str, email: str, role: str, extra_roles: Optional[List[str
extra_roles: Additional roles to assign to the user.
"""

_handle_errors(
return User(**_handle_errors(
_get_client().create_user(
input=_graphql_client.UserInput(name=name, email=email, role=role, extraRoles=extra_roles)
)
)
).model_dump())


def delete_user(name: str) -> None:
Expand Down Expand Up @@ -131,7 +131,7 @@ def set_role(
extra_roles: Optional[List[str]] = None,
*,
append: bool = False,
) -> None:
) -> User:
"""
Set the active and extra roles for a user.
Expand All @@ -144,10 +144,10 @@ def set_role(
result = _get_client().set_role(name=name, role=role, extra_roles=extra_roles, append=append)
if result is None:
raise UserNotFoundError
_handle_errors(result.set_role)
return User(**_handle_errors(result.set_role).model_dump())


def add_roles(name: str, roles: List[str]) -> None:
def add_roles(name: str, roles: List[str]) -> User:
"""
Add roles to a user.
Expand All @@ -158,14 +158,14 @@ def add_roles(name: str, roles: List[str]) -> None:
result = _get_client().add_roles(name=name, roles=roles)
if result is None:
raise UserNotFoundError
_handle_errors(result.add_roles)
return User(**_handle_errors(result.add_roles).model_dump())


def remove_roles(
name: str,
roles: List[str],
fallback: Optional[str] = None,
) -> None:
) -> User:
"""
Remove roles from a user.
Expand All @@ -177,4 +177,4 @@ def remove_roles(
result = _get_client().remove_roles(name=name, roles=roles, fallback=fallback)
if result is None:
raise UserNotFoundError
_handle_errors(result.remove_roles)
return User(**_handle_errors(result.remove_roles).model_dump())
4 changes: 2 additions & 2 deletions api/python/quilt3/admin/_graphql_client/add_roles.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

144 changes: 144 additions & 0 deletions api/python/quilt3/admin/_graphql_client/client.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions api/python/quilt3/admin/_graphql_client/create_user.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions api/python/quilt3/admin/_graphql_client/remove_roles.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions api/python/quilt3/admin/_graphql_client/set_role.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 11a4fe0

Please sign in to comment.