Merge lp:~roadmr/canonical-identity-provider/suspend-admin-action into lp:canonical-identity-provider/release

Proposed by Daniel Manrique
Status: Merged
Approved by: Daniel Manrique
Approved revision: no longer in the source branch.
Merge reported by: Otto Co-Pilot
Merged at revision: not available
Proposed branch: lp:~roadmr/canonical-identity-provider/suspend-admin-action
Merge into: lp:canonical-identity-provider/release
Diff against target: 62 lines (+37/-0)
2 files modified
src/identityprovider/admin.py (+11/-0)
src/identityprovider/tests/test_admin.py (+26/-0)
To merge this branch: bzr merge lp:~roadmr/canonical-identity-provider/suspend-admin-action
Reviewer Review Type Date Requested Status
Maximiliano Bertacchini Approve
Daniel Manrique (community) Approve
Review via email: mp+345449@code.launchpad.net

Commit message

Add admin list action to suspend accounts.

This is handy if the account in question has e.g. thousands of e-mail addresses (grounds for suspension!) which makes the account change page unusable. With this, the suspend can be applied from the accounts list page.

Description of the change

Add admin list action to suspend accounts.

This is handy if the account in question has e.g. thousands of e-mail addresses (grounds for suspension!) which makes the account change page unusable. With this, the suspend can be applied from the accounts list page.

To post a comment you must log in.
Revision history for this message
Maximiliano Bertacchini (maxiberta) wrote :

LGTM, with a couple of nitpicks.

review: Approve
Revision history for this message
Daniel Manrique (roadmr) wrote :

Made changes per review!

review: Approve
Revision history for this message
Maximiliano Bertacchini (maxiberta) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/identityprovider/admin.py'
--- src/identityprovider/admin.py 2018-02-20 15:45:11 +0000
+++ src/identityprovider/admin.py 2018-05-14 14:21:32 +0000
@@ -291,6 +291,7 @@
291291
292292
293class AccountAdmin(LargeTableMixin, admin.ModelAdmin):293class AccountAdmin(LargeTableMixin, admin.ModelAdmin):
294 actions = ['suspend']
294 inlines = [AccountPasswordInline, EmailAddressInline,295 inlines = [AccountPasswordInline, EmailAddressInline,
295 AuthenticationDeviceInline]296 AuthenticationDeviceInline]
296 readonly_fields = ('date_created',)297 readonly_fields = ('date_created',)
@@ -366,6 +367,16 @@
366 super(AccountAdmin, self).save_formset(367 super(AccountAdmin, self).save_formset(
367 request, form, formset, change)368 request, form, formset, change)
368369
370 def suspend(self, request, queryset):
371 """Suspend the selected accounts."""
372 for account in queryset.all():
373 account.status = AccountStatus.SUSPENDED
374 account.save()
375 self.message_user(
376 request, "Suspended %s accounts" % queryset.count())
377
378 suspend.short_description = "Suspend accounts"
379
369380
370class APIUserAdminForm(forms.ModelForm):381class APIUserAdminForm(forms.ModelForm):
371382
372383
=== modified file 'src/identityprovider/tests/test_admin.py'
--- src/identityprovider/tests/test_admin.py 2018-05-09 22:00:09 +0000
+++ src/identityprovider/tests/test_admin.py 2018-05-14 14:21:32 +0000
@@ -693,3 +693,29 @@
693 response, reverse('admin:identityprovider_account_change',693 response, reverse('admin:identityprovider_account_change',
694 args=(self.account.id,)))694 args=(self.account.id,)))
695 self.assertNotContains(response, self.account.displayname)695 self.assertNotContains(response, self.account.displayname)
696
697
698class AccountAdminTestCase(SSOBaseTestCase):
699
700 def setUp(self):
701 super(AccountAdminTestCase, self).setUp()
702 self.admin = self.factory.make_account(
703 is_superuser=True, password="admin007")
704 assert self.client.login(
705 username=self.admin.user.email, password="admin007")
706 self.accounts = [self.factory.make_account() for _ in range(2)]
707
708 def test_account_suspend_action(self):
709 assert all((
710 account.status != AccountStatus.SUSPENDED
711 for account in self.accounts))
712 action_data = {
713 'action': 'suspend',
714 '_selected_action': [account.pk for account in self.accounts]
715 }
716 self.client.post(
717 reverse('admin:identityprovider_account_changelist'),
718 action_data, follow=True)
719 for account in self.accounts:
720 account.refresh_from_db()
721 self.assertEqual(account.status, AccountStatus.SUSPENDED)