-
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
Generic dataset module and specific s3_datasets module - part 5 (Move DatasetServiceInterface to datasets_base, add property, create first list API for datasets_base) #1281
Merged
Merged
Changes from 35 commits
Commits
Show all changes
36 commits
Select commit
Hold shift + click to select a range
035a637
Rename datasets to s3_datasets
dlpzx aa99257
Rename datasets to s3_datasets
dlpzx 8ea5ca2
Rename datasets to s3_datasets
dlpzx 2ad4a2e
Fix references to config in frontend
dlpzx 59d4c93
Merge branch 'refs/heads/main' into feat/generic-dataset-model-refact…
dlpzx 17fe992
Fix s3_dataset references frontend
dlpzx 2c333a2
Added datasets_base module and dependencies
dlpzx 7d66809
Moved dataset_enums to datasets_base
dlpzx 38a2275
Use S3Dataset instead of Dataset in s3_dataset module
dlpzx fe71766
Use S3Dataset instead of Dataset in dataset_sharing module
dlpzx 3985167
Use S3Dataset instead of Dataset in tests+some missing in modules
dlpzx f05a4f6
Use S3Dataset instead of Dataset in migration scripts and init
dlpzx aacd1f0
Fix foreign key between datasetBase and s3dataset
dlpzx 41db8ed
Fix migration references to Dataset and add new migration script with…
dlpzx b3849cd
Added first draft of migration scripts
dlpzx 313dd89
Merge remote-tracking branch 'refs/remotes/origin/main' into feat/gen…
dlpzx 7e287d1
Fix details of init files
dlpzx 98660df
Finis migration scripts
dlpzx c4ec66d
Add datasets_base in config.json
dlpzx 58ea763
Merge remote-tracking branch 'refs/remotes/origin/feat/generic-datase…
dlpzx 449d689
Merge remote-tracking branch 'refs/remotes/origin/main' into feat/gen…
dlpzx 5d472e8
Adapt permission resourceType to DatasetBase
dlpzx 8a573da
Adapt permission resourceType to DatasetBase
dlpzx b806100
linting
dlpzx b31922f
Fix issues in foreign keys migration scripts
dlpzx ffe372e
PR review comments - fix downgrade and add enums to dataset tables
dlpzx a98632f
Move DatasetLock and Activity to DatasetBaseRepository
dlpzx 9e9415b
Move DatasetLock model
dlpzx 3a6765e
Fixes from PR review: stewards and polymorphic definition with enum
dlpzx 8939faa
Move DatasetServiceInterface to datasets_base, add property, create f…
dlpzx 8f1605e
Adapt initialization of datasetBase module and FE response to listDat…
dlpzx 254b23b
Merge branch 'refs/heads/feat/generic-dataset-model-refactoring-3' in…
dlpzx 8219f22
Merge branch 'refs/heads/feat/generic-dataset-model-refactoring-4' in…
dlpzx 132970b
Make changes to frontend to show generic info
dlpzx 933ce1f
Merge branch 'refs/heads/main' into feat/generic-dataset-model-refact…
dlpzx f39296f
Better typing hints
dlpzx 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
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,5 @@ | ||
"""The package defines the schema for Dataset_base lists""" | ||
|
||
from dataall.modules.datasets_base.api import input_types, queries, types, resolvers | ||
|
||
__all__ = ['types', 'input_types', 'queries', 'resolvers'] |
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,27 @@ | ||
from dataall.base.api import gql | ||
from dataall.base.api.constants import SortDirection | ||
from dataall.modules.datasets_base.services.datasets_enums import DatasetSortField | ||
|
||
|
||
DatasetSortCriteria = gql.InputType( | ||
name='DatasetSortCriteria', | ||
arguments=[ | ||
gql.Argument(name='field', type=gql.NonNullableType(DatasetSortField.toGraphQLEnum())), | ||
gql.Argument(name='direction', type=SortDirection.toGraphQLEnum()), | ||
], | ||
) | ||
|
||
|
||
DatasetFilter = gql.InputType( | ||
name='DatasetFilter', | ||
arguments=[ | ||
gql.Argument('term', gql.String), | ||
gql.Argument('roles', gql.ArrayType(gql.Ref('DatasetRole'))), | ||
gql.Argument('InProject', gql.String), | ||
gql.Argument('notInProject', gql.String), | ||
gql.Argument('displayArchived', gql.Boolean), | ||
gql.Argument('sort', gql.ArrayType(DatasetSortCriteria)), | ||
gql.Argument('page', gql.Integer), | ||
gql.Argument('pageSize', gql.Integer), | ||
], | ||
) |
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,13 @@ | ||
from dataall.base.api import gql | ||
from dataall.modules.datasets_base.api.input_types import DatasetFilter | ||
from dataall.modules.datasets_base.api.resolvers import ( | ||
list_all_user_datasets, | ||
) | ||
from dataall.modules.datasets_base.api.types import DatasetBaseSearchResult | ||
|
||
listDatasets = gql.QueryField( | ||
name='listDatasets', | ||
args=[gql.Argument('filter', DatasetFilter)], | ||
type=DatasetBaseSearchResult, | ||
resolver=list_all_user_datasets, | ||
) |
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,71 @@ | ||
import logging | ||
|
||
from dataall.base.api.context import Context | ||
from dataall.core.environment.services.environment_service import EnvironmentService | ||
from dataall.core.organizations.db.organization_repositories import OrganizationRepository | ||
from dataall.core.stacks.services.stack_service import StackService | ||
from dataall.modules.datasets_base.services.dataset_list_service import DatasetListService | ||
from dataall.modules.datasets_base.services.datasets_enums import DatasetRole | ||
from dataall.modules.datasets_base.db.dataset_models import DatasetBase | ||
|
||
log = logging.getLogger(__name__) | ||
|
||
|
||
def list_all_user_datasets(context: Context, source, filter: dict = None): | ||
if not filter: | ||
filter = {'page': 1, 'pageSize': 5} | ||
return DatasetListService.list_all_user_datasets(filter) | ||
|
||
|
||
def resolve_user_role(context: Context, source: DatasetBase, **kwargs): | ||
if not source: | ||
return None | ||
if source.owner == context.username: | ||
return DatasetRole.Creator.value | ||
elif source.SamlAdminGroupName in context.groups: | ||
return DatasetRole.Admin.value | ||
elif source.stewards in context.groups: | ||
return DatasetRole.DataSteward.value | ||
else: | ||
with context.engine.scoped_session() as session: | ||
other_modules_user_role = DatasetListService.get_other_modules_dataset_user_role( | ||
session, source.datasetUri, context.username, context.groups | ||
) | ||
if other_modules_user_role is not None: | ||
return other_modules_user_role | ||
return DatasetRole.NoPermission.value | ||
|
||
|
||
def get_dataset_organization(context, source: DatasetBase, **kwargs): | ||
if not source: | ||
return None | ||
with context.engine.scoped_session() as session: | ||
return OrganizationRepository.get_organization_by_uri(session, source.organizationUri) | ||
|
||
|
||
def get_dataset_environment(context, source: DatasetBase, **kwargs): | ||
if not source: | ||
return None | ||
with context.engine.scoped_session() as session: | ||
return EnvironmentService.get_environment_by_uri(session, source.environmentUri) | ||
|
||
|
||
def get_dataset_owners_group(context, source: DatasetBase, **kwargs): | ||
if not source: | ||
return None | ||
return source.SamlAdminGroupName | ||
|
||
|
||
def get_dataset_stewards_group(context, source: DatasetBase, **kwargs): | ||
if not source: | ||
return None | ||
return source.stewards | ||
|
||
|
||
def resolve_dataset_stack(context: Context, source: DatasetBase, **kwargs): | ||
if not source: | ||
return None | ||
return StackService.get_stack_with_cfn_resources( | ||
targetUri=source.datasetUri, | ||
environmentUri=source.environmentUri, | ||
) |
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,79 @@ | ||
from dataall.base.api import gql | ||
from dataall.modules.datasets_base.services.datasets_enums import DatasetRole | ||
from dataall.modules.datasets_base.api.resolvers import ( | ||
get_dataset_environment, | ||
get_dataset_organization, | ||
get_dataset_owners_group, | ||
get_dataset_stewards_group, | ||
resolve_user_role, | ||
resolve_dataset_stack, | ||
) | ||
from dataall.core.environment.api.enums import EnvironmentPermission | ||
|
||
DatasetBase = gql.ObjectType( | ||
name='DatasetBase', | ||
fields=[ | ||
gql.Field(name='datasetUri', type=gql.ID), | ||
gql.Field(name='datasetType', type=gql.String), | ||
gql.Field(name='label', type=gql.String), | ||
gql.Field(name='name', type=gql.String), | ||
gql.Field(name='description', type=gql.String), | ||
gql.Field(name='tags', type=gql.ArrayType(gql.String)), | ||
gql.Field(name='owner', type=gql.String), | ||
gql.Field(name='created', type=gql.String), | ||
gql.Field(name='updated', type=gql.String), | ||
gql.Field(name='admins', type=gql.ArrayType(gql.String)), | ||
gql.Field(name='AwsAccountId', type=gql.String), | ||
gql.Field(name='region', type=gql.String), | ||
gql.Field(name='SamlAdminGroupName', type=gql.String), | ||
gql.Field(name='businessOwnerEmail', type=gql.String), | ||
gql.Field(name='businessOwnerDelegationEmails', type=gql.ArrayType(gql.String)), | ||
gql.Field(name='imported', type=gql.Boolean), | ||
gql.Field( | ||
name='environment', | ||
type=gql.Ref('Environment'), | ||
resolver=get_dataset_environment, | ||
), | ||
gql.Field( | ||
name='organization', | ||
type=gql.Ref('Organization'), | ||
resolver=get_dataset_organization, | ||
), | ||
gql.Field( | ||
name='owners', | ||
type=gql.String, | ||
resolver=get_dataset_owners_group, | ||
), | ||
gql.Field( | ||
name='stewards', | ||
type=gql.String, | ||
resolver=get_dataset_stewards_group, | ||
), | ||
gql.Field( | ||
name='userRoleForDataset', | ||
type=DatasetRole.toGraphQLEnum(), | ||
resolver=resolve_user_role, | ||
), | ||
gql.Field(name='userRoleInEnvironment', type=EnvironmentPermission.toGraphQLEnum()), | ||
gql.Field(name='topics', type=gql.ArrayType(gql.Ref('Topic'))), | ||
gql.Field(name='confidentiality', type=gql.String), | ||
gql.Field(name='language', type=gql.Ref('Language')), | ||
gql.Field(name='autoApprovalEnabled', type=gql.Boolean), | ||
gql.Field(name='stack', type=gql.Ref('Stack'), resolver=resolve_dataset_stack), | ||
], | ||
) | ||
|
||
DatasetBaseSearchResult = gql.ObjectType( | ||
name='DatasetBaseSearchResult', | ||
fields=[ | ||
gql.Field(name='count', type=gql.Integer), | ||
gql.Field(name='nodes', type=gql.ArrayType(DatasetBase)), | ||
gql.Field(name='pageSize', type=gql.Integer), | ||
gql.Field(name='nextPage', type=gql.Integer), | ||
gql.Field(name='pages', type=gql.Integer), | ||
gql.Field(name='page', type=gql.Integer), | ||
gql.Field(name='previousPage', type=gql.Integer), | ||
gql.Field(name='hasNext', type=gql.Boolean), | ||
gql.Field(name='hasPrevious', type=gql.Boolean), | ||
], | ||
) |
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
45 changes: 45 additions & 0 deletions
45
backend/dataall/modules/datasets_base/services/dataset_list_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,45 @@ | ||
import logging | ||
from typing import List | ||
from dataall.modules.datasets_base.services.dataset_service_interface import DatasetServiceInterface | ||
from dataall.base.context import get_context | ||
from dataall.modules.datasets_base.db.dataset_repositories import DatasetListRepository | ||
|
||
log = logging.getLogger(__name__) | ||
|
||
|
||
class DatasetListService: | ||
_interfaces: List[DatasetServiceInterface] = [] | ||
|
||
@classmethod | ||
def register(cls, interface: DatasetServiceInterface): | ||
cls._interfaces.append(interface) | ||
|
||
@classmethod | ||
def _list_all_user_interface_datasets(cls, session, username, groups) -> List: | ||
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. Does this return |
||
"""All list_datasets from other modules that need to be appended to the list of datasets""" | ||
return [ | ||
query | ||
for interface in cls._interfaces | ||
for query in [interface.append_to_list_user_datasets(session, username, groups)] | ||
if query.first() is not None | ||
] | ||
|
||
@classmethod | ||
def get_other_modules_dataset_user_role(cls, session, uri, username, groups) -> str: | ||
"""All other user role types that might come from other modules""" | ||
for interface in cls._interfaces: | ||
role = interface.resolve_additional_dataset_user_role(session, uri, username, groups) | ||
if role is not None: | ||
return role | ||
return None | ||
|
||
@staticmethod | ||
def list_all_user_datasets(data: dict): | ||
context = get_context() | ||
with context.db_engine.scoped_session() as session: | ||
all_subqueries = DatasetListService._list_all_user_interface_datasets( | ||
session, context.username, context.groups | ||
) | ||
return DatasetListRepository.paginated_all_user_datasets( | ||
session, context.username, context.groups, all_subqueries, data=data | ||
) |
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.
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.
I assume
all_subqueries
is of typeList[Query]
?