super ultra fix

pull/12/head
def 2022-07-24 17:38:39 +02:00
parent f53cc22cbc
commit 6a9ecd5913
4 changed files with 12 additions and 27 deletions

View File

@ -22,7 +22,7 @@ class User:
user_type: UserType
username: str
# userHomeFolderspace: UserHomeFolderUsage
ssh_keys: typing.List[str] = []
ssh_keys: typing.List[str] = strawberry.field(default_factory=list)
@strawberry.type
@ -31,7 +31,7 @@ class UserMutationReturn(MutationReturnInterface):
user: typing.Optional[User]
def get_user_by_username(username):
def get_user_by_username(username: str) -> typing.Optional[User]:
with ReadUserData() as data:
if username == "root":
@ -63,3 +63,4 @@ def get_user_by_username(username):
username=username,
ssh_keys=user["sshKeys"],
)
return None

View File

@ -6,14 +6,13 @@ import subprocess
import typing
import strawberry
from selfprivacy_api.graphql import IsAuthenticated
from selfprivacy_api.graphql.common_types.user import User, UserMutationReturn
from selfprivacy_api.graphql.common_types.user import User, UserMutationReturn, get_user_by_username
from selfprivacy_api.graphql.mutations.mutation_interface import (
MutationReturnInterface,
)
from selfprivacy_api.utils import (
WriteUserData,
ReadUserData,
get_user_by_username,
is_username_forbidden,
)
from selfprivacy_api.utils import hash_password

View File

@ -3,7 +3,7 @@
import typing
import strawberry
from selfprivacy_api.graphql.common_types.user import User
from selfprivacy_api.graphql.common_types.user import User, get_user_by_username
from selfprivacy_api.utils import ReadUserData
@ -12,33 +12,19 @@ def get_users() -> typing.List[User]:
user_list = []
with ReadUserData() as data:
for user in data["users"]:
user_list.append(User(**user))
user_list.append(get_user_by_username(user["username"]))
if data["sshKeys"] not in data:
data["sshKeys"] = []
user_list.append(User(data["username"], data["sshKeys"]))
user_list.append(get_user_by_username(data["username"]))
return user_list
return user_list
@strawberry.type
class Users:
@strawberry.field
def get_user(self, username: str) -> typing.Optional[User]:
"""Get user"""
user = None
with ReadUserData() as data:
if username == data["username"]:
user = User(data["username"], data["sshKeys"])
elif username == "root":
user = User("root", data["ssh"]["rootKeys"])
else:
for user in data["users"]:
if user["username"] == username:
user = User(data["username"], data["sshKeys"])
return user
"""Get users"""
return get_user_by_username(username)
all_users: typing.List[User] = strawberry.field(resolver=get_users)

View File

@ -9,9 +9,8 @@ from selfprivacy_api.graphql.mutations.system_mutations import SystemMutations
from selfprivacy_api.graphql.queries.api_queries import Api
from selfprivacy_api.graphql.queries.system import System
from selfprivacy_api.resources.users import Users
from selfprivacy_api.graphql.mutations.users_mutations import UserMutations
from selfprivacy_api.graphql.queries.users import Users
@strawberry.type
class Query: