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

Proposed by Daniel Manrique on 2018-05-11
Status: Merged
Approved by: Daniel Manrique on 2018-05-14
Approved revision: 1629
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 2018-05-11 Approve on 2018-05-14
Daniel Manrique Approve on 2018-05-14
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.
Maximiliano Bertacchini (maxiberta) wrote :

LGTM, with a couple of nitpicks.

review: Approve
1629. By Daniel Manrique on 2018-05-14

Test multiple accounts

Daniel Manrique (roadmr) wrote :

Made changes per review!

review: Approve
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/identityprovider/admin.py'
2--- src/identityprovider/admin.py 2018-02-20 15:45:11 +0000
3+++ src/identityprovider/admin.py 2018-05-14 14:21:32 +0000
4@@ -291,6 +291,7 @@
5
6
7 class AccountAdmin(LargeTableMixin, admin.ModelAdmin):
8+ actions = ['suspend']
9 inlines = [AccountPasswordInline, EmailAddressInline,
10 AuthenticationDeviceInline]
11 readonly_fields = ('date_created',)
12@@ -366,6 +367,16 @@
13 super(AccountAdmin, self).save_formset(
14 request, form, formset, change)
15
16+ def suspend(self, request, queryset):
17+ """Suspend the selected accounts."""
18+ for account in queryset.all():
19+ account.status = AccountStatus.SUSPENDED
20+ account.save()
21+ self.message_user(
22+ request, "Suspended %s accounts" % queryset.count())
23+
24+ suspend.short_description = "Suspend accounts"
25+
26
27 class APIUserAdminForm(forms.ModelForm):
28
29
30=== modified file 'src/identityprovider/tests/test_admin.py'
31--- src/identityprovider/tests/test_admin.py 2018-05-09 22:00:09 +0000
32+++ src/identityprovider/tests/test_admin.py 2018-05-14 14:21:32 +0000
33@@ -693,3 +693,29 @@
34 response, reverse('admin:identityprovider_account_change',
35 args=(self.account.id,)))
36 self.assertNotContains(response, self.account.displayname)
37+
38+
39+class AccountAdminTestCase(SSOBaseTestCase):
40+
41+ def setUp(self):
42+ super(AccountAdminTestCase, self).setUp()
43+ self.admin = self.factory.make_account(
44+ is_superuser=True, password="admin007")
45+ assert self.client.login(
46+ username=self.admin.user.email, password="admin007")
47+ self.accounts = [self.factory.make_account() for _ in range(2)]
48+
49+ def test_account_suspend_action(self):
50+ assert all((
51+ account.status != AccountStatus.SUSPENDED
52+ for account in self.accounts))
53+ action_data = {
54+ 'action': 'suspend',
55+ '_selected_action': [account.pk for account in self.accounts]
56+ }
57+ self.client.post(
58+ reverse('admin:identityprovider_account_changelist'),
59+ action_data, follow=True)
60+ for account in self.accounts:
61+ account.refresh_from_db()
62+ self.assertEqual(account.status, AccountStatus.SUSPENDED)