-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BB2-3243: Add --all option to update_access_grants Django command (#1204
- Loading branch information
1 parent
a140bca
commit 91298bf
Showing
1 changed file
with
11 additions
and
6 deletions.
There are no files selected for viewing
17 changes: 11 additions & 6 deletions
17
apps/authorization/management/commands/update_access_grants.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
||
|