From f4ef677795cee86ea4e0ed0389688ff6a57bc3f2 Mon Sep 17 00:00:00 2001 From: Pedro Crespo-Valero <32402063+pcrespov@users.noreply.github.com> Date: Wed, 4 Dec 2024 18:16:41 +0100 Subject: [PATCH] adding privacy --- .../src/simcore_service_webserver/users/_models.py | 14 ++++++++++++++ .../src/simcore_service_webserver/users/api.py | 4 +++- .../src/simcore_service_webserver/users/schemas.py | 6 ++++++ 3 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 services/web/server/src/simcore_service_webserver/users/_models.py diff --git a/services/web/server/src/simcore_service_webserver/users/_models.py b/services/web/server/src/simcore_service_webserver/users/_models.py new file mode 100644 index 000000000000..656bbb587a8a --- /dev/null +++ b/services/web/server/src/simcore_service_webserver/users/_models.py @@ -0,0 +1,14 @@ +from pydantic import BaseModel + + +# +# REST models +# +class ProfilePrivacyGet(BaseModel): + hide_fullname: bool + hide_email: bool + + +class ProfilePrivacyUpdate(BaseModel): + hide_fullname: bool | None = None + hide_email: bool | None = None diff --git a/services/web/server/src/simcore_service_webserver/users/api.py b/services/web/server/src/simcore_service_webserver/users/api.py index 9fc6198191d5..7ab28bafcf08 100644 --- a/services/web/server/src/simcore_service_webserver/users/api.py +++ b/services/web/server/src/simcore_service_webserver/users/api.py @@ -65,7 +65,9 @@ async def get_user_profile( sa.join( users, sa.join( - user_to_groups, groups, user_to_groups.c.gid == groups.c.gid + user_to_groups, + groups, + user_to_groups.c.gid == groups.c.gid, ), users.c.id == user_to_groups.c.uid, ) diff --git a/services/web/server/src/simcore_service_webserver/users/schemas.py b/services/web/server/src/simcore_service_webserver/users/schemas.py index be2a5b7b0390..f7decdd9d7d8 100644 --- a/services/web/server/src/simcore_service_webserver/users/schemas.py +++ b/services/web/server/src/simcore_service_webserver/users/schemas.py @@ -12,6 +12,7 @@ from simcore_postgres_database.models.users import UserRole from ..utils import gravatar_hash +from ._models import ProfilePrivacyGet, ProfilePrivacyUpdate # @@ -66,6 +67,7 @@ class ProfileGet(BaseModel): alias="expirationDate", ) + privacy: ProfilePrivacyGet = ProfilePrivacyGet(hide_fullname=True, hide_email=True) preferences: AggregatedPreferences model_config = ConfigDict( @@ -74,6 +76,7 @@ class ProfileGet(BaseModel): populate_by_name=True, json_schema_extra={ "examples": [ + # 1. with gravatar { "id": 1, "login": "bla@foo.com", @@ -82,6 +85,7 @@ class ProfileGet(BaseModel): "gravatar_id": "205e460b479e2e5b48aec07710c08d50", "preferences": {}, }, + # 2. with expiration date { "id": 42, "login": "bla@foo.com", @@ -117,6 +121,8 @@ class ProfileUpdate(BaseModel): first_name: FirstNameStr | None = None last_name: LastNameStr | None = None + privacy: ProfilePrivacyUpdate | None = None + model_config = ConfigDict( json_schema_extra={ "example": {