Skip to content

Commit ba53d20

Browse files
committed
consolidate expire functions
1 parent aeab3fa commit ba53d20

File tree

3 files changed

+20
-20
lines changed

3 files changed

+20
-20
lines changed

endorsement/dao/shared_drive.py

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -85,27 +85,28 @@ def sync_quota_from_subscription(drive_id):
8585

8686

8787
def expire_shared_drive(shared_drive_record):
88+
"""
89+
Set lifecycle expired shared drive record
90+
91+
Actions:
92+
- set shared_drive_record datetime_deleted to now
93+
- set lifecycle to expired for shared drive using:
94+
- shared_drive_lifecycle_expired(shared_drive_record.shared_drive)
95+
"""
8896
try:
89-
shared_drive_lifecycle_expired(shared_drive_record.shared_drive)
97+
logger.info(
98+
"Expire shared drive "
99+
f"{shared_drive_record.shared_drive.drive_id}, "
100+
"mark for deletion")
101+
102+
mark_drive_for_deletion(shared_drive_record.shared_drive.drive_id)
103+
90104
shared_drive_record.datetime_deleted = timezone.now()
91105
shared_drive_record.save()
92106
except DataFailureException as ex:
93107
logger.error(
94-
"Cannot expire drive "
95-
f"{shared_drive_record.shared_drive.drive_id} : {ex}")
96-
97-
98-
def shared_drive_lifecycle_expired(shared_drive):
99-
"""
100-
Set lifecycle to expired for shared drive
101-
102-
Actions:
103-
- set shared_drive quota to 0 (org_unit_name "None"? pending delete?)
104-
- set subscription end_date to today using:
105-
- expire_subscription(drive_record)
106-
"""
107-
logger.info(f"Shared drive {shared_drive.drive_id} marked for deletion")
108-
mark_drive_for_deletion(shared_drive.drive_id)
108+
f"Expire {shared_drive_record.shared_drive.drive_id} "
109+
f"failure: {ex}")
109110

110111

111112
def rescue_shared_drive_from_deletion(shared_drive):

endorsement/management/commands/expire_shared_drives.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
from django.core.management.base import BaseCommand
55
from restclients_core.exceptions import DataFailureException
66
from endorsement.policy.shared_drive import SharedDrivePolicy
7-
from endorsement.dao.shared_drive import (
8-
shared_drive_lifecycle_expired, expire_shared_drive)
7+
from endorsement.dao.shared_drive import expire_shared_drive
98
import csv
109
import logging
1110

endorsement/views/api/google/shared_drive.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from endorsement.dao.itbill import update_itbill_subscription
77
from endorsement.dao.shared_drive import (
88
sync_quota_from_subscription,
9-
shared_drive_lifecycle_expired,
9+
expire_shared_drive,
1010
rescue_shared_drive_from_deletion)
1111
from endorsement.dao.pws import get_person
1212
from endorsement.util.auth import is_support_user
@@ -71,7 +71,7 @@ def put(self, request, *args, **kwargs):
7171
if drive.datetime_deleted:
7272
rescue_shared_drive_from_deletion(drive.shared_drive)
7373
else:
74-
shared_drive_lifecycle_expired(drive.shared_drive)
74+
expire_shared_drive(drive.shared_drive)
7575

7676
drive.set_acceptance(netid, accept, acted_as)
7777

0 commit comments

Comments
 (0)