launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #06982
[Merge] lp:~rvb/maas/maas-bug-972499 into lp:maas
Raphaël Badin has proposed merging lp:~rvb/maas/maas-bug-972499 into lp:maas.
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
Related bugs:
Bug #972499 in MAAS: "Owner shouldn't be editable on the node settings page"
https://bugs.launchpad.net/maas/+bug/972499
For more details, see:
https://code.launchpad.net/~rvb/maas/maas-bug-972499/+merge/100631
This branch removes owner from the editable fields in the NodeEditForm. It also adds the display of the owner on the "view node" page if node.owner != None.
--
https://code.launchpad.net/~rvb/maas/maas-bug-972499/+merge/100631
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~rvb/maas/maas-bug-972499 into lp:maas.
=== modified file 'src/maasserver/forms.py'
--- src/maasserver/forms.py 2012-04-03 10:19:47 +0000
+++ src/maasserver/forms.py 2012-04-03 15:30:33 +0000
@@ -54,7 +54,6 @@
NODE_PERMISSION,
NODE_STATUS,
SSHKey,
- UserProfile,
)
@@ -110,13 +109,11 @@
class UIAdminNodeEditForm(ModelForm):
after_commissioning_action = forms.ChoiceField(
choices=NODE_AFTER_COMMISSIONING_ACTION_CHOICES)
- owner = forms.ModelChoiceField(
- queryset=UserProfile.objects.all_users(), required=False)
class Meta:
model = Node
fields = (
- 'hostname', 'after_commissioning_action', 'power_type', 'owner')
+ 'hostname', 'after_commissioning_action', 'power_type')
class MACAddressForm(ModelForm):
=== modified file 'src/maasserver/models.py'
--- src/maasserver/models.py 2012-04-03 10:19:47 +0000
+++ src/maasserver/models.py 2012-04-03 15:30:33 +0000
@@ -489,7 +489,7 @@
default=NODE_STATUS.DEFAULT_STATUS)
owner = models.ForeignKey(
- User, default=None, blank=True, null=True, editable=True)
+ User, default=None, blank=True, null=True, editable=False)
after_commissioning_action = models.IntegerField(
choices=NODE_AFTER_COMMISSIONING_ACTION_CHOICES,
=== modified file 'src/maasserver/templates/maasserver/node_view.html'
--- src/maasserver/templates/maasserver/node_view.html 2012-04-03 09:58:17 +0000
+++ src/maasserver/templates/maasserver/node_view.html 2012-04-03 15:30:33 +0000
@@ -56,6 +56,14 @@
{{ node.display_status }}
</span>
</li>
+ {% if node.owner %}
+ <li class="block size2 first">
+ <h4>Owner</h4>
+ <span>
+ {{ node.owner }}
+ </span>
+ </li>
+ {% endif %}
</ul>
{% endblock %}
=== modified file 'src/maasserver/tests/test_forms.py'
--- src/maasserver/tests/test_forms.py 2012-04-03 10:19:47 +0000
+++ src/maasserver/tests/test_forms.py 2012-04-03 15:30:33 +0000
@@ -11,8 +11,6 @@
__metaclass__ = type
__all__ = []
-import random
-
from django import forms
from django.core.exceptions import (
PermissionDenied,
@@ -209,7 +207,7 @@
form = UIAdminNodeEditForm()
self.assertSequenceEqual(
- ['hostname', 'after_commissioning_action', 'power_type', 'owner'],
+ ['hostname', 'after_commissioning_action', 'power_type'],
list(form.fields))
def test_UIAdminNodeEditForm_changes_node(self):
@@ -218,50 +216,19 @@
after_commissioning_action = factory.getRandomChoice(
NODE_AFTER_COMMISSIONING_ACTION_CHOICES)
power_type = factory.getRandomChoice(POWER_TYPE_CHOICES)
- owner = random.choice([factory.make_user() for i in range(3)])
- form = UIAdminNodeEditForm(
- data={
- 'hostname': hostname,
- 'after_commissioning_action': after_commissioning_action,
- 'power_type': power_type,
- 'owner': owner.id,
- },
- instance=node)
- form.save()
-
- self.assertEqual(hostname, node.hostname)
- self.assertEqual(
- after_commissioning_action, node.after_commissioning_action)
- self.assertEqual(power_type, node.power_type)
- self.assertEqual(owner, node.owner)
-
- def test_UIAdminNodeEditForm_changes_node_empty_owner(self):
- node = factory.make_node()
- hostname = factory.getRandomString()
- after_commissioning_action = factory.getRandomChoice(
- NODE_AFTER_COMMISSIONING_ACTION_CHOICES)
- power_type = factory.getRandomChoice(POWER_TYPE_CHOICES)
- form = UIAdminNodeEditForm(
- data={
- 'hostname': hostname,
- 'after_commissioning_action': after_commissioning_action,
- 'power_type': power_type,
- },
- instance=node)
- form.save()
-
- self.assertEqual(hostname, node.hostname)
- self.assertEqual(
- after_commissioning_action, node.after_commissioning_action)
- self.assertEqual(power_type, node.power_type)
- self.assertEqual(None, node.owner)
-
- def test_UIAdminNodeEditForm_owner_choices_contains_active_users(self):
- form = UIAdminNodeEditForm()
- user = factory.make_user()
- user_ids = [choice[0] for choice in form.fields['owner'].choices]
-
- self.assertItemsEqual(['', user.id], user_ids)
+ form = UIAdminNodeEditForm(
+ data={
+ 'hostname': hostname,
+ 'after_commissioning_action': after_commissioning_action,
+ 'power_type': power_type,
+ },
+ instance=node)
+ form.save()
+
+ self.assertEqual(hostname, node.hostname)
+ self.assertEqual(
+ after_commissioning_action, node.after_commissioning_action)
+ self.assertEqual(power_type, node.power_type)
class NodeTransitionsMethodsTests(TestCase):
=== modified file 'src/maasserver/tests/test_views.py'
--- src/maasserver/tests/test_views.py 2012-04-03 12:05:37 +0000
+++ src/maasserver/tests/test_views.py 2012-04-03 15:30:33 +0000
@@ -14,7 +14,6 @@
from collections import namedtuple
import httplib
import os
-import random
import urllib2
from django.conf import settings
@@ -486,13 +485,23 @@
def test_view_node_displays_node_info(self):
# The node page features the basic information about the node.
- node = factory.make_node()
+ node = factory.make_node(owner=self.logged_in_user)
node_link = reverse('node-view', args=[node.system_id])
response = self.client.get(node_link)
doc = fromstring(response.content)
content_text = doc.cssselect('#content')[0].text_content()
self.assertIn(node.hostname, content_text)
self.assertIn(node.display_status(), content_text)
+ self.assertIn(self.logged_in_user.username, content_text)
+
+ def test_view_node_displays_node_info_no_owner(self):
+ # If the node has no owner, the Owner 'slot' does not exist.
+ node = factory.make_node()
+ node_link = reverse('node-view', args=[node.system_id])
+ response = self.client.get(node_link)
+ doc = fromstring(response.content)
+ content_text = doc.cssselect('#content')[0].text_content()
+ self.assertNotIn('Owner', content_text)
def test_view_node_displays_link_to_edit_if_user_owns_node(self):
node = factory.make_node(owner=self.logged_in_user)
@@ -621,18 +630,15 @@
def test_admin_can_edit_nodes(self):
node = factory.make_node(owner=factory.make_user())
node_edit_link = reverse('node-edit', args=[node.system_id])
- owner = random.choice([factory.make_user() for i in range(5)])
params = {
'hostname': factory.getRandomString(),
'after_commissioning_action': factory.getRandomEnum(
NODE_AFTER_COMMISSIONING_ACTION),
'power_type': factory.getRandomChoice(POWER_TYPE_CHOICES),
- 'owner': owner.id,
}
response = self.client.post(node_edit_link, params)
node = reload_object(node)
- params['owner'] = owner
self.assertEqual(httplib.FOUND, response.status_code)
self.assertAttributes(node, params)