Skip to content

Commit

Permalink
BB2-3243: Add --all option to update_access_grants Django command (#1204
Browse files Browse the repository at this point in the history
)

* Added --all option

* Revert dockerfile change

* Removed extra lines
  • Loading branch information
loganbertram committed Jun 6, 2024
1 parent a140bca commit 91298bf
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions apps/authorization/management/commands/update_access_grants.py
Original file line number Diff line number Diff line change
@@ -1,33 +1,38 @@
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.'
'Pass in a list of application ids.'
)

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:
for grant in grants:
grant.update_expiration_date()
else:
continue


0 comments on commit 91298bf

Please sign in to comment.