-
Notifications
You must be signed in to change notification settings - Fork 24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
BB2-3243: Add --all option to update_access_grants Django command #1204
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,35 @@ | ||
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") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of superseding There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we were introducing outside our team I probably would, lol. I may still! I thought that for us and future internal teams, the help string would make it make sense and defaulting to the less destructive option would at least limit accidents. |
||
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) | ||
Comment on lines
+22
to
+23
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm pretty sure the django orm compiles very similar sql with this pattern to if i iterated over the queryset directly below. I think this way is more readable, but may shuffle the whole thing to make the options mutually exclusive. |
||
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: | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this an accidental extra new line, or is this an automatic formatter thing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Purposeful to match PEP 8 standard on spacing around class declarations. We should get the team using PEP 8 tools in their IDE. I fix a lot of stuff like this reflexively when I see it because PyCharm yells at me if its not to the standard.