66import re
77import logging
88
9+ from django .utils import timezone
10+
911# methods are imported to populate namespace and be used elsewhere
1012from uw_msca .shared_drive import ( # noqa: F401
1113 get_default_quota ,
1214 get_google_drive_states ,
1315 set_drive_quota ,
16+ mark_drive_for_deletion ,
17+ rescue_drive_from_deletion ,
1418)
1519from uw_msca .models import GoogleDriveState
1620
5256)
5357MISSING_DRIVE_THRESHOLD = 500
5458MISSING_DRIVE_NOTIFICATION = 150
59+ PENDING_DELETE_ORG_UNIT = "deleteprt"
5560
5661
5762def sync_quota_from_subscription (drive_id ):
@@ -87,7 +92,7 @@ def expire_shared_drives(gracetime, lifetime):
8792 shared_drive_lifecycle_expired (drive )
8893
8994
90- def shared_drive_lifecycle_expired (drive_record ):
95+ def shared_drive_lifecycle_expired (shared_drive ):
9196 """
9297 Set lifecycle to expired for shared drive
9398
@@ -96,8 +101,20 @@ def shared_drive_lifecycle_expired(drive_record):
96101 - set subscription end_date to today using:
97102 - expire_subscription(drive_record)
98103 """
99- logger .error (
100- f"Shared drive { drive_record } lifecycle expired: not implemented" )
104+ logger .info (f"Shared drive { shared_drive .drive_id } marked for deletion" )
105+ mark_drive_for_deletion (shared_drive .drive_id )
106+
107+
108+ def rescue_shared_drive_from_deletion (shared_drive ):
109+ """
110+ Restore OrgUnit for shared drive previously marked for deletion
111+
112+ Actions:
113+ - set call msca rescue method with original drive quota
114+ """
115+ logger .info (f"Rescue shared drive { shared_drive } from deletion" )
116+ rescue_drive_from_deletion (
117+ shared_drive .drive_quota .quota_limit , shared_drive .drive_id )
101118
102119
103120def load_shared_drives (google_drive_states ):
@@ -608,9 +625,21 @@ def managers_for_shared_drive(google_drive_states):
608625 f"existing drive ({ drive_id } ) "
609626 f"usage ({ drive_state .drive_name } ) update: { ex } " )
610627
611- # confirm drive and subscription match
612628 sdr = SharedDriveRecord .objects .get_record_by_drive_id (
613629 drive_id )
630+
631+ # drive reported in pending delete org unit, store deleted date if
632+ # not present to help signal state in the ui
633+ if (shared_drive .drive_quota .org_unit_name != drive_state .org_unit_name
634+ and drive_state .org_unit_name .lower () == PENDING_DELETE_ORG_UNIT
635+ and sdr .datetime_deleted is None ):
636+ logger .info (f"drive quota org unit change: drive { drive_id } "
637+ f"org unit { shared_drive .drive_quota .org_unit_name } "
638+ f"to { drive_state .org_unit_name } " )
639+ sdr .datetime_deleted = timezone .now ()
640+ sdr .save ()
641+
642+ # confirm drive and subscription match
614643 reconcile_drive_quota (
615644 sdr ,
616645 no_subscription_quota = subsidized_quota ,
0 commit comments