Skip to content

Commit fa45abd

Browse files
authored
fix: safe removal of consumption roles with open share requests (#485)
### Feature or Bugfix - Bugfix ### Detail - Added check and exception if there are open share requests on a consumption role or on a group that we are removing from an environment ### Relates - #450 By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
1 parent 9fc84bf commit fa45abd

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

backend/dataall/db/api/environment.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,23 @@ def remove_group(session, username, groups, uri, data=None, check_perm=None):
392392
message=f'Team: {group} has created {group_env_objects_count} resources on this environment.',
393393
)
394394

395+
shares_count = (
396+
session.query(models.ShareObject)
397+
.filter(
398+
and_(
399+
models.ShareObject.principalId == group,
400+
models.ShareObject.principalType == PrincipalType.Group.value
401+
)
402+
)
403+
.count()
404+
)
405+
406+
if shares_count > 0:
407+
raise exceptions.EnvironmentResourcesFound(
408+
action='Remove Team',
409+
message=f'Team: {group} has created {shares_count} share requests on this environment.',
410+
)
411+
395412
group_membership = Environment.find_environment_group(
396413
session, group, environment.environmentUri
397414
)
@@ -529,6 +546,23 @@ def remove_consumption_role(session, username, groups, uri, data=None, check_per
529546

530547
consumption_role = Environment.get_environment_consumption_role(session, uri, data.get('environmentUri'))
531548

549+
shares_count = (
550+
session.query(models.ShareObject)
551+
.filter(
552+
and_(
553+
models.ShareObject.principalId == uri,
554+
models.ShareObject.principalType == PrincipalType.ConsumptionRole.value
555+
)
556+
)
557+
.count()
558+
)
559+
560+
if shares_count > 0:
561+
raise exceptions.EnvironmentResourcesFound(
562+
action='Remove Consumption Role',
563+
message=f'Consumption role: {consumption_role.consumptionRoleName} has created {shares_count} share requests on this environment.',
564+
)
565+
532566
if consumption_role:
533567
session.delete(consumption_role)
534568
session.commit()

0 commit comments

Comments
 (0)