-
Notifications
You must be signed in to change notification settings - Fork 32
🎨 moving folders to workspaces #6851
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
sanderegg
merged 40 commits into
ITISFoundation:master
from
matusdrobuliak66:move-folder-between-workspaced
Dec 3, 2024
Merged
Changes from 15 commits
Commits
Show all changes
40 commits
Select commit
Hold shift + click to select a range
496bba5
api and handlers
matusdrobuliak66 fcd0701
db
matusdrobuliak66 29f67de
Merge branch 'master' into move-folder-between-workspaced
matusdrobuliak66 33b48e6
open api specs
matusdrobuliak66 f9c7c0b
Merge branch 'master' into move-folder-between-workspaced
matusdrobuliak66 dc092c2
adding unit tests
matusdrobuliak66 3f8e8b1
adding unit tests
matusdrobuliak66 e6908f0
refactor project DB
matusdrobuliak66 57b63b1
adding transaction
matusdrobuliak66 5e8e5e3
open api specs
matusdrobuliak66 f45879c
final cleanup
matusdrobuliak66 1ce4f4e
final cleanup
matusdrobuliak66 b7ee5cf
final cleanup
matusdrobuliak66 470716f
open api specs
matusdrobuliak66 e2d205e
open api specs
matusdrobuliak66 4b87ce3
review @pcrespov
matusdrobuliak66 0ac8e2d
Merge branch 'master' into move-folder-between-workspaced
matusdrobuliak66 0d71046
review @pcrespov
matusdrobuliak66 96d9b93
Merge branch 'master' into move-folder-between-workspaced
matusdrobuliak66 7061af7
review @pcrespov
matusdrobuliak66 b77602c
open api specs
matusdrobuliak66 6f43ade
Merge branch 'move-folder-between-workspaced' of github.com:matusdrob…
matusdrobuliak66 4e4675f
frontend changes
matusdrobuliak66 c37f3dc
clieaning
matusdrobuliak66 0fb74d4
frontend changes
matusdrobuliak66 c2f63e9
fix
matusdrobuliak66 f2cad55
Merge branch 'master' into move-folder-between-workspaced
matusdrobuliak66 7a9284c
Merge branch 'master' into move-folder-between-workspaced
matusdrobuliak66 6e3ed2a
fix
matusdrobuliak66 d03a496
fix
matusdrobuliak66 64758ff
fix
matusdrobuliak66 4dfa541
fix
matusdrobuliak66 763586a
fix
matusdrobuliak66 6e287d9
fix
matusdrobuliak66 21619d9
Merge branch 'master' into move-folder-between-workspaced
matusdrobuliak66 cd50981
Merge branch 'master' into move-folder-between-workspaced
matusdrobuliak66 5c785d2
fix
matusdrobuliak66 a9d5436
fix
matusdrobuliak66 658b167
Merge branch 'master' into move-folder-between-workspaced
matusdrobuliak66 eabeafb
fix
matusdrobuliak66 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
matusdrobuliak66 marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
138 changes: 138 additions & 0 deletions
138
services/web/server/src/simcore_service_webserver/folders/_workspaces_api.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,138 @@ | ||
| import logging | ||
|
|
||
| from aiohttp import web | ||
| from models_library.folders import FolderID | ||
| from models_library.products import ProductName | ||
| from models_library.users import UserID | ||
| from models_library.workspaces import WorkspaceID | ||
| from simcore_postgres_database.utils_repos import transaction_context | ||
|
|
||
| from ..db.plugin import get_asyncpg_engine | ||
| from ..projects import _db_v2 as projects_db | ||
| from ..projects import _folders_db as project_to_folders_db | ||
| from ..projects import _groups_db as project_groups_db | ||
| from ..projects._access_rights_api import check_user_project_permission | ||
| from ..users.api import get_user | ||
| from ..workspaces.api import check_user_workspace_access | ||
| from . import _folders_db | ||
|
|
||
| _logger = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| async def move_folder_into_workspace( | ||
| app: web.Application, | ||
| *, | ||
| user_id: UserID, | ||
| folder_id: FolderID, | ||
| workspace_id: WorkspaceID | None, | ||
| product_name: ProductName, | ||
| ) -> None: | ||
| # 1. User needs to have delete permission on source folder | ||
| folder_db = await _folders_db.get( | ||
| app, folder_id=folder_id, product_name=product_name | ||
| ) | ||
| workspace_is_private = True | ||
| if folder_db.workspace_id: | ||
| await check_user_workspace_access( | ||
| app, | ||
| user_id=user_id, | ||
| workspace_id=folder_db.workspace_id, | ||
| product_name=product_name, | ||
| permission="delete", | ||
| ) | ||
| workspace_is_private = False | ||
|
|
||
| # 2. User needs to have write permission on destination workspace | ||
| if workspace_id is not None: | ||
| await check_user_workspace_access( | ||
| app, | ||
| user_id=user_id, | ||
| workspace_id=workspace_id, | ||
| product_name=product_name, | ||
| permission="write", | ||
| ) | ||
|
|
||
| # 3. User needs to have delete permission on all the projects inside source folder | ||
| ( | ||
| folder_ids, | ||
| project_ids, | ||
| ) = await _folders_db.get_all_folders_and_projects_recursively( | ||
| app, | ||
| connection=None, | ||
| folder_id=folder_id, | ||
| private_workspace_user_id_or_none=user_id if workspace_is_private else None, | ||
| product_name=product_name, | ||
| ) | ||
| # NOTE: Not the most effective, can be improved | ||
| for project_id in project_ids: | ||
| await check_user_project_permission( | ||
matusdrobuliak66 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| app, | ||
| project_id=project_id, | ||
| user_id=user_id, | ||
| product_name=product_name, | ||
| permission="delete", | ||
| ) | ||
|
|
||
| # ⬆️ Here we have already guaranties that user has all the right permissions to do this operation ⬆️ | ||
|
|
||
| async with transaction_context(get_asyncpg_engine(app)) as conn: | ||
| # 4. Update workspace ID on the project resource | ||
| for project_id in project_ids: | ||
| await projects_db.patch_project( | ||
matusdrobuliak66 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| app=app, | ||
| connection=conn, | ||
| project_uuid=project_id, | ||
| new_partial_project_data={"workspace_id": workspace_id}, | ||
| ) | ||
|
|
||
| # 5. BATCH update of folders with workspace_id | ||
| await _folders_db.update( | ||
| app, | ||
| connection=conn, | ||
| folders_id_or_ids=set(folder_ids), | ||
matusdrobuliak66 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| product_name=product_name, | ||
| workspace_id=workspace_id, # <-- Updating workspace_id | ||
| user_id=user_id if workspace_id is None else None, # <-- Updating user_id | ||
| ) | ||
|
|
||
| # 6. Update source folder parent folder ID with NULL (it will appear in the root directory) | ||
| await _folders_db.update( | ||
| app, | ||
| connection=conn, | ||
| folders_id_or_ids=folder_id, | ||
| product_name=product_name, | ||
| parent_folder_id=None, # <-- Updating parent folder ID | ||
| ) | ||
|
|
||
| # 7. Remove all records of project to folders that are not in the folders that we are moving | ||
| # (ex. If we are moving from private workspace, the same project can be in different folders for different users) | ||
| await project_to_folders_db.delete_all_project_to_folder_by_project_ids_not_in_folder_ids( | ||
| app, | ||
| connection=conn, | ||
| project_id_or_ids=set(project_ids), | ||
| not_in_folder_ids=set(folder_ids), | ||
| ) | ||
|
|
||
| # 8. Update the user id field for the remaining folders | ||
| await project_to_folders_db.update_project_to_folder( | ||
| app, | ||
| connection=conn, | ||
| folders_id_or_ids=set(folder_ids), | ||
| user_id=user_id if workspace_id is None else None, # <-- Updating user_id | ||
| ) | ||
|
|
||
| # 9. Remove all project permissions, leave only the user who moved the project | ||
| user = await get_user(app, user_id=user_id) | ||
| for project_id in project_ids: | ||
| await project_groups_db.delete_all_project_groups( | ||
matusdrobuliak66 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| app, connection=conn, project_id=project_id | ||
| ) | ||
| await project_groups_db.update_or_insert_project_group( | ||
| app, | ||
| connection=conn, | ||
| project_id=project_id, | ||
| group_id=user["primary_gid"], | ||
| read=True, | ||
| write=True, | ||
| delete=True, | ||
| ) | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.