diff --git a/apps/authorization/management/commands/update_access_grants.py b/apps/authorization/management/commands/update_access_grants.py index 798bc6d50..a0e1bd7aa 100644 --- a/apps/authorization/management/commands/update_access_grants.py +++ b/apps/authorization/management/commands/update_access_grants.py @@ -1,6 +1,8 @@ from django.core.management.base import BaseCommand from apps.authorization.models import DataAccessGrant from apps.dot_ext.models import Application + + class Command(BaseCommand): help = ( 'Update Access Grants Per Application.' @@ -8,20 +10,25 @@ class Command(BaseCommand): ) def add_arguments(self, parser): - parser.add_argument('--applications', help="list of applications to update " + parser.add_argument('--applications', help="List of applications to update " "id, comma separated: " - "eg. 1,2,3 ") - + "eg. 1,2,3. Supersedes --all") + parser.add_argument('--all', action='store_true', help="Update access grants for all applications") + parser.set_defaults(all=False) def handle(self, *args, **options): if options['applications']: application_ids = options['applications'].split(',') + elif options['all']: + application_ids = Application.objects.values_list('id', flat=True) else: - print("You must pass at least one application to update.") + print("You must pass at least one application to update or use the --all option.") return False for app_id in application_ids: application = Application.objects.get(id=app_id) grants = DataAccessGrant.objects.filter(application=app_id) + if not grants: + continue if "ONE_TIME" in application.data_access_type: grants.delete() elif "THIRTEEN_MONTH" in application.data_access_type: @@ -29,5 +36,3 @@ def handle(self, *args, **options): grant.update_expiration_date() else: continue - -