-
Notifications
You must be signed in to change notification settings - Fork 82
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
Add LIST_ENVIRONMENT_DATASETS permission for listing shared datasets and cleanup unused code #1719
Merged
+17
−29
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
import logging | ||
|
||
from dataall.base.db import utils | ||
from dataall.base.db import utils, exceptions | ||
from dataall.base.context import get_context | ||
from dataall.base.aws.sts import SessionHelper | ||
from dataall.base.aws.iam import IAM | ||
|
@@ -10,6 +10,7 @@ | |
from dataall.core.tasks.db.task_models import Task | ||
from dataall.core.tasks.service_handlers import Worker | ||
from dataall.modules.datasets_base.db.dataset_repositories import DatasetBaseRepository | ||
from dataall.modules.datasets_base.services.dataset_list_permissions import LIST_ENVIRONMENT_DATASETS | ||
from dataall.modules.shares_base.db.share_object_models import ShareObject | ||
from dataall.modules.shares_base.db.share_object_repositories import ShareObjectRepository | ||
from dataall.modules.shares_base.db.share_object_item_repositories import ShareObjectItemRepository | ||
|
@@ -173,12 +174,13 @@ def reapply_share_items_for_dataset(uri: str): | |
return True | ||
|
||
@staticmethod | ||
def list_shared_tables_by_env_dataset(dataset_uri: str, env_uri: str): | ||
@ResourcePolicyService.has_resource_permission(LIST_ENVIRONMENT_DATASETS) | ||
def list_shared_tables_by_env_dataset(uri: str, dataset_uri: str): | ||
context = get_context() | ||
with context.db_engine.scoped_session() as session: | ||
log.info( | ||
S3ShareObjectRepository.query_dataset_tables_shared_with_env( | ||
session, env_uri, dataset_uri, context.username, context.groups | ||
session, uri, dataset_uri, context.username, context.groups | ||
) | ||
) | ||
return [ | ||
|
@@ -188,7 +190,7 @@ def list_shared_tables_by_env_dataset(dataset_uri: str, env_uri: str): | |
+ (f'_{res.resourceLinkSuffix}' if res.resourceLinkSuffix else ''), | ||
} | ||
for res in S3ShareObjectRepository.query_dataset_tables_shared_with_env( | ||
session, env_uri, dataset_uri, context.username, context.groups | ||
session, uri, dataset_uri, context.username, context.groups | ||
) | ||
] | ||
|
||
|
@@ -259,11 +261,17 @@ def get_s3_consumption_data(uri): | |
} | ||
|
||
@staticmethod | ||
def list_shared_databases_tables_with_env_group(environmentUri: str, groupUri: str): | ||
@ResourcePolicyService.has_resource_permission(LIST_ENVIRONMENT_DATASETS) | ||
def list_shared_databases_tables_with_env_group(uri: str, group_uri: str): | ||
context = get_context() | ||
if group_uri not in context.groups: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This condition (or the similar ones) is widely used. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
raise exceptions.UnauthorizedOperation( | ||
action='LIST_ENVIRONMENT_GROUP_DATASETS', | ||
message=f'User: {context.username} is not a member of the owner team', | ||
) | ||
with context.db_engine.scoped_session() as session: | ||
return S3ShareObjectRepository.query_shared_glue_databases( | ||
session=session, groups=context.groups, env_uri=environmentUri, group_uri=groupUri | ||
session=session, groups=context.groups, env_uri=uri, group_uri=group_uri | ||
) | ||
|
||
@staticmethod | ||
|
@@ -303,7 +311,7 @@ def list_table_data_filters_by_attached(uri: str, data: dict): | |
) | ||
|
||
@staticmethod | ||
def resolve_shared_db_name(GlueDatabaseName: str, shareUri: str, targetEnvAwsAccountId: str, targetEnvRegion: str): | ||
def resolve_shared_db_name(GlueDatabaseName: str, shareUri: str): | ||
with get_context().db_engine.scoped_session() as session: | ||
share = ShareObjectRepository.get_share_by_uri(session, shareUri) | ||
dataset = DatasetBaseRepository.get_dataset_by_uri(session, share.datasetUri) | ||
|
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if removing here - should we not remove
def list_profiling_runs(session, dataset_uri)
fromdataall/backend/dataall/modules/s3_datasets/db/dataset_profiling_repositories.py
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, cleaned up!