Skip to content

Commit

Permalink
Fixing share expiration task
Browse files Browse the repository at this point in the history
  • Loading branch information
TejasRGitHub authored and trajopadhye committed Jan 10, 2025
1 parent f5fbcfd commit 298bd62
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ def fetch_submitted_shares_with_notifications(session):
def get_all_active_shares_with_expiration(session):
return (
session.query(ShareObject)
.filter(and_(ShareObject.expiryDate.isnot(None), ShareObject.deleted.is_(None)))
.filter(and_(ShareObject.expiryDate.isnot(None), ShareObject.deleted.is_(None), ShareObject.status == 'Processed'))
.all()
)

Expand Down
20 changes: 9 additions & 11 deletions backend/dataall/modules/shares_base/tasks/share_expiration_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,24 +27,23 @@ def share_expiration_checker(engine):
try:
if share.expiryDate.date() < datetime.today().date():
log.info(f'Revoking share with uri: {share.shareUri} as it is expired')
# Put all share items in revoke state and then revoke
# If a share is expired, pull all the share items which are in Share_Succeeded state
# Update status for each share item to Revoke_Approved and Revoke the share
share_items_to_revoke = ShareObjectRepository.get_all_share_items_in_share(
session, share.shareUri, ['Share_Succeeded']
)
item_uris = [share_item.shareItemUri for share_item in share_items_to_revoke]
revoked_items_states = ShareStatusRepository.get_share_items_states(
session, share.shareUri, item_uris
)

# If the share doesn't have any share items in Share_Succeeded state then skip this share
if len(share_items_to_revoke) == 0:
continue

share_sm = ShareObjectSM(share.status)
new_share_state = share_sm.run_transition(ShareObjectActions.RevokeItems.value)

for item_state in revoked_items_states:
item_sm = ShareItemSM(item_state)
for item in share_items_to_revoke:
item_sm = ShareItemSM(item.status)
new_state = item_sm.run_transition(ShareObjectActions.RevokeItems.value)
for item in share_items_to_revoke:
if item.status == item_state:
item_sm.update_state_single_item(session, item, new_state)
item_sm.update_state_single_item(session, item, new_state)

share_sm.update_state(session, share, new_share_state)
SharingService.revoke_share(engine=engine, share_uri=share.shareUri)
Expand All @@ -70,7 +69,6 @@ def share_expiration_checker(engine):
f'Error occured while processing share expiration processing for share with URI: {share.shareUri} due to: {e}'
)


if __name__ == '__main__':
load_modules(modes={ImportMode.SHARES_TASK})
ENVNAME = os.environ.get('envname', 'dkrcompose')
Expand Down

0 comments on commit 298bd62

Please sign in to comment.