Skip to content

Commit d5f2e7e

Browse files
committed
privacy
1 parent ce0a606 commit d5f2e7e

File tree

4 files changed

+21
-6
lines changed

4 files changed

+21
-6
lines changed

packages/postgres-database/src/simcore_postgres_database/models/users.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,13 @@
9595
#
9696
# User Privacy Rules ------------------
9797
#
98+
sa.Column(
99+
"privacy_hide_username",
100+
sa.Boolean,
101+
nullable=False,
102+
server_default=expression.false(),
103+
doc="If true, it hides users.name to others",
104+
),
98105
sa.Column(
99106
"privacy_hide_fullname",
100107
sa.Boolean,

packages/postgres-database/src/simcore_postgres_database/utils_users.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,9 +242,16 @@ def is_public(hide_attribute: Column, caller_id: int):
242242
return hide_attribute.is_(False) | (users.c.id == caller_id)
243243

244244

245-
def visible_user_profile_cols(caller_id: int):
245+
def visible_user_profile_cols(caller_id: int, *, username_label: str):
246246
"""Returns user profile columns with visibility constraints applied based on privacy settings."""
247247
return (
248+
sa.case(
249+
(
250+
is_private(users.c.privacy_hide_username, caller_id),
251+
None,
252+
),
253+
else_=users.c.name,
254+
).label(username_label),
248255
sa.case(
249256
(
250257
is_private(users.c.privacy_hide_email, caller_id),

services/web/server/src/simcore_service_webserver/groups/_groups_repository.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -440,8 +440,7 @@ async def get_user_from_email(
440440
def _group_user_cols(caller_id: UserID):
441441
return (
442442
users.c.id,
443-
users.c.name,
444-
*visible_user_profile_cols(caller_id),
443+
*visible_user_profile_cols(caller_id, username_label="name"),
445444
users.c.primary_gid,
446445
)
447446

services/web/server/src/simcore_service_webserver/users/_users_repository.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,7 @@ def _public_user_cols(caller_id: int):
5959
return (
6060
# Fits PublicUser model
6161
users.c.id.label("user_id"),
62-
users.c.name.label("user_name"),
63-
*visible_user_profile_cols(caller_id),
62+
*visible_user_profile_cols(caller_id, username_label="user_name"),
6463
users.c.primary_gid.label("group_id"),
6564
)
6665

@@ -103,7 +102,10 @@ async def search_public_user(
103102
query = (
104103
sa.select(*_public_user_cols(caller_id=caller_id))
105104
.where(
106-
users.c.name.ilike(_pattern)
105+
(
106+
is_public(users.c.privacy_hide_username, caller_id)
107+
& users.c.name.ilike(_pattern)
108+
)
107109
| (
108110
is_public(users.c.privacy_hide_email, caller_id)
109111
& users.c.email.ilike(_pattern)

0 commit comments

Comments
 (0)