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

[Bugfix] | GH-1749 -Fixing share expiration task #1750

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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