Skip to content

Commit

Permalink
Merge pull request #700 from uw-it-aca/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
mikeseibel committed Aug 28, 2024
2 parents c66e656 + e31ff3e commit 381df7f
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 2 deletions.
9 changes: 8 additions & 1 deletion endorsement/dao/shared_drive.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ def get_drive_quota(a):
try:
defaults["quota_limit"] = a.quota_limit
except ValueError:
"Drive has no quota set. Probably in invalid org unit."
logger.error(f"Drive has no quota set. Probably in invalid org unit.")

drive_quota, _ = SharedDriveQuota.objects.update_or_create(
org_unit_id=a.org_unit_id,
Expand Down Expand Up @@ -338,6 +338,13 @@ def reconcile_drive_quota(
sdr, no_subscription_quota=no_subscription_quota
)

if quota_actual == 0:
logger.info(
f"reconcile: skip set drive for {sdr.shared_drive.drive_id} "
"as the drive has {quota_actual} quota set"
)
return

if not quota_correct:
logger.info(
f"reconcile: skip set drive for {sdr.shared_drive.drive_id} "
Expand Down
63 changes: 63 additions & 0 deletions endorsement/management/commands/notify_non_subsidized.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# Copyright 2024 UW-IT, University of Washington
# SPDX-License-Identifier: Apache-2.0

from django.core.management.base import BaseCommand
from django.utils import timezone
from endorsement.models import SharedDriveRecord
from endorsement.dao.notification import send_notification
from endorsement.util.email import uw_email_address
from endorsement.exceptions import EmailFailureException
from endorsement.notifications.shared_drive import (
_create_notification_over_quota_non_subsidized)
import logging


logger = logging.getLogger(__name__)


class Command(BaseCommand):
help = 'Send email notifications to reduced-quota shared drive members'

def add_arguments(self, parser):
parser.add_argument('shared_drive_ids', type=str)
parser.add_argument(
'--commit',
action='store_true',
default=False,
help='Actually send the email notifications',
)

def handle(self, *args, **options):
send_email = options['commit']
shared_drive_ids = [d.strip() for d in options[
'shared_drive_ids'].split(',')]

for drive_id in shared_drive_ids:
drive = SharedDriveRecord.objects.get(
shared_drive__drive_id=drive_id)

if "PENDING_DELETE_" in drive.shared_drive.drive_name:
logger.info("skip notification: drive name "
f"{drive.shared_drive.drive_name}")
continue

try:
members = [uw_email_address(netid) for (
netid) in drive.shared_drive.get_member_netids()]
(subject,
text_body,
html_body) = _create_notification_over_quota_non_subsidized(
drive)
if send_email:
logger.info("over quota email: DriveId: "
f"{drive.shared_drive.drive_id} -- "
f"To: {', '.join(members)}")
send_notification(
members, subject, text_body, html_body,
"OverSubsidizedQuota")

setattr(
drive, 'datetime_over_quota_emailed', timezone.now())
drive.save()
except EmailFailureException as ex:
sys.exit(f"Email failure: {ex}")
2 changes: 1 addition & 1 deletion endorsement/test/dao/test_shared_drive.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ def setUp(self):
super().setUp()
# drive exists in non-subsidized OU with no subscription
self.mocks['get_google_drive_states'].return_value = [
GDS(drive_id='grace1', member='Al', org_unit_name='200G'),
GDS(drive_id='grace1', member='Al', org_unit_name='200GB'),
]

def test(self):
Expand Down

0 comments on commit 381df7f

Please sign in to comment.