fractal-server 2.9.0a8__py3-none-any.whl → 2.9.0a9__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.9.0a8"
1
+ __VERSION__ = "2.9.0a9"
@@ -1,6 +1,8 @@
1
1
  """
2
2
  Definition of `/auth/current-user/` endpoints
3
3
  """
4
+ import os
5
+
4
6
  from fastapi import APIRouter
5
7
  from fastapi import Depends
6
8
  from fastapi_users import schemas
@@ -22,6 +24,8 @@ from fractal_server.app.schemas import UserSettingsReadStrict
22
24
  from fractal_server.app.schemas import UserSettingsUpdateStrict
23
25
  from fractal_server.app.security import get_user_manager
24
26
  from fractal_server.app.security import UserManager
27
+ from fractal_server.config import get_settings
28
+ from fractal_server.syringe import Inject
25
29
 
26
30
  router_current_user = APIRouter()
27
31
 
@@ -109,26 +113,65 @@ async def patch_current_user_settings(
109
113
 
110
114
 
111
115
  @router_current_user.get(
112
- "/current-user/viewer-paths/", response_model=list[str]
116
+ "/current-user/allowed-viewer-paths/", response_model=list[str]
113
117
  )
114
- async def get_current_user_viewer_paths(
118
+ async def get_current_user_allowed_viewer_paths(
115
119
  current_user: UserOAuth = Depends(current_active_user),
116
120
  db: AsyncSession = Depends(get_async_db),
117
121
  ) -> list[str]:
118
- """Returns the union of `viewer_paths` for all user's groups"""
119
- cmd = (
120
- select(UserGroup.viewer_paths)
121
- .join(LinkUserGroup)
122
- .where(LinkUserGroup.group_id == UserGroup.id)
123
- .where(LinkUserGroup.user_id == current_user.id)
124
- )
125
- res = await db.execute(cmd)
126
- viewer_paths_nested = res.scalars().all()
122
+ """
123
+ Returns the allowed viewer paths for current user, according to the
124
+ selected FRACTAL_VIEWER_AUTHORIZATION_SCHEME
125
+ """
127
126
 
128
- # Flatten a nested object and make its elements unique
129
- all_viewer_paths_set = set(
130
- path for _viewer_paths in viewer_paths_nested for path in _viewer_paths
131
- )
132
- all_viewer_paths = list(all_viewer_paths_set)
127
+ settings = Inject(get_settings)
128
+
129
+ if settings.FRACTAL_VIEWER_AUTHORIZATION_SCHEME == "none":
130
+ return []
133
131
 
134
- return all_viewer_paths
132
+ authorized_paths = []
133
+
134
+ # Respond with 422 error if user has no settings
135
+ verify_user_has_settings(current_user)
136
+
137
+ # Load current user settings
138
+ current_user_settings = await db.get(
139
+ UserSettings, current_user.user_settings_id
140
+ )
141
+ # If project_dir is set, append it to the list of authorized paths
142
+ if current_user_settings.project_dir is not None:
143
+ authorized_paths.append(current_user_settings.project_dir)
144
+
145
+ # If auth scheme is "users-folders" and `slurm_user` is set,
146
+ # build and append the user folder
147
+ if (
148
+ settings.FRACTAL_VIEWER_AUTHORIZATION_SCHEME == "users-folders"
149
+ and current_user_settings.slurm_user is not None
150
+ ):
151
+ base_folder = settings.FRACTAL_VIEWER_BASE_FOLDER
152
+ user_folder = os.path.join(
153
+ base_folder, current_user_settings.slurm_user
154
+ )
155
+ authorized_paths.append(user_folder)
156
+
157
+ if settings.FRACTAL_VIEWER_AUTHORIZATION_SCHEME == "viewer-paths":
158
+ # Returns the union of `viewer_paths` for all user's groups
159
+ cmd = (
160
+ select(UserGroup.viewer_paths)
161
+ .join(LinkUserGroup)
162
+ .where(LinkUserGroup.group_id == UserGroup.id)
163
+ .where(LinkUserGroup.user_id == current_user.id)
164
+ )
165
+ res = await db.execute(cmd)
166
+ viewer_paths_nested = res.scalars().all()
167
+
168
+ # Flatten a nested object and make its elements unique
169
+ all_viewer_paths_set = set(
170
+ path
171
+ for _viewer_paths in viewer_paths_nested
172
+ for path in _viewer_paths
173
+ )
174
+
175
+ authorized_paths.extend(all_viewer_paths_set)
176
+
177
+ return authorized_paths
fractal_server/config.py CHANGED
@@ -87,7 +87,7 @@ class Settings(BaseSettings):
87
87
  """
88
88
  Contains all the configuration variables for Fractal Server
89
89
 
90
- The attributes of this class are set from the environtment.
90
+ The attributes of this class are set from the environment.
91
91
  """
92
92
 
93
93
  class Config:
@@ -383,7 +383,7 @@ class Settings(BaseSettings):
383
383
  @root_validator(pre=True)
384
384
  def check_tasks_python(cls, values) -> None:
385
385
  """
386
- Perform multiple checks of the Python-intepreter variables.
386
+ Perform multiple checks of the Python-interpreter variables.
387
387
 
388
388
  1. Each `FRACTAL_TASKS_PYTHON_X_Y` variable must be an absolute path,
389
389
  if set.
@@ -432,7 +432,7 @@ class Settings(BaseSettings):
432
432
  f"{current_version_dot}"
433
433
  )
434
434
 
435
- # Unset all existing intepreters variable
435
+ # Unset all existing interpreters variable
436
436
  for _version in ["3_9", "3_10", "3_11", "3_12"]:
437
437
  key = f"FRACTAL_TASKS_PYTHON_{_version}"
438
438
  if _version == current_version:
@@ -498,6 +498,36 @@ class Settings(BaseSettings):
498
498
  Maximum value at which to update `pip` before performing task collection.
499
499
  """
500
500
 
501
+ FRACTAL_VIEWER_AUTHORIZATION_SCHEME: Literal[
502
+ "viewer-paths", "users-folders", "none"
503
+ ] = "none"
504
+ """
505
+ Defines how the list of allowed viewer paths is built.
506
+
507
+ This variable affects the `GET /auth/current-user/allowed-viewer-paths/`
508
+ response, which is then consumed by
509
+ [fractal-vizarr-viewer](https://github.com/fractal-analytics-platform/fractal-vizarr-viewer).
510
+
511
+ Options:
512
+
513
+ - "viewer-paths": The list of allowed viewer paths will include the user's
514
+ `project_dir` along with any path defined in user groups' `viewer_paths`
515
+ attributes.
516
+ - "users-folders": The list will consist of the user's `project_dir` and a
517
+ user-specific folder. The user folder is constructed by concatenating
518
+ the base folder `FRACTAL_VIEWER_BASE_FOLDER` with the user's
519
+ `slurm_user`.
520
+ - "none": An empty list will be returned, indicating no access to
521
+ viewer paths. Useful when vizarr viewer is not used.
522
+ """
523
+
524
+ FRACTAL_VIEWER_BASE_FOLDER: Optional[str] = None
525
+ """
526
+ Base path to Zarr files that will be served by fractal-vizarr-viewer;
527
+ This variable is required and used only when
528
+ FRACTAL_VIEWER_AUTHORIZATION_SCHEME is set to "users-folders".
529
+ """
530
+
501
531
  ###########################################################################
502
532
  # BUSINESS LOGIC
503
533
  ###########################################################################
@@ -589,6 +619,23 @@ class Settings(BaseSettings):
589
619
  if not self.FRACTAL_TASKS_DIR:
590
620
  raise FractalConfigurationError("FRACTAL_TASKS_DIR cannot be None")
591
621
 
622
+ # FRACTAL_VIEWER_BASE_FOLDER is required when
623
+ # FRACTAL_VIEWER_AUTHORIZATION_SCHEME is set to "users-folders"
624
+ # and it must be an absolute path
625
+ if self.FRACTAL_VIEWER_AUTHORIZATION_SCHEME == "users-folders":
626
+ viewer_base_folder = self.FRACTAL_VIEWER_BASE_FOLDER
627
+ if viewer_base_folder is None:
628
+ raise FractalConfigurationError(
629
+ "FRACTAL_VIEWER_BASE_FOLDER is required when "
630
+ "FRACTAL_VIEWER_AUTHORIZATION_SCHEME is set to "
631
+ "users-folders"
632
+ )
633
+ if not Path(viewer_base_folder).is_absolute():
634
+ raise FractalConfigurationError(
635
+ f"Non-absolute value for "
636
+ f"FRACTAL_VIEWER_BASE_FOLDER={viewer_base_folder}"
637
+ )
638
+
592
639
  self.check_db()
593
640
  self.check_runner()
594
641
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: fractal-server
3
- Version: 2.9.0a8
3
+ Version: 2.9.0a9
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,4 +1,4 @@
1
- fractal_server/__init__.py,sha256=VLpRwbtJf-Ix3UM5F6cus-Ipabzl-u3aEANGaiXBtsE,24
1
+ fractal_server/__init__.py,sha256=AgkJcJmAplHlQOvkvgp6iM_-dHeN1ajiKqWDu3YtZwc,24
2
2
  fractal_server/__main__.py,sha256=dEkCfzLLQrIlxsGC-HBfoR-RBMWnJDgNrxYTyzmE9c0,6146
3
3
  fractal_server/alembic.ini,sha256=MWwi7GzjzawI9cCAK1LW7NxIBQDUqD12-ptJoq5JpP0,3153
4
4
  fractal_server/app/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -62,7 +62,7 @@ fractal_server/app/routes/api/v2/workflow_import.py,sha256=WJST1AZypvOTGUrjhomYV
62
62
  fractal_server/app/routes/api/v2/workflowtask.py,sha256=ciHTwXXFiFnMF7ZpJ3Xs0q6YfuZrFvIjqndlzAEdZpo,6969
63
63
  fractal_server/app/routes/auth/__init__.py,sha256=fao6CS0WiAjHDTvBzgBVV_bSXFpEAeDBF6Z6q7rRkPc,1658
64
64
  fractal_server/app/routes/auth/_aux_auth.py,sha256=ifkNocTYatBSMYGwiR14qohmvR9SfMldceiEj6uJBrU,4783
65
- fractal_server/app/routes/auth/current_user.py,sha256=v767HGi8k076ZHoErlU4Vv0_c8HQqYmi8ncjzZZDaDE,4455
65
+ fractal_server/app/routes/auth/current_user.py,sha256=I3aVY5etWAJ_SH6t65Mj5TjvB2X8sAGuu1KG7FxLyPU,5883
66
66
  fractal_server/app/routes/auth/group.py,sha256=dSS7r8J2cejZ6sKnOWAPSDKynxD9VyBNtqDbFpySzIU,7489
67
67
  fractal_server/app/routes/auth/login.py,sha256=tSu6OBLOieoBtMZB4JkBAdEgH2Y8KqPGSbwy7NIypIo,566
68
68
  fractal_server/app/routes/auth/oauth.py,sha256=AnFHbjqL2AgBX3eksI931xD6RTtmbciHBEuGf9YJLjU,1895
@@ -162,7 +162,7 @@ fractal_server/app/schemas/v2/workflow.py,sha256=-KWvXnbHBFA3pj5n7mfSyLKJQSqkJmo
162
162
  fractal_server/app/schemas/v2/workflowtask.py,sha256=vDdMktYbHeYBgB5OuWSv6wRPRXWqvetkeqQ7IC5YtfA,5751
163
163
  fractal_server/app/security/__init__.py,sha256=8Xd4GxumZgvxEH1Vli3ULehwdesEPiaAbtffJvAEgNo,12509
164
164
  fractal_server/app/user_settings.py,sha256=aZgQ3i0JkHfgwLGW1ee6Gzr1ae3IioFfJKKSsSS8Svk,1312
165
- fractal_server/config.py,sha256=1MmVIbnztrFA0w2gYIjgJXg0bqVDsSeSEsMFimb4y74,21153
165
+ fractal_server/config.py,sha256=Bk6EFKnU07sjgThf2NVEqrFAx9F4s0BfCvDKtWHzJTc,23217
166
166
  fractal_server/data_migrations/README.md,sha256=_3AEFvDg9YkybDqCLlFPdDmGJvr6Tw7HRI14aZ3LOIw,398
167
167
  fractal_server/data_migrations/tools.py,sha256=LeMeASwYGtEqd-3wOLle6WARdTGAimoyMmRbbJl-hAM,572
168
168
  fractal_server/gunicorn_fractal.py,sha256=u6U01TLGlXgq1v8QmEpLih3QnsInZD7CqphgJ_GrGzc,1230
@@ -238,8 +238,8 @@ fractal_server/tasks/v2/utils_templates.py,sha256=C5WLuY3uGG2s53OEL-__H35-fmSlgu
238
238
  fractal_server/urls.py,sha256=5o_qq7PzKKbwq12NHSQZDmDitn5RAOeQ4xufu-2v9Zk,448
239
239
  fractal_server/utils.py,sha256=utvmBx8K9I8hRWFquxna2pBaOqe0JifDL_NVPmihEJI,3525
240
240
  fractal_server/zip_tools.py,sha256=GjDgo_sf6V_DDg6wWeBlZu5zypIxycn_l257p_YVKGc,4876
241
- fractal_server-2.9.0a8.dist-info/LICENSE,sha256=QKAharUuhxL58kSoLizKJeZE3mTCBnX6ucmz8W0lxlk,1576
242
- fractal_server-2.9.0a8.dist-info/METADATA,sha256=lJzxJeo2n6DgBq4W6SjhuD0Vq4YL82QbSxBj62aFjcQ,4585
243
- fractal_server-2.9.0a8.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
244
- fractal_server-2.9.0a8.dist-info/entry_points.txt,sha256=8tV2kynvFkjnhbtDnxAqImL6HMVKsopgGfew0DOp5UY,58
245
- fractal_server-2.9.0a8.dist-info/RECORD,,
241
+ fractal_server-2.9.0a9.dist-info/LICENSE,sha256=QKAharUuhxL58kSoLizKJeZE3mTCBnX6ucmz8W0lxlk,1576
242
+ fractal_server-2.9.0a9.dist-info/METADATA,sha256=kVjqPsTd7RPiIlTSbj8CzDM6dZEKzvo23ofH6ylpl2E,4585
243
+ fractal_server-2.9.0a9.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
244
+ fractal_server-2.9.0a9.dist-info/entry_points.txt,sha256=8tV2kynvFkjnhbtDnxAqImL6HMVKsopgGfew0DOp5UY,58
245
+ fractal_server-2.9.0a9.dist-info/RECORD,,