← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] lp:~rvb/maas/maas-bug-948353 into lp:maas

 

Raphaël Badin has proposed merging lp:~rvb/maas/maas-bug-948353 into lp:maas.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)
Related bugs:
  Bug #948353 in MaaS: "add user screen doesn't have a field to enter email address"
  https://bugs.launchpad.net/maas/+bug/948353

For more details, see:
https://code.launchpad.net/~rvb/maas/maas-bug-948353/+merge/96325

This branch adds a email field to the "Add user" page.
-- 
https://code.launchpad.net/~rvb/maas/maas-bug-948353/+merge/96325
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~rvb/maas/maas-bug-948353 into lp:maas.
=== modified file 'src/maasserver/forms.py'
--- src/maasserver/forms.py	2012-03-07 04:47:58 +0000
+++ src/maasserver/forms.py	2012-03-07 11:01:19 +0000
@@ -122,7 +122,6 @@
 
 
 class NewUserCreationForm(UserCreationForm):
-    # Add is_superuser field.
     is_superuser = forms.BooleanField(
         label="MaaS administrator", required=False)
 
@@ -133,6 +132,12 @@
         self.fields.insert(
             1, 'last_name',
             forms.CharField(label="Full name", max_length=30, required=False))
+        # Insert 'email' field at the right place (right after
+        # the 'last_name' field).
+        self.fields.insert(
+            2, 'email',
+            forms.EmailField(
+                label="E-mail address", max_length=75, required=False))
 
     def save(self, commit=True):
         user = super(NewUserCreationForm, self).save(commit=False)
@@ -141,6 +146,9 @@
         new_last_name = self.cleaned_data.get('last_name', None)
         if new_last_name is not None:
             user.last_name = new_last_name
+        new_email = self.cleaned_data.get('email', None)
+        if new_email is not None:
+            user.email = new_email
         user.save()
         return user
 

=== modified file 'src/maasserver/templatetags/field_type.py'
--- src/maasserver/templatetags/field_type.py	2012-03-06 02:53:42 +0000
+++ src/maasserver/templatetags/field_type.py	2012-03-07 11:01:19 +0000
@@ -15,8 +15,10 @@
 
 from django import template
 
+
 register = template.Library()
 
+
 @register.filter('field_type')
 def field_type(field):
     return field.field.widget.__class__.__name__

=== modified file 'src/maasserver/testing/factory.py'
--- src/maasserver/testing/factory.py	2012-03-05 09:10:38 +0000
+++ src/maasserver/testing/factory.py	2012-03-07 11:01:19 +0000
@@ -34,6 +34,9 @@
             random.choice(string.letters + string.digits)
             for x in range(size))
 
+    def getRandomEmail(self, login_size=10):
+        return "%s@xxxxxxxxxxx" % self.getRandomString(size=login_size)
+
     def getRandomBoolean(self):
         return random.choice((True, False))
 

=== modified file 'src/maasserver/tests/test_forms.py'
--- src/maasserver/tests/test_forms.py	2012-03-05 19:22:54 +0000
+++ src/maasserver/tests/test_forms.py	2012-03-07 11:01:19 +0000
@@ -184,6 +184,6 @@
         form = NewUserCreationForm()
 
         self.assertEqual(
-            ['username', u'last_name', 'password1', 'password2',
+            ['username', 'last_name', 'email', 'password1', 'password2',
                 'is_superuser'],
             list(form.fields))

=== modified file 'src/maasserver/tests/test_views.py'
--- src/maasserver/tests/test_views.py	2012-03-06 15:24:01 +0000
+++ src/maasserver/tests/test_views.py	2012-03-07 11:01:19 +0000
@@ -273,6 +273,7 @@
     def test_add_user_POST(self):
         new_last_name = factory.getRandomString(30)
         new_password = factory.getRandomString()
+        new_email = factory.getRandomEmail()
         new_admin_status = factory.getRandomBoolean()
         response = self.client.post(
             reverse('accounts-add'),
@@ -282,12 +283,14 @@
                 'password1': new_password,
                 'password2': new_password,
                 'is_superuser': new_admin_status,
+                'email': new_email,
             })
         self.assertEqual(httplib.FOUND, response.status_code)
         users = list(User.objects.filter(username='my_user'))
         self.assertEqual(1, len(users))
         self.assertEqual(new_last_name, users[0].last_name)
         self.assertEqual(new_admin_status, users[0].is_superuser)
+        self.assertEqual(new_email, users[0].email)
         self.assertTrue(users[0].check_password(new_password))
 
     def test_edit_user_POST(self):