-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor: uncouple datasets and dataset_sharing modules - part 2 (#1185)
### Feature or Bugfix - Refactoring ### Detail Remove and move logic from dataset to datasets_sharing module. This is needed as explained in full PR [AFTER 2.4] Refactor: uncouple datasets and dataset_sharing modules #1179 - [X] Moves the verify dataset shares mutation to the datasets_sharing module - [X] Move dataset_subscription task to dataset_sharing - [X] Move listDatasetShares query to dataset_sharing module - [X] Remove unused `shares` field from the Dataset graphql type as it was not used in the frontend: listDatasets, listOwnedDatasets, listDatasetsOwnedByEnvGroup, listDatasetsCreatedInEnvironment and getDataset - [x] Move getSharedDatasetTables to data_sharing module and fix reference to DatasetService I am aware that some of the queries and mutations that this PR moves look a bit odd in the dataset_sharing module, but this will be solved once data sharing is divided into dataset_sharing_base and s3_dataset_sharing. ### Relates #1179 ### Security Please answer the questions below briefly where applicable, or write `N/A`. Based on [OWASP 10](https://owasp.org/Top10/en/). - Does this PR introduce or modify any input fields or queries - this includes fetching data from storage outside the application (e.g. a database, an S3 bucket)? - Is the input sanitized? - What precautions are you taking before deserializing the data you consume? - Is injection prevented by parametrizing queries? - Have you ensured no `eval` or similar functions are used? - Does this PR introduce any functionality or component that requires authorization? - How have you ensured it respects the existing AuthN/AuthZ mechanisms? - Are you logging failed auth attempts? - Are you using or adding any cryptographic features? - Do you use a standard proven implementations? - Are the used keys controlled by the customer? Where are they stored? - Are you introducing any new policies/roles/users? - Have you used the least-privilege principle? How? By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
- Loading branch information
Showing
23 changed files
with
159 additions
and
295 deletions.
There are no files selected for viewing
This file contains 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 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 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 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
51 changes: 51 additions & 0 deletions
51
backend/dataall/modules/dataset_sharing/services/dataset_sharing_service.py
This file contains 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,51 @@ | ||
from dataall.core.permissions.services.resource_policy_service import ResourcePolicyService | ||
from dataall.core.permissions.services.tenant_policy_service import TenantPolicyService | ||
from dataall.base.context import get_context | ||
from dataall.modules.dataset_sharing.db.share_object_repositories import ( | ||
ShareObjectRepository, | ||
ShareItemSM, | ||
) | ||
from dataall.modules.dataset_sharing.services.share_item_service import ShareItemService | ||
from dataall.modules.datasets.services.dataset_permissions import ( | ||
MANAGE_DATASETS, | ||
UPDATE_DATASET, | ||
) | ||
|
||
from dataall.modules.datasets_base.db.dataset_models import Dataset | ||
|
||
import logging | ||
|
||
log = logging.getLogger(__name__) | ||
|
||
|
||
class DatasetSharingService: | ||
@staticmethod | ||
@TenantPolicyService.has_tenant_permission(MANAGE_DATASETS) | ||
@ResourcePolicyService.has_resource_permission(UPDATE_DATASET) | ||
def verify_dataset_share_objects(uri: str, share_uris: list): | ||
with get_context().db_engine.scoped_session() as session: | ||
for share_uri in share_uris: | ||
share = ShareObjectRepository.get_share_by_uri(session, share_uri) | ||
states = ShareItemSM.get_share_item_revokable_states() | ||
items = ShareObjectRepository.list_shareable_items( | ||
session, share, states, {'pageSize': 1000, 'isShared': True} | ||
) | ||
item_uris = [item.shareItemUri for item in items.get('nodes', [])] | ||
ShareItemService.verify_items_share_object(uri=share_uri, item_uris=item_uris) | ||
return True | ||
|
||
@staticmethod | ||
def list_dataset_share_objects(dataset: Dataset, data: dict = None): | ||
with get_context().db_engine.scoped_session() as session: | ||
return ShareObjectRepository.paginated_dataset_shares(session=session, uri=dataset.datasetUri, data=data) | ||
|
||
@staticmethod | ||
def list_shared_tables_by_env_dataset(dataset_uri: str, env_uri: str): | ||
context = get_context() | ||
with context.db_engine.scoped_session() as session: | ||
return [ | ||
{'tableUri': t.tableUri, 'GlueTableName': t.GlueTableName} | ||
for t in ShareObjectRepository.query_dataset_tables_shared_with_env( | ||
session, env_uri, dataset_uri, context.username, context.groups | ||
) | ||
] |
This file contains 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
File renamed without changes.
File renamed without changes.
This file contains 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 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 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 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 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 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 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
Oops, something went wrong.