fractal-server 2.7.0a0__py3-none-any.whl → 2.7.0a1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- __VERSION__ = "2.7.0a0"
1
+ __VERSION__ = "2.7.0a1"
@@ -1,6 +1,12 @@
1
+ from datetime import datetime
2
+
3
+ from sqlalchemy import Column
4
+ from sqlalchemy.types import DateTime
1
5
  from sqlmodel import Field
2
6
  from sqlmodel import SQLModel
3
7
 
8
+ from fractal_server.utils import get_timestamp
9
+
4
10
 
5
11
  class LinkUserGroup(SQLModel, table=True):
6
12
  """
@@ -9,3 +15,8 @@ class LinkUserGroup(SQLModel, table=True):
9
15
 
10
16
  group_id: int = Field(foreign_key="usergroup.id", primary_key=True)
11
17
  user_id: int = Field(foreign_key="user_oauth.id", primary_key=True)
18
+
19
+ timestamp_created: datetime = Field(
20
+ default_factory=get_timestamp,
21
+ sa_column=Column(DateTime(timezone=True), nullable=False),
22
+ )
@@ -31,12 +31,17 @@ logger = set_logger(__name__)
31
31
  async def get_task_group_list(
32
32
  user: UserOAuth = Depends(current_active_user),
33
33
  db: AsyncSession = Depends(get_async_db),
34
+ only_active: bool = False,
35
+ only_owner: bool = False,
34
36
  ) -> list[TaskGroupReadV2]:
35
37
  """
36
38
  Get all accessible TaskGroups
37
39
  """
38
- stm = select(TaskGroupV2).where(
39
- or_(
40
+
41
+ if only_owner:
42
+ condition = TaskGroupV2.user_id == user.id
43
+ else:
44
+ condition = or_(
40
45
  TaskGroupV2.user_id == user.id,
41
46
  TaskGroupV2.user_group_id.in_(
42
47
  select(LinkUserGroup.group_id).where(
@@ -44,7 +49,10 @@ async def get_task_group_list(
44
49
  )
45
50
  ),
46
51
  )
47
- )
52
+ stm = select(TaskGroupV2).where(condition)
53
+ if only_active:
54
+ stm = stm.where(TaskGroupV2.active)
55
+
48
56
  res = await db.execute(stm)
49
57
  task_groups = res.scalars().all()
50
58
 
@@ -1,6 +1,7 @@
1
1
  from fastapi import HTTPException
2
2
  from fastapi import status
3
3
  from sqlalchemy.ext.asyncio import AsyncSession
4
+ from sqlmodel import asc
4
5
  from sqlmodel import select
5
6
 
6
7
  from fractal_server.app.models.linkusergroup import LinkUserGroup
@@ -9,58 +10,58 @@ from fractal_server.app.models.security import UserOAuth
9
10
  from fractal_server.app.schemas.user import UserRead
10
11
  from fractal_server.app.schemas.user_group import UserGroupRead
11
12
  from fractal_server.app.security import FRACTAL_DEFAULT_GROUP_NAME
13
+ from fractal_server.logger import set_logger
12
14
 
15
+ logger = set_logger(__name__)
13
16
 
14
- async def _get_single_user_with_group_names(
17
+
18
+ async def _get_single_user_with_groups(
15
19
  user: UserOAuth,
16
20
  db: AsyncSession,
17
21
  ) -> UserRead:
18
22
  """
19
- Enrich a user object by filling its `group_names` attribute.
23
+ Enrich a user object by filling its `group_ids_names` attribute.
20
24
 
21
25
  Arguments:
22
26
  user: The current `UserOAuth` object
23
27
  db: Async db session
24
28
 
25
29
  Returns:
26
- A `UserRead` object with `group_names` set
30
+ A `UserRead` object with `group_ids_names` dict
27
31
  """
28
32
  stm_groups = (
29
33
  select(UserGroup)
30
34
  .join(LinkUserGroup)
31
- .where(LinkUserGroup.user_id == UserOAuth.id)
35
+ .where(LinkUserGroup.user_id == user.id)
36
+ .order_by(asc(LinkUserGroup.timestamp_created))
32
37
  )
33
38
  res = await db.execute(stm_groups)
34
39
  groups = res.scalars().unique().all()
35
- group_names = [group.name for group in groups]
36
- return UserRead(
37
- **user.model_dump(),
38
- group_names=group_names,
39
- oauth_accounts=user.oauth_accounts,
40
+ group_ids_names = [(group.id, group.name) for group in groups]
41
+
42
+ # Check that Fractal Default Group is the first of the list. If not, fix.
43
+ index = next(
44
+ (
45
+ i
46
+ for i, group_tuple in enumerate(group_ids_names)
47
+ if group_tuple[1] == FRACTAL_DEFAULT_GROUP_NAME
48
+ ),
49
+ None,
40
50
  )
51
+ if index is None:
52
+ logger.warning(
53
+ f"User {user.id} not in "
54
+ f"default UserGroup '{FRACTAL_DEFAULT_GROUP_NAME}'"
55
+ )
56
+ elif index != 0:
57
+ default_group = group_ids_names.pop(index)
58
+ group_ids_names.insert(0, default_group)
59
+ else:
60
+ pass
41
61
 
42
-
43
- async def _get_single_user_with_group_ids(
44
- user: UserOAuth,
45
- db: AsyncSession,
46
- ) -> UserRead:
47
- """
48
- Enrich a user object by filling its `group_ids` attribute.
49
-
50
- Arguments:
51
- user: The current `UserOAuth` object
52
- db: Async db session
53
-
54
- Returns:
55
- A `UserRead` object with `group_ids` set
56
- """
57
- stm_links = select(LinkUserGroup).where(LinkUserGroup.user_id == user.id)
58
- res = await db.execute(stm_links)
59
- links = res.scalars().unique().all()
60
- group_ids = [link.group_id for link in links]
61
62
  return UserRead(
62
63
  **user.model_dump(),
63
- group_ids=group_ids,
64
+ group_ids_names=group_ids_names,
64
65
  oauth_accounts=user.oauth_accounts,
65
66
  )
66
67
 
@@ -13,7 +13,7 @@ from ...schemas.user import UserRead
13
13
  from ...schemas.user import UserUpdate
14
14
  from ...schemas.user import UserUpdateStrict
15
15
  from ..aux.validate_user_settings import verify_user_has_settings
16
- from ._aux_auth import _get_single_user_with_group_names
16
+ from ._aux_auth import _get_single_user_with_groups
17
17
  from fractal_server.app.models import LinkUserGroup
18
18
  from fractal_server.app.models import UserGroup
19
19
  from fractal_server.app.models import UserOAuth
@@ -28,15 +28,15 @@ router_current_user = APIRouter()
28
28
 
29
29
  @router_current_user.get("/current-user/", response_model=UserRead)
30
30
  async def get_current_user(
31
- group_names: bool = False,
31
+ group_ids_names: bool = False,
32
32
  user: UserOAuth = Depends(current_active_user),
33
33
  db: AsyncSession = Depends(get_async_db),
34
34
  ):
35
35
  """
36
36
  Return current user
37
37
  """
38
- if group_names is True:
39
- user_with_groups = await _get_single_user_with_group_names(user, db)
38
+ if group_ids_names is True:
39
+ user_with_groups = await _get_single_user_with_groups(user, db)
40
40
  return user_with_groups
41
41
  else:
42
42
  return user
@@ -65,7 +65,7 @@ async def patch_current_user(
65
65
  patched_user = await db.get(
66
66
  UserOAuth, validated_user.id, populate_existing=True
67
67
  )
68
- patched_user_with_groups = await _get_single_user_with_group_names(
68
+ patched_user_with_groups = await _get_single_user_with_groups(
69
69
  patched_user, db
70
70
  )
71
71
  return patched_user_with_groups
@@ -2,7 +2,6 @@ from fastapi import APIRouter
2
2
 
3
3
  from .current_user import router_current_user
4
4
  from .group import router_group
5
- from .group_names import router_group_names
6
5
  from .login import router_login
7
6
  from .oauth import router_oauth
8
7
  from .register import router_register
@@ -13,7 +12,6 @@ router_auth = APIRouter()
13
12
  router_auth.include_router(router_register)
14
13
  router_auth.include_router(router_current_user)
15
14
  router_auth.include_router(router_login)
16
- router_auth.include_router(router_group_names)
17
15
  router_auth.include_router(router_users)
18
16
  router_auth.include_router(router_group)
19
17
  router_auth.include_router(router_oauth)
@@ -20,7 +20,7 @@ from ...schemas.user import UserRead
20
20
  from ...schemas.user import UserUpdate
21
21
  from ...schemas.user import UserUpdateWithNewGroupIds
22
22
  from ..aux.validate_user_settings import verify_user_has_settings
23
- from ._aux_auth import _get_single_user_with_group_ids
23
+ from ._aux_auth import _get_single_user_with_groups
24
24
  from fractal_server.app.models import LinkUserGroup
25
25
  from fractal_server.app.models import UserGroup
26
26
  from fractal_server.app.models import UserOAuth
@@ -41,13 +41,14 @@ logger = set_logger(__name__)
41
41
  @router_users.get("/users/{user_id}/", response_model=UserRead)
42
42
  async def get_user(
43
43
  user_id: int,
44
- group_ids: bool = True,
44
+ group_ids_names: bool = True,
45
45
  superuser: UserOAuth = Depends(current_active_superuser),
46
46
  db: AsyncSession = Depends(get_async_db),
47
47
  ) -> UserRead:
48
48
  user = await _user_or_404(user_id, db)
49
- if group_ids:
50
- user = await _get_single_user_with_group_ids(user, db)
49
+ if group_ids_names:
50
+ user_with_groups = await _get_single_user_with_groups(user, db)
51
+ return user_with_groups
51
52
  return user
52
53
 
53
54
 
@@ -163,12 +164,12 @@ async def patch_user(
163
164
  # Nothing to do, just continue
164
165
  patched_user = user_to_patch
165
166
 
166
- # Enrich user object with `group_ids` attribute
167
- patched_user_with_group_ids = await _get_single_user_with_group_ids(
167
+ # Enrich user object with `group_ids_names` attribute
168
+ patched_user_with_groups = await _get_single_user_with_groups(
168
169
  patched_user, db
169
170
  )
170
171
 
171
- return patched_user_with_group_ids
172
+ return patched_user_with_groups
172
173
 
173
174
 
174
175
  @router_users.get("/users/", response_model=list[UserRead])
@@ -41,8 +41,7 @@ class UserRead(schemas.BaseUser[int]):
41
41
  """
42
42
 
43
43
  username: Optional[str]
44
- group_names: Optional[list[str]] = None
45
- group_ids: Optional[list[int]] = None
44
+ group_ids_names: Optional[list[tuple[int, str]]] = None
46
45
  oauth_accounts: list[OAuthAccountRead]
47
46
 
48
47
 
@@ -0,0 +1,42 @@
1
+ """LinkUserGroup.timestamp_created
2
+
3
+ Revision ID: df7cc3501bf7
4
+ Revises: 7cf1baae8fb4
5
+ Create Date: 2024-10-03 13:55:53.272269
6
+
7
+ """
8
+ from datetime import datetime
9
+ from datetime import timezone
10
+
11
+ import sqlalchemy as sa
12
+ from alembic import op
13
+
14
+
15
+ # revision identifiers, used by Alembic.
16
+ revision = "df7cc3501bf7"
17
+ down_revision = "7cf1baae8fb4"
18
+ branch_labels = None
19
+ depends_on = None
20
+
21
+
22
+ def upgrade() -> None:
23
+ with op.batch_alter_table("linkusergroup", schema=None) as batch_op:
24
+ batch_op.add_column(
25
+ sa.Column(
26
+ "timestamp_created",
27
+ sa.DateTime(timezone=True),
28
+ nullable=False,
29
+ server_default=str(datetime(2000, 1, 1, tzinfo=timezone.utc)),
30
+ )
31
+ )
32
+
33
+ with op.batch_alter_table("project", schema=None) as batch_op:
34
+ batch_op.alter_column("timestamp_created", server_default=None)
35
+
36
+
37
+ def downgrade() -> None:
38
+ # ### commands auto generated by Alembic - please adjust! ###
39
+ with op.batch_alter_table("linkusergroup", schema=None) as batch_op:
40
+ batch_op.drop_column("timestamp_created")
41
+
42
+ # ### end Alembic commands ###
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: fractal-server
3
- Version: 2.7.0a0
3
+ Version: 2.7.0a1
4
4
  Summary: Server component of the Fractal analytics platform
5
5
  Home-page: https://github.com/fractal-analytics-platform/fractal-server
6
6
  License: BSD-3-Clause
@@ -1,10 +1,10 @@
1
- fractal_server/__init__.py,sha256=ZS0eSCN-H2wC1jN2xuEEQO0H7w40xuoUIC5HTgQKC2o,24
1
+ fractal_server/__init__.py,sha256=a93MyH1kQ9BKFlxzrvnhMDhXFBw7mHkaQCSrrhceInk,24
2
2
  fractal_server/__main__.py,sha256=WcBAkmVE9aH5mDI6wGkVmPAql2N5Vyk0A-7zuUl8WX0,6122
3
3
  fractal_server/alembic.ini,sha256=MWwi7GzjzawI9cCAK1LW7NxIBQDUqD12-ptJoq5JpP0,3153
4
4
  fractal_server/app/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
5
5
  fractal_server/app/db/__init__.py,sha256=81rK9w1__Z6PJ5cEcChPVc-wI9YOK4fN--_5Opry0MQ,4119
6
6
  fractal_server/app/models/__init__.py,sha256=aG7mf1zZbsgzDSp7GHEcZhdjHfW3TGPOLCI8MrvYhPw,500
7
- fractal_server/app/models/linkusergroup.py,sha256=ufthlbLFAWMU_dJmsVZzVlQa_D9C9SmgydxypQ2Xq1U,309
7
+ fractal_server/app/models/linkusergroup.py,sha256=LWTUfhH2uAnn_4moK7QdRUIHWtpw-hPZuW-5jClv_OE,610
8
8
  fractal_server/app/models/linkuserproject.py,sha256=eQaourbGRshvlMVlKzLYJKHEjfsW1CbWws9yW4eHXhA,567
9
9
  fractal_server/app/models/security.py,sha256=2npjgRKBZ7OAnhAXNbYxjtuOsSm1P4kak__qfk2SpeM,3770
10
10
  fractal_server/app/models/user_settings.py,sha256=0YXCAwoAVGqI2irRLdXgr9-JS0STtHhSaoFENigAnrk,1312
@@ -49,19 +49,18 @@ fractal_server/app/routes/api/v2/submit.py,sha256=h7mjmea_VNCriGiA4HRuyxLHlvd9aG
49
49
  fractal_server/app/routes/api/v2/task.py,sha256=CZQjI5IKxeN23YTu3eTjPuPcO6BSmcAXQR3Pcy0WSuQ,7828
50
50
  fractal_server/app/routes/api/v2/task_collection.py,sha256=9trKrJDuaKKgdn-mG06VuFpyObhbcCD8AstaxN4lAOM,13507
51
51
  fractal_server/app/routes/api/v2/task_collection_custom.py,sha256=T3RoxQWmJVipEdXSjbD_Zdw_mc3IIYT3aDLZIQ_StIM,7272
52
- fractal_server/app/routes/api/v2/task_group.py,sha256=jTPXYohA1x9y4u5HWRs_1h3tgjPzlnkMHEG7vqealSA,3855
52
+ fractal_server/app/routes/api/v2/task_group.py,sha256=yRUCMZtXH9KdfD2pfdCKPBGf_eVn-S5CXFHCUyXAoJk,4078
53
53
  fractal_server/app/routes/api/v2/workflow.py,sha256=q4_sFCSw-_1oC4FENv_HIInDF_2uJG5QXqiH9Ns_ZK4,11330
54
54
  fractal_server/app/routes/api/v2/workflowtask.py,sha256=TIOePM13uK3GKVhtGK2wBB341ZFheBYQKTfXuPfdymE,6999
55
55
  fractal_server/app/routes/auth/__init__.py,sha256=fao6CS0WiAjHDTvBzgBVV_bSXFpEAeDBF6Z6q7rRkPc,1658
56
- fractal_server/app/routes/auth/_aux_auth.py,sha256=TN98qypik2pwcRpnlVQ9VOBFEW5HBOLqkpD5PgaOT44,4661
57
- fractal_server/app/routes/auth/current_user.py,sha256=s3R1O53Qnow1LqDW-UpkYvfKKSJwLrDWGeMtsIEMUNs,4462
56
+ fractal_server/app/routes/auth/_aux_auth.py,sha256=6GERRDXK4P-2OA81bjxJZEw6hN4QCk5x7MqDNtN7VG4,4746
57
+ fractal_server/app/routes/auth/current_user.py,sha256=v767HGi8k076ZHoErlU4Vv0_c8HQqYmi8ncjzZZDaDE,4455
58
58
  fractal_server/app/routes/auth/group.py,sha256=eT-1c0Ow8KbYkKEMQ5ebhEAeRixwJs2kQW45UIutH5w,5833
59
- fractal_server/app/routes/auth/group_names.py,sha256=zvYDfhxKlDmbSr-oLXYy6WUVkPPTvzH6ZJtuoNdGZbE,960
60
59
  fractal_server/app/routes/auth/login.py,sha256=tSu6OBLOieoBtMZB4JkBAdEgH2Y8KqPGSbwy7NIypIo,566
61
60
  fractal_server/app/routes/auth/oauth.py,sha256=AnFHbjqL2AgBX3eksI931xD6RTtmbciHBEuGf9YJLjU,1895
62
61
  fractal_server/app/routes/auth/register.py,sha256=DlHq79iOvGd_gt2v9uwtsqIKeO6i_GKaW59VIkllPqY,587
63
- fractal_server/app/routes/auth/router.py,sha256=zWoZWiO69U48QFQf5tLRYQDWu8PUCj7GacnaFeW1n_I,618
64
- fractal_server/app/routes/auth/users.py,sha256=63gOBjGaQpUfakVmqb9RzBcKdIafiFlmaN_ctUOA0fg,8356
62
+ fractal_server/app/routes/auth/router.py,sha256=tzJrygXFZlmV_uWelVqTOJMEH-3Fr7ydwlgx1LxRjxY,527
63
+ fractal_server/app/routes/auth/users.py,sha256=FzKNoB-wD32AkVOj1Vi29lGGyOl8NSMCRL9tEhxqpJk,8403
65
64
  fractal_server/app/routes/aux/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
66
65
  fractal_server/app/routes/aux/_job.py,sha256=q-RCiW17yXnZKAC_0La52RLvhqhxuvbgQJ2MlGXOj8A,702
67
66
  fractal_server/app/routes/aux/_runner.py,sha256=FdCVla5DxGAZ__aB7Z8dEJzD_RIeh5tftjrPyqkr8N8,895
@@ -128,7 +127,7 @@ fractal_server/app/runner/v2/task_interface.py,sha256=myS-kT0DsJ8xIJZBVEzgD8g54V
128
127
  fractal_server/app/runner/versions.py,sha256=dSaPRWqmFPHjg20kTCHmi_dmGNcCETflDtDLronNanU,852
129
128
  fractal_server/app/schemas/__init__.py,sha256=stURAU_t3AOBaH0HSUbV-GKhlPKngnnIMoqWc3orFyI,135
130
129
  fractal_server/app/schemas/_validators.py,sha256=XKEGEHxp3H6YSJewtFWXe_2Nh7SDdNtAXmlEmJO6Vb0,3606
131
- fractal_server/app/schemas/user.py,sha256=VNnAPnAVK6X0PZlw7XehocAshVNuUHdDwiZVWCCor6Y,2156
130
+ fractal_server/app/schemas/user.py,sha256=aUD8YAcfYTEO06TEUoTx4heVrXFiX7E2Mb8D2--4FsA,2130
132
131
  fractal_server/app/schemas/user_group.py,sha256=YwJvYgj-PI66LWy38CEd_FIZPsBV1_2N5zJPGFcFvBw,2143
133
132
  fractal_server/app/schemas/user_settings.py,sha256=UEST1MSmd9w2YypCji3SONSFlJcr2u4uG3bTczZy_Pk,3102
134
133
  fractal_server/app/schemas/v1/__init__.py,sha256=CrBGgBhoemCvmZ70ZUchM-jfVAICnoa7AjZBAtL2UB0,1852
@@ -187,6 +186,7 @@ fractal_server/migrations/versions/9fd26a2b0de4_add_workflow_timestamp_created.p
187
186
  fractal_server/migrations/versions/a7f4d6137b53_add_workflow_dump_to_applyworkflow.py,sha256=ekDUML7ILpmdoqEclKbEUdyLi4uw9HSG_sTjG2hp_JE,867
188
187
  fractal_server/migrations/versions/d4fe3708d309_make_applyworkflow_workflow_dump_non_.py,sha256=6cHEZFuTXiQg9yu32Y3RH1XAl71av141WQ6UMbiITIg,949
189
188
  fractal_server/migrations/versions/da2cb2ac4255_user_group_viewer_paths.py,sha256=yGWSA2HIHUybcVy66xBITk08opV2DFYSCIIrulaUZhI,901
189
+ fractal_server/migrations/versions/df7cc3501bf7_linkusergroup_timestamp_created.py,sha256=pkF9ocXKYCsIeVXf8kDRK4hmIgv7UHCytJu2U-X1n7w,1134
190
190
  fractal_server/migrations/versions/e75cac726012_make_applyworkflow_start_timestamp_not_.py,sha256=lOggSvzGWqQvnxxFuSM6W50Ui49R918A-uBuiZJ0pNM,963
191
191
  fractal_server/migrations/versions/efa89c30e0a4_add_project_timestamp_created.py,sha256=jilQW3QIqYQ4Q6hCnUiG7UtNMpA41ujqrB3tPFiPM1Q,1221
192
192
  fractal_server/migrations/versions/f384e1c0cf5d_drop_task_default_args_columns.py,sha256=9BwqUS9Gf7UW_KjrzHbtViC880qhD452KAytkHWWZyk,746
@@ -219,8 +219,8 @@ fractal_server/tasks/v2/utils.py,sha256=JOyCacb6MNvrwfLNTyLwcz8y79J29YuJeJ2MK5kq
219
219
  fractal_server/urls.py,sha256=5o_qq7PzKKbwq12NHSQZDmDitn5RAOeQ4xufu-2v9Zk,448
220
220
  fractal_server/utils.py,sha256=b7WwFdcFZ8unyT65mloFToYuEDXpQoHRcmRNqrhd_dQ,2115
221
221
  fractal_server/zip_tools.py,sha256=xYpzBshysD2nmxkD5WLYqMzPYUcCRM3kYy-7n9bJL-U,4426
222
- fractal_server-2.7.0a0.dist-info/LICENSE,sha256=QKAharUuhxL58kSoLizKJeZE3mTCBnX6ucmz8W0lxlk,1576
223
- fractal_server-2.7.0a0.dist-info/METADATA,sha256=2AODEnxq0BSIyIof4wmwTTDXE21-DCtH8QtGzts8V0U,4630
224
- fractal_server-2.7.0a0.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
225
- fractal_server-2.7.0a0.dist-info/entry_points.txt,sha256=8tV2kynvFkjnhbtDnxAqImL6HMVKsopgGfew0DOp5UY,58
226
- fractal_server-2.7.0a0.dist-info/RECORD,,
222
+ fractal_server-2.7.0a1.dist-info/LICENSE,sha256=QKAharUuhxL58kSoLizKJeZE3mTCBnX6ucmz8W0lxlk,1576
223
+ fractal_server-2.7.0a1.dist-info/METADATA,sha256=sl_pu6zE_5uRj_frkAhgWsAJxDvNNz6LYpmsLq4BPWE,4630
224
+ fractal_server-2.7.0a1.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
225
+ fractal_server-2.7.0a1.dist-info/entry_points.txt,sha256=8tV2kynvFkjnhbtDnxAqImL6HMVKsopgGfew0DOp5UY,58
226
+ fractal_server-2.7.0a1.dist-info/RECORD,,
@@ -1,34 +0,0 @@
1
- """
2
- Definition `/auth/group-names/` endpoints
3
- """
4
- from fastapi import APIRouter
5
- from fastapi import Depends
6
- from fastapi import status
7
- from sqlalchemy.ext.asyncio import AsyncSession
8
- from sqlmodel import select
9
-
10
- from . import current_active_user
11
- from ...db import get_async_db
12
- from fractal_server.app.models import UserGroup
13
- from fractal_server.app.models import UserOAuth
14
-
15
- router_group_names = APIRouter()
16
-
17
-
18
- @router_group_names.get(
19
- "/group-names/", response_model=list[str], status_code=status.HTTP_200_OK
20
- )
21
- async def get_list_user_group_names(
22
- user: UserOAuth = Depends(current_active_user),
23
- db: AsyncSession = Depends(get_async_db),
24
- ) -> list[str]:
25
- """
26
- Return the available group names.
27
-
28
- This endpoint is not restricted to superusers.
29
- """
30
- stm_all_groups = select(UserGroup)
31
- res = await db.execute(stm_all_groups)
32
- groups = res.scalars().all()
33
- group_names = [group.name for group in groups]
34
- return group_names