Skip to content
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

925 datasets auto approval #988

Merged
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,17 @@ def submit_share_object(cls, uri: str):
share=share
).notify_share_object_submission(email_id=context.username)

# if parent dataset has auto-approve flag, we trigger the next transition to approved state
if dataset.autoApprovalEnabled:
ResourcePolicy.attach_resource_policy(
session=session,
group=share.groupUri,
permissions=SHARE_OBJECT_APPROVER,
resource_uri=share.shareUri,
resource_type=ShareObject.__name__,
)
share = cls.approve_share_object(uri=share.shareUri)

return share

@classmethod
Expand Down Expand Up @@ -236,7 +247,6 @@ def approve_share_object(cls, uri: str):
session.add(approve_share_task)

Worker.queue(engine=context.db_engine, task_ids=[approve_share_task.taskUri])

return share

@staticmethod
Expand Down
4 changes: 4 additions & 0 deletions backend/dataall/modules/datasets/api/dataset/input_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
),
gql.Argument('confidentiality', gql.Ref('ConfidentialityClassification')),
gql.Argument(name='stewards', type=gql.String),
gql.Argument(name='autoApprovalEnabled', type=gql.Boolean)
],
)

Expand All @@ -38,6 +39,7 @@
gql.Argument('confidentiality', gql.Ref('ConfidentialityClassification')),
gql.Argument(name='stewards', type=gql.String),
gql.Argument('KmsAlias', gql.NonNullableType(gql.String)),
gql.Argument(name='autoApprovalEnabled', type=gql.Boolean)
],
)

Expand Down Expand Up @@ -103,5 +105,7 @@
),
gql.Argument('confidentiality', gql.Ref('ConfidentialityClassification')),
gql.Argument(name='stewards', type=gql.String),
gql.Argument(name='autoApprovalEnabled', type=gql.Boolean)

],
)
1 change: 1 addition & 0 deletions backend/dataall/modules/datasets/api/dataset/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@
type=gql.Boolean,
),
gql.Field(name='stack', type=gql.Ref('Stack'), resolver=get_dataset_stack),
gql.Field(name='autoApprovalEnabled', type=gql.Boolean),
],
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ def create_dataset(uri, admin_group, data: dict):
resource_uri=dataset.datasetUri,
resource_type=Dataset.__name__,
)

if environment.SamlGroupName != dataset.SamlAdminGroupName:
ResourcePolicy.attach_resource_policy(
session=session,
Expand Down
2 changes: 2 additions & 0 deletions backend/dataall/modules/datasets_base/db/dataset_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@ class Dataset(Resource, Base):
importedAdminRole = Column(Boolean, default=False)
imported = Column(Boolean, default=False)

autoApprovalEnabled = Column(Boolean, default=False)

@classmethod
def uri(cls):
return cls.datasetUri
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ def build_dataset(cls, username: str, env: Environment, data: dict) -> Dataset:
stewards=data.get('stewards')
if data.get('stewards')
else data['SamlAdminGroupName'],
autoApprovalEnabled=data.get('autoApprovalEnabled', False),
)
cls._set_dataset_aws_resources(dataset, data, env)
cls._set_import_data(dataset, data)
Expand Down Expand Up @@ -177,7 +178,7 @@ def paginated_dataset_tables(session, uri, data=None) -> dict:
).to_dict()

@staticmethod
def update_dataset_activity(session, dataset, username) :
def update_dataset_activity(session, dataset, username):
activity = Activity(
action='dataset:update',
label='dataset:update',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
"""_dataset_autoapproval_field

Revision ID: f6cd4ba7dd8d
Revises: 71a5f5de322f
Create Date: 2024-01-16 13:49:29.527312

"""
from alembic import op
import sqlalchemy as sa

# revision identifiers, used by Alembic.
revision = 'f6cd4ba7dd8d'
down_revision = '71a5f5de322f'
branch_labels = None
depends_on = None


def upgrade():
op.add_column('dataset', sa.Column('autoApprovalEnabled', sa.Boolean(), default=False))


def downgrade():
op.drop_column('dataset', 'autoApprovalEnabled')
10 changes: 10 additions & 0 deletions frontend/src/modules/Datasets/components/DatasetGovernance.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,16 @@ export const DatasetGovernance = (props) => {
{dataset.stewards}
</Typography>
</CardContent>
<CardContent>
<Typography color="textSecondary" variant="subtitle2">
Auto-Approval
</Typography>
<Box sx={{ mt: 1 }}>
<Label color="primary">
{dataset.autoApprovalEnabled ? 'Enabled' : 'Disabled'}
</Label>
</Box>
</CardContent>
<CardContent>
<Typography color="textSecondary" variant="subtitle2">
Classification
Expand Down
32 changes: 27 additions & 5 deletions frontend/src/modules/Datasets/views/DatasetCreateForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@ const DatasetCreateForm = (props) => {
tags: values.tags,
description: values.description,
topics: values.topics ? values.topics.map((t) => t.value) : [],
confidentiality: values.confidentiality
confidentiality: values.confidentiality,
autoApprovalEnabled: values.autoApprovalEnabled
})
);
if (!response.errors) {
Expand Down Expand Up @@ -214,7 +215,8 @@ const DatasetCreateForm = (props) => {
confidentiality: '',
SamlGroupName: '',
tags: [],
topics: []
topics: [],
autoApprovalEnabled: false
}}
validationSchema={Yup.object().shape({
label: Yup.string()
Expand All @@ -230,7 +232,10 @@ const DatasetCreateForm = (props) => {
stewards: Yup.string().max(255).nullable(),
confidentiality: Yup.string()
.max(255)
.required('*Confidentiality is required')
.required('*Confidentiality is required'),
autoApprovalEnabled: Yup.boolean().required(
'*AutoApproval property is required'
)
})}
onSubmit={async (
values,
Expand Down Expand Up @@ -263,7 +268,6 @@ const DatasetCreateForm = (props) => {
name="label"
onBlur={handleBlur}
onChange={handleChange}
value={values.label}
variant="outlined"
/>
</CardContent>
Expand Down Expand Up @@ -300,7 +304,7 @@ const DatasetCreateForm = (props) => {
)}
</CardContent>
</Card>
<Card sx={{ mt: 3 }}>
<Card sx={{ mt: 4 }}>
<CardHeader title="Classification" />
<CardContent>
<TextField
Expand Down Expand Up @@ -368,6 +372,24 @@ const DatasetCreateForm = (props) => {
/>
</Box>
</CardContent>
<CardContent>
<TextField
fullWidth
label="Auto Approval"
name="autoApprovalEnabled"
onChange={handleChange}
select
value={values.autoApprovalEnabled}
variant="outlined"
>
<MenuItem key={'Enabled'} value={true}>
Enabled
</MenuItem>
<MenuItem key={'Enabled'} value={false}>
Disabled
</MenuItem>
</TextField>
</CardContent>
</Card>
</Grid>
<Grid item lg={5} md={5} xs={12}>
Expand Down
27 changes: 25 additions & 2 deletions frontend/src/modules/Datasets/views/DatasetEditForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,8 @@ const DatasetEditForm = (props) => {
? values.terms.nodes.map((t) => t.nodeUri)
: values.terms.map((t) => t.nodeUri),
confidentiality: values.confidentiality,
KmsAlias: values.KmsAlias
KmsAlias: values.KmsAlias,
autoApprovalEnabled: values.autoApprovalEnabled
}
})
);
Expand Down Expand Up @@ -261,7 +262,8 @@ const DatasetEditForm = (props) => {
terms: dataset.terms || [],
stewards: dataset.stewards,
confidentiality: dataset.confidentiality,
KmsAlias: dataset.KmsAlias
KmsAlias: dataset.KmsAlias,
autoApprovalEnabled: dataset.autoApprovalEnabled
}}
validationSchema={Yup.object().shape({
label: Yup.string()
Expand All @@ -273,6 +275,9 @@ const DatasetEditForm = (props) => {
tags: Yup.array().min(1).required('*Tags are required'),
confidentiality: Yup.string().required(
'*Confidentiality is required'
),
autoApprovalEnabled: Yup.boolean().required(
'*AutoApproval property is required'
)
})}
onSubmit={async (
Expand Down Expand Up @@ -453,6 +458,24 @@ const DatasetEditForm = (props) => {
/>
</Box>
</CardContent>
<CardContent>
<TextField
fullWidth
label="Auto Approval"
name="autoApprovalEnabled"
onChange={handleChange}
select
value={values.autoApprovalEnabled}
variant="outlined"
>
<MenuItem key={'Enabled'} value={true}>
Enabled
</MenuItem>
<MenuItem key={'Enabled'} value={false}>
Disabled
</MenuItem>
</TextField>
</CardContent>
</Card>
</Grid>
<Grid item lg={5} md={5} xs={12}>
Expand Down
29 changes: 26 additions & 3 deletions frontend/src/modules/Datasets/views/DatasetImportForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,8 @@ const DatasetImportForm = (props) => {
KmsKeyAlias: values.KmsKeyAlias,
glueDatabaseName: values.glueDatabaseName,
stewards: values.stewards,
confidentiality: values.confidentiality
confidentiality: values.confidentiality,
autoApprovalEnabled: values.autoApprovalEnabled
})
);
if (!response.errors) {
Expand Down Expand Up @@ -222,7 +223,8 @@ const DatasetImportForm = (props) => {
glueDatabaseName: '',
bucketName: '',
KmsKeyAlias: '',
confidentiality: ''
confidentiality: '',
autoApprovalEnabled: false
}}
validationSchema={Yup.object().shape({
label: Yup.string()
Expand All @@ -242,7 +244,10 @@ const DatasetImportForm = (props) => {
.required('*S3 bucket name is required'),
confidentiality: Yup.string()
.max(255)
.required('*Confidentiality is required')
.required('*Confidentiality is required'),
autoApprovalEnabled: Yup.boolean().required(
'*AutoApproval property is required'
)
})}
onSubmit={async (
values,
Expand Down Expand Up @@ -380,6 +385,24 @@ const DatasetImportForm = (props) => {
/>
</Box>
</CardContent>
<CardContent>
<TextField
fullWidth
label="Auto Approval"
name="autoApprovalEnabled"
onChange={handleChange}
select
value={values.autoApprovalEnabled}
variant="outlined"
>
<MenuItem key={'Enabled'} value={true}>
Enabled
</MenuItem>
<MenuItem key={'Enabled'} value={false}>
Disabled
</MenuItem>
</TextField>
</CardContent>
</Card>
</Grid>
<Grid item lg={5} md={5} xs={12}>
Expand Down
1 change: 1 addition & 0 deletions frontend/src/services/graphql/Datasets/getDataset.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export const getDataset = (datasetUri) => ({
topics
language
confidentiality
autoApprovalEnabled
organization {
organizationUri
label
Expand Down
11 changes: 8 additions & 3 deletions tests/modules/datasets/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ def factory(
name: str,
owner: str,
group: str,
confidentiality: str = None
confidentiality: str = None,
autoApprovalEnabled: bool = False
) -> Dataset:
key = f'{org.organizationUri}-{env.environmentUri}-{name}-{group}'
if cache.get(key):
Expand Down Expand Up @@ -95,6 +96,7 @@ def factory(
topics
language
confidentiality
autoApprovalEnabled
organization{
organizationUri
label
Expand Down Expand Up @@ -149,7 +151,8 @@ def factory(
'environmentUri': env.environmentUri,
'SamlAdminGroupName': group or random_group(),
'organizationUri': org.organizationUri,
'confidentiality': confidentiality or ConfidentialityClassification.Unclassified.value
'confidentiality': confidentiality or ConfidentialityClassification.Unclassified.value,
'autoApprovalEnabled': autoApprovalEnabled

},
)
Expand Down Expand Up @@ -267,7 +270,8 @@ def dataset_model(db):
def factory(
organization: Organization,
environment: Environment,
label: str
label: str,
autoApprovalEnabled: bool = False
) -> Dataset:
with db.scoped_session() as session:
dataset = Dataset(
Expand All @@ -286,6 +290,7 @@ def factory(
region=environment.region,
IAMDatasetAdminUserArn=f"arn:aws:iam::{environment.AwsAccountId}:user/dataset",
IAMDatasetAdminRoleArn=f"arn:aws:iam::{environment.AwsAccountId}:role/dataset",
autoApprovalEnabled = autoApprovalEnabled
)
session.add(dataset)
session.commit()
Expand Down
6 changes: 4 additions & 2 deletions tests/modules/datasets/tasks/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ def factory(
organization: Organization,
environment: Environment,
label: str,
imported: bool = False
imported: bool = False,
autoApprovalEnabled: bool = False,
) -> Dataset:
with db.scoped_session() as session:
dataset = Dataset(
Expand All @@ -32,7 +33,8 @@ def factory(
IAMDatasetAdminUserArn=f"arn:aws:iam::{environment.AwsAccountId}:user/dataset",
IAMDatasetAdminRoleArn=f"arn:aws:iam::{environment.AwsAccountId}:role/dataset",
imported=imported,
importedKmsKey=imported
importedKmsKey=imported,
autoApprovalEnabled=autoApprovalEnabled,
)
session.add(dataset)
session.commit()
Expand Down
Loading
Loading