Merge lp:~facundo/canonical-identity-provider/add-password-changed-timestamp into lp:canonical-identity-provider/release

Proposed by Facundo Batista
Status: Merged
Approved by: Daniel Manrique
Approved revision: no longer in the source branch.
Merged at revision: 1417
Proposed branch: lp:~facundo/canonical-identity-provider/add-password-changed-timestamp
Merge into: lp:canonical-identity-provider/release
Diff against target: 83 lines (+38/-2)
3 files modified
src/identityprovider/migrations/0008_accountpassword_date_changed.py (+19/-0)
src/identityprovider/models/account.py (+5/-1)
src/identityprovider/tests/test_models_account.py (+14/-1)
To merge this branch: bzr merge lp:~facundo/canonical-identity-provider/add-password-changed-timestamp
Reviewer Review Type Date Requested Status
Daniel Manrique (community) Approve
Review via email: mp+289896@code.launchpad.net

Commit message

Added a timestamp to flag when the password was changed.

To post a comment you must log in.
Revision history for this message
Daniel Manrique (roadmr) wrote :

May need fixing, see below.

review: Needs Information
Revision history for this message
Facundo Batista (facundo) wrote :

Commends addressed

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

LGTM, thanks!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added file 'src/identityprovider/migrations/0008_accountpassword_date_changed.py'
2--- src/identityprovider/migrations/0008_accountpassword_date_changed.py 1970-01-01 00:00:00 +0000
3+++ src/identityprovider/migrations/0008_accountpassword_date_changed.py 2016-03-23 16:24:27 +0000
4@@ -0,0 +1,19 @@
5+# -*- coding: utf-8 -*-
6+from __future__ import unicode_literals
7+
8+from django.db import migrations, models
9+
10+
11+class Migration(migrations.Migration):
12+
13+ dependencies = [
14+ ('identityprovider', '0007_auto_20160310_2013'),
15+ ]
16+
17+ operations = [
18+ migrations.AddField(
19+ model_name='accountpassword',
20+ name='date_changed',
21+ field=models.DateTimeField(null=True, editable=False),
22+ ),
23+ ]
24
25=== modified file 'src/identityprovider/models/account.py'
26--- src/identityprovider/models/account.py 2015-11-09 10:41:10 +0000
27+++ src/identityprovider/models/account.py 2016-03-23 16:24:27 +0000
28@@ -1,4 +1,4 @@
29-# Copyright 2010, 2012 Canonical Ltd. This software is licensed under
30+# Copyright 2010-2016 Canonical Ltd. This software is licensed under
31 # the GNU Affero General Public License version 3 (see the file
32 # LICENSE).
33
34@@ -665,6 +665,7 @@
35 account = models.OneToOneField(Account, db_column=b'account')
36 password = PasswordField()
37 last_leak_check = models.DateTimeField(null=True)
38+ date_changed = models.DateTimeField(null=True, editable=False)
39
40 LEAK_REFERENCE_DATE = datetime(2000, 01, 01, 0, 0, 0)
41
42@@ -687,9 +688,12 @@
43
44 Usual "update_fields" behavior applies (i.e. last_leak_check will NOT
45 be auto_updated if any fields are specified with update_fields).
46+
47+ Also, we keep the last time the password was changed.
48 """
49 if 'last_leak_check' not in kwargs.get('update_fields', []):
50 self.last_leak_check = AccountPassword.LEAK_REFERENCE_DATE
51+ self.date_changed = now()
52 super(AccountPassword, self).save(*args, **kwargs)
53
54
55
56=== modified file 'src/identityprovider/tests/test_models_account.py'
57--- src/identityprovider/tests/test_models_account.py 2016-01-07 16:45:57 +0000
58+++ src/identityprovider/tests/test_models_account.py 2016-03-23 16:24:27 +0000
59@@ -1,4 +1,4 @@
60-# Copyright 2010 Canonical Ltd. This software is licensed under the
61+# Copyright 2010-2016 Canonical Ltd. This software is licensed under the
62 # GNU Affero General Public License version 3 (see the file LICENSE).
63
64
65@@ -972,6 +972,19 @@
66 AccountPassword.objects.all()[0].last_leak_check,
67 AccountPassword.LEAK_REFERENCE_DATE)
68
69+ def test_changed_password(self):
70+ account = self.factory.make_account()
71+
72+ # get timestamp from creation
73+ created_at = account.accountpassword.date_changed
74+
75+ # change the password
76+ account.accountpassword.password = "Somethingelse"
77+ account.accountpassword.save()
78+
79+ # verify!
80+ self.assertGreater(account.accountpassword.date_changed, created_at)
81+
82
83 class CreateOAuthTokenForAccountTestCase(SSOBaseTestCase):
84