Update mgmt cmds to use user_ids instead of PII
This commit is contained in:
@@ -162,7 +162,7 @@ class Command(BaseCommand):
|
||||
help='Send program award notifications with course notification tasks',
|
||||
)
|
||||
parser.add_argument(
|
||||
'--usernames',
|
||||
'--user_ids',
|
||||
default=None,
|
||||
nargs='+',
|
||||
help='Run the command for the given user or list of users',
|
||||
@@ -190,7 +190,7 @@ class Command(BaseCommand):
|
||||
|
||||
log.info(
|
||||
u"notify_credentials starting, dry-run=%s, site=%s, delay=%d seconds, page_size=%d, "
|
||||
u"from=%s, to=%s, notify_programs=%s, usernames=%s, execution=%s",
|
||||
u"from=%s, to=%s, notify_programs=%s, user_ids=%s, execution=%s",
|
||||
options['dry_run'],
|
||||
options['site'],
|
||||
options['delay'],
|
||||
@@ -198,7 +198,7 @@ class Command(BaseCommand):
|
||||
options['start_date'] if options['start_date'] else 'NA',
|
||||
options['end_date'] if options['end_date'] else 'NA',
|
||||
options['notify_programs'],
|
||||
options['usernames'],
|
||||
options['user_ids'],
|
||||
'auto' if options['auto'] else 'manual',
|
||||
)
|
||||
|
||||
@@ -208,16 +208,16 @@ class Command(BaseCommand):
|
||||
log.error(u'No site configuration found for site %s', options['site'])
|
||||
|
||||
course_keys = self.get_course_keys(options['courses'])
|
||||
if not (course_keys or options['start_date'] or options['end_date'] or options['usernames']):
|
||||
raise CommandError('You must specify a filter (e.g. --courses= or --start-date or --usernames)')
|
||||
if not (course_keys or options['start_date'] or options['end_date'] or options['user_ids']):
|
||||
raise CommandError('You must specify a filter (e.g. --courses= or --start-date or --user_ids)')
|
||||
|
||||
certs = get_recently_modified_certificates(
|
||||
course_keys, options['start_date'], options['end_date'], options['usernames']
|
||||
course_keys, options['start_date'], options['end_date'], options['user_ids']
|
||||
)
|
||||
|
||||
users = None
|
||||
if options['usernames']:
|
||||
users = User.objects.filter(username__in=options['usernames'])
|
||||
if options['user_ids']:
|
||||
users = User.objects.filter(id__in=options['user_ids'])
|
||||
grades = get_recently_modified_grades(
|
||||
course_keys, options['start_date'], options['end_date'], users
|
||||
)
|
||||
|
||||
@@ -126,7 +126,7 @@ class TestNotifyCredentials(TestCase):
|
||||
@mock.patch(COMMAND_MODULE + '.Command.send_notifications')
|
||||
def test_username_arg(self, mock_send):
|
||||
call_command(
|
||||
Command(), '--start-date', '2017-02-01', '--end-date', '2017-02-02', '--usernames', self.user2.username
|
||||
Command(), '--start-date', '2017-02-01', '--end-date', '2017-02-02', '--user_ids', self.user2.id
|
||||
)
|
||||
self.assertTrue(mock_send.called)
|
||||
self.assertListEqual(list(mock_send.call_args[0][0]), [self.cert4])
|
||||
@@ -134,7 +134,7 @@ class TestNotifyCredentials(TestCase):
|
||||
mock_send.reset_mock()
|
||||
|
||||
call_command(
|
||||
Command(), '--usernames', self.user2.username
|
||||
Command(), '--user_ids', self.user2.id
|
||||
)
|
||||
self.assertTrue(mock_send.called)
|
||||
self.assertListEqual(list(mock_send.call_args[0][0]), [self.cert4])
|
||||
@@ -142,7 +142,7 @@ class TestNotifyCredentials(TestCase):
|
||||
mock_send.reset_mock()
|
||||
|
||||
call_command(
|
||||
Command(), '--start-date', '2017-02-01', '--end-date', '2017-02-02', '--usernames', self.user.username
|
||||
Command(), '--start-date', '2017-02-01', '--end-date', '2017-02-02', '--user_ids', self.user.id
|
||||
)
|
||||
self.assertTrue(mock_send.called)
|
||||
self.assertListEqual(list(mock_send.call_args[0][0]), [self.cert2])
|
||||
@@ -150,7 +150,7 @@ class TestNotifyCredentials(TestCase):
|
||||
mock_send.reset_mock()
|
||||
|
||||
call_command(
|
||||
Command(), '--usernames', self.user.username
|
||||
Command(), '--user_ids', self.user.id
|
||||
)
|
||||
self.assertTrue(mock_send.called)
|
||||
self.assertListEqual(list(mock_send.call_args[0][0]), [self.cert1, self.cert2, self.cert3])
|
||||
@@ -158,7 +158,7 @@ class TestNotifyCredentials(TestCase):
|
||||
mock_send.reset_mock()
|
||||
|
||||
call_command(
|
||||
Command(), '--usernames', self.user.username, self.user2.username
|
||||
Command(), '--user_ids', self.user.id, self.user2.id
|
||||
)
|
||||
self.assertTrue(mock_send.called)
|
||||
self.assertListEqual(list(mock_send.call_args[0][0]), [self.cert1, self.cert2, self.cert4, self.cert3])
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
# Generated by Django 2.2.18 on 2021-02-18 22:01
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
"""
|
||||
Delete all existing NotifyCredentialsConfig entries because they may contain PII prior to this change
|
||||
"""
|
||||
def remove_existing_configs(apps, schema_editor):
|
||||
NotifyCredentialsConfig = apps.get_model('credentials', 'NotifyCredentialsConfig')
|
||||
NotifyCredentialsConfig.objects.all().delete()
|
||||
|
||||
dependencies = [
|
||||
('credentials', '0004_notifycredentialsconfig'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RunPython(remove_existing_configs)
|
||||
]
|
||||
Reference in New Issue
Block a user