← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] lp:~rvb/maas/maas-rename-NODE_PERMISSION into lp:maas

 

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

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~rvb/maas/maas-rename-NODE_PERMISSION/+merge/100576

bzr ls -VR --kind=file --null | xargs -r0 grep -Iil NODE_PERMISSIONS --null | xargs -r0 sed -i 's/NODE_PERMISSIONS/NODE_PERMISSION/g'
-- 
https://code.launchpad.net/~rvb/maas/maas-rename-NODE_PERMISSION/+merge/100576
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~rvb/maas/maas-rename-NODE_PERMISSION into lp:maas.
=== modified file 'src/maasserver/api.py'
--- src/maasserver/api.py	2012-04-03 07:09:40 +0000
+++ src/maasserver/api.py	2012-04-03 10:22:47 +0000
@@ -103,7 +103,7 @@
     FileStorage,
     MACAddress,
     Node,
-    NODE_PERMISSIONS,
+    NODE_PERMISSION,
     NODE_STATUS,
     )
 from piston.doc import generate_doc
@@ -321,12 +321,12 @@
     def read(self, request, system_id):
         """Read a specific Node."""
         return Node.objects.get_node_or_404(
-            system_id=system_id, user=request.user, perm=NODE_PERMISSIONS.VIEW)
+            system_id=system_id, user=request.user, perm=NODE_PERMISSION.VIEW)
 
     def update(self, request, system_id):
         """Update a specific Node."""
         node = Node.objects.get_node_or_404(
-            system_id=system_id, user=request.user, perm=NODE_PERMISSIONS.EDIT)
+            system_id=system_id, user=request.user, perm=NODE_PERMISSION.EDIT)
         for key, value in request.data.items():
             setattr(node, key, value)
         node.save()
@@ -336,7 +336,7 @@
         """Delete a specific Node."""
         node = Node.objects.get_node_or_404(
             system_id=system_id, user=request.user,
-            perm=NODE_PERMISSIONS.ADMIN)
+            perm=NODE_PERMISSION.ADMIN)
         node.delete()
         return rc.DELETED
 
@@ -387,7 +387,7 @@
     def release(self, request, system_id):
         """Release a node.  Opposite of `NodesHandler.acquire`."""
         node = Node.objects.get_node_or_404(
-            system_id=system_id, user=request.user, perm=NODE_PERMISSIONS.EDIT)
+            system_id=system_id, user=request.user, perm=NODE_PERMISSION.EDIT)
         if node.status == NODE_STATUS.READY:
             # Nothing to do.  This may be a redundant retry, and the
             # postcondition is achieved, so call this success.
@@ -568,14 +568,14 @@
     def read(self, request, system_id):
         """Read all MAC Addresses related to a Node."""
         node = Node.objects.get_node_or_404(
-            user=request.user, system_id=system_id, perm=NODE_PERMISSIONS.VIEW)
+            user=request.user, system_id=system_id, perm=NODE_PERMISSION.VIEW)
 
         return MACAddress.objects.filter(node=node).order_by('id')
 
     def create(self, request, system_id):
         """Create a MAC Address for a specified Node."""
         node = Node.objects.get_node_or_404(
-            user=request.user, system_id=system_id, perm=NODE_PERMISSIONS.EDIT)
+            user=request.user, system_id=system_id, perm=NODE_PERMISSION.EDIT)
         mac = node.add_mac_address(request.data.get('mac_address', None))
         return mac
 
@@ -593,7 +593,7 @@
     def read(self, request, system_id, mac_address):
         """Read a MAC Address related to a Node."""
         node = Node.objects.get_node_or_404(
-            user=request.user, system_id=system_id, perm=NODE_PERMISSIONS.VIEW)
+            user=request.user, system_id=system_id, perm=NODE_PERMISSION.VIEW)
 
         validate_mac(mac_address)
         return get_object_or_404(
@@ -603,7 +603,7 @@
         """Delete a specific MAC Address for the specified Node."""
         validate_mac(mac_address)
         node = Node.objects.get_node_or_404(
-            user=request.user, system_id=system_id, perm=NODE_PERMISSIONS.EDIT)
+            user=request.user, system_id=system_id, perm=NODE_PERMISSION.EDIT)
 
         mac = get_object_or_404(MACAddress, node=node, mac_address=mac_address)
         mac.delete()

=== modified file 'src/maasserver/forms.py'
--- src/maasserver/forms.py	2012-04-03 07:09:40 +0000
+++ src/maasserver/forms.py	2012-04-03 10:22:47 +0000
@@ -51,7 +51,7 @@
     Node,
     NODE_AFTER_COMMISSIONING_ACTION,
     NODE_AFTER_COMMISSIONING_ACTION_CHOICES,
-    NODE_PERMISSIONS,
+    NODE_PERMISSION,
     NODE_STATUS,
     SSHKey,
     UserProfile,
@@ -211,7 +211,7 @@
     NODE_STATUS.DECLARED: [
         {
             'display': "Accept Enlisted node",
-            'permission': NODE_PERMISSIONS.ADMIN,
+            'permission': NODE_PERMISSION.ADMIN,
             'execute': lambda node, user: Node.accept_enlistment(node),
         },
     ],

=== modified file 'src/maasserver/models.py'
--- src/maasserver/models.py	2012-04-03 07:09:40 +0000
+++ src/maasserver/models.py	2012-04-03 10:22:47 +0000
@@ -18,7 +18,7 @@
     "Config",
     "FileStorage",
     "NODE_STATUS",
-    "NODE_PERMISSIONS",
+    "NODE_PERMISSION",
     "NODE_TRANSITIONS",
     "Node",
     "MACAddress",
@@ -453,7 +453,7 @@
         return None
 
 
-class NODE_PERMISSIONS:
+class NODE_PERMISSION:
     VIEW = 'view_node'
     EDIT = 'edit_node'
     ADMIN = 'admin_node'
@@ -1209,11 +1209,11 @@
             raise NotImplementedError(
                 'Invalid permission check (invalid object type).')
 
-        if perm == NODE_PERMISSIONS.VIEW:
+        if perm == NODE_PERMISSION.VIEW:
             return obj.owner in (None, user)
-        elif perm == NODE_PERMISSIONS.EDIT:
+        elif perm == NODE_PERMISSION.EDIT:
             return obj.owner == user
-        elif perm == NODE_PERMISSIONS.ADMIN:
+        elif perm == NODE_PERMISSION.ADMIN:
             # 'admin_node' permission is solely granted to superusers.
             return False
         else:

=== modified file 'src/maasserver/tests/test_api.py'
--- src/maasserver/tests/test_api.py	2012-04-03 07:15:11 +0000
+++ src/maasserver/tests/test_api.py	2012-04-03 10:22:47 +0000
@@ -1148,7 +1148,7 @@
             MACAddress.objects.filter(node=node).count())
 
     def test_macs_POST_add_mac_without_edit_perm(self):
-        # Adding a MAC Address to a node requires the NODE_PERMISSIONS.EDIT
+        # Adding a MAC Address to a node requires the NODE_PERMISSION.EDIT
         # permission.
         node = factory.make_node()
         response = self.client.post(

=== modified file 'src/maasserver/tests/test_auth.py'
--- src/maasserver/tests/test_auth.py	2012-04-03 07:09:40 +0000
+++ src/maasserver/tests/test_auth.py	2012-04-03 10:22:47 +0000
@@ -17,7 +17,7 @@
 from maasserver.models import (
     MAASAuthorizationBackend,
     Node,
-    NODE_PERMISSIONS,
+    NODE_PERMISSION,
     NODE_STATUS,
     )
 from maasserver.testing.factory import factory
@@ -80,7 +80,7 @@
         mac = make_unallocated_node().add_mac_address('AA:BB:CC:DD:EE:FF')
         self.assertRaises(
             NotImplementedError, backend.has_perm,
-            factory.make_admin(), NODE_PERMISSIONS.VIEW, mac)
+            factory.make_admin(), NODE_PERMISSION.VIEW, mac)
 
     def test_invalid_check_permission(self):
         backend = MAASAuthorizationBackend()
@@ -91,19 +91,19 @@
     def test_node_init_user_cannot_access(self):
         backend = MAASAuthorizationBackend()
         self.assertFalse(backend.has_perm(
-            get_node_init_user(), NODE_PERMISSIONS.VIEW,
+            get_node_init_user(), NODE_PERMISSION.VIEW,
             make_unallocated_node()))
 
     def test_user_can_access_unowned_node(self):
         backend = MAASAuthorizationBackend()
         self.assertTrue(backend.has_perm(
-            factory.make_user(), NODE_PERMISSIONS.VIEW,
+            factory.make_user(), NODE_PERMISSION.VIEW,
             make_unallocated_node()))
 
     def test_user_cannot_access_nodes_owned_by_others(self):
         backend = MAASAuthorizationBackend()
         self.assertFalse(backend.has_perm(
-            factory.make_user(), NODE_PERMISSIONS.VIEW, make_allocated_node()))
+            factory.make_user(), NODE_PERMISSION.VIEW, make_allocated_node()))
 
     def test_owned_status(self):
         # A non-admin user can access nodes he owns.
@@ -111,33 +111,33 @@
         node = make_allocated_node()
         self.assertTrue(
             backend.has_perm(
-                node.owner, NODE_PERMISSIONS.VIEW, node))
+                node.owner, NODE_PERMISSION.VIEW, node))
 
     def test_user_cannot_edit_nodes_owned_by_others(self):
         backend = MAASAuthorizationBackend()
         self.assertFalse(backend.has_perm(
-            factory.make_user(), NODE_PERMISSIONS.EDIT, make_allocated_node()))
+            factory.make_user(), NODE_PERMISSION.EDIT, make_allocated_node()))
 
     def test_user_cannot_edit_unowned_node(self):
         backend = MAASAuthorizationBackend()
         self.assertFalse(backend.has_perm(
-            factory.make_user(), NODE_PERMISSIONS.EDIT,
+            factory.make_user(), NODE_PERMISSION.EDIT,
             make_unallocated_node()))
 
     def test_user_can_edit_his_own_nodes(self):
         backend = MAASAuthorizationBackend()
         user = factory.make_user()
         self.assertTrue(backend.has_perm(
-            user, NODE_PERMISSIONS.EDIT, make_allocated_node(owner=user)))
+            user, NODE_PERMISSION.EDIT, make_allocated_node(owner=user)))
 
     def test_user_has_no_admin_permission_on_node(self):
-        # NODE_PERMISSIONS.ADMIN permission on nodes is granted to super users
+        # NODE_PERMISSION.ADMIN permission on nodes is granted to super users
         # only.
         backend = MAASAuthorizationBackend()
         user = factory.make_user()
         self.assertFalse(
             backend.has_perm(
-                user, NODE_PERMISSIONS.ADMIN, factory.make_node()))
+                user, NODE_PERMISSION.ADMIN, factory.make_node()))
 
 
 class TestNodeVisibility(TestCase):

=== modified file 'src/maasserver/tests/test_forms.py'
--- src/maasserver/tests/test_forms.py	2012-04-03 07:09:40 +0000
+++ src/maasserver/tests/test_forms.py	2012-04-03 10:22:47 +0000
@@ -38,7 +38,7 @@
     Config,
     DEFAULT_CONFIG,
     NODE_AFTER_COMMISSIONING_ACTION_CHOICES,
-    NODE_PERMISSIONS,
+    NODE_PERMISSION,
     NODE_STATUS,
     NODE_STATUS_CHOICES_DICT,
     POWER_TYPE_CHOICES,
@@ -295,7 +295,7 @@
             ["Accept Enlisted node"],
             [transition['display'] for transition in transitions])
         self.assertEqual(
-            [NODE_PERMISSIONS.ADMIN],
+            [NODE_PERMISSION.ADMIN],
             [transition['permission'] for transition in transitions])
 
     def test_available_transition_methods_for_declared_node_simple_user(self):
@@ -327,7 +327,7 @@
 
         self.assertItemsEqual(
             {"Accept Enlisted node": (
-                'accept_enlistment', NODE_PERMISSIONS.ADMIN)},
+                'accept_enlistment', NODE_PERMISSION.ADMIN)},
             form.transition_dict)
 
     def test_get_transition_form_for_user(self):

=== modified file 'src/maasserver/tests/test_models.py'
--- src/maasserver/tests/test_models.py	2012-04-03 07:09:40 +0000
+++ src/maasserver/tests/test_models.py	2012-04-03 10:22:47 +0000
@@ -43,7 +43,7 @@
     HELLIPSIS,
     MACAddress,
     Node,
-    NODE_PERMISSIONS,
+    NODE_PERMISSION,
     NODE_STATUS,
     NODE_STATUS_CHOICES,
     NODE_STATUS_CHOICES_DICT,
@@ -435,7 +435,7 @@
         self.assertEqual(
             node,
             Node.objects.get_node_or_404(
-                node.system_id, user, NODE_PERMISSIONS.VIEW))
+                node.system_id, user, NODE_PERMISSION.VIEW))
 
     def test_get_visible_node_or_404_raises_PermissionDenied(self):
         """get_node_or_404 raises PermissionDenied if the provided
@@ -444,7 +444,7 @@
         self.assertRaises(
             PermissionDenied,
             Node.objects.get_node_or_404,
-            user_node.system_id, factory.make_user(), NODE_PERMISSIONS.VIEW)
+            user_node.system_id, factory.make_user(), NODE_PERMISSION.VIEW)
 
     def test_get_available_node_for_acquisition_finds_available_node(self):
         user = factory.make_user()

=== modified file 'src/maasserver/views.py'
--- src/maasserver/views.py	2012-04-03 09:40:38 +0000
+++ src/maasserver/views.py	2012-04-03 10:22:47 +0000
@@ -89,7 +89,7 @@
 from maasserver.messages import messaging
 from maasserver.models import (
     Node,
-    NODE_PERMISSIONS,
+    NODE_PERMISSION,
     SSHKey,
     UserProfile,
     )
@@ -118,7 +118,7 @@
         system_id = self.kwargs.get('system_id', None)
         node = Node.objects.get_node_or_404(
             system_id=system_id, user=self.request.user,
-            perm=NODE_PERMISSIONS.VIEW)
+            perm=NODE_PERMISSION.VIEW)
         return node
 
     def get_form_class(self):
@@ -128,7 +128,7 @@
         context = super(NodeView, self).get_context_data(**kwargs)
         node = self.get_object()
         context['can_edit'] = self.request.user.has_perm(
-            NODE_PERMISSIONS.EDIT, node)
+            NODE_PERMISSION.EDIT, node)
         return context
 
     def get_success_url(self):
@@ -143,7 +143,7 @@
         system_id = self.kwargs.get('system_id', None)
         node = Node.objects.get_node_or_404(
             system_id=system_id, user=self.request.user,
-            perm=NODE_PERMISSIONS.EDIT)
+            perm=NODE_PERMISSION.EDIT)
         return node
 
     def get_form_class(self):