Skip to content

Commit

Permalink
Disable editing of configuration module and class details (#2970)
Browse files Browse the repository at this point in the history
* ConfigurationModule - disable name and parent
* ConfigurationClass - disable module and class_name

Changing these fields could be dissruptive for configuration of hosts.
  • Loading branch information
mkurek committed Mar 3, 2017
1 parent 16137c3 commit 655ba6b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
10 changes: 10 additions & 0 deletions src/ralph/assets/admin.py
Expand Up @@ -59,6 +59,11 @@ def objects_count(self, instance):
objects_count.short_description = _('Objects count')
objects_count.admin_order_field = 'objects_count'

def get_readonly_fields(self, request, obj=None):
if obj:
return self.readonly_fields + ['class_name', 'module']
return self.readonly_fields


@register(ConfigurationModule)
class ConfigurationModuleAdmin(CustomFieldValueAdminMixin, RalphMPTTAdmin):
Expand Down Expand Up @@ -104,6 +109,11 @@ def show_children_classes(self, module):
show_children_classes.allow_tags = True
show_children_classes.short_description = _('Children classes')

def get_readonly_fields(self, request, obj=None):
if obj:
return self.readonly_fields + ['name', 'parent']
return self.readonly_fields


@register(ServiceEnvironment)
class ServiceEnvironmentAdmin(CustomFieldValueAdminMixin, RalphAdmin):
Expand Down
6 changes: 6 additions & 0 deletions src/ralph/assets/api/views.py
Expand Up @@ -198,6 +198,9 @@ class ConfigurationModuleViewSet(RalphAPIViewSet):
serializer_class = serializers.ConfigurationModuleSerializer
save_serializer_class = serializers.ConfigurationModuleSimpleSerializer
filter_fields = ('parent', 'name')
# don't allow for ConfigurationModule updating or deleting as it might
# dissrupt configuration of many hosts!
http_method_names = ['get', 'post', 'options', 'head']


class ConfigurationClassViewSet(RalphAPIViewSet):
Expand All @@ -206,6 +209,9 @@ class ConfigurationClassViewSet(RalphAPIViewSet):
filter_fields = ('module', 'module__name', 'class_name', 'path')
select_related = ['module']
prefetch_related = ['tags']
# don't allow for ConfigurationClass updating or deleting as it might
# dissrupt configuration of many hosts!
http_method_names = ['get', 'post', 'options', 'head']


class BaseObjectViewSetMixin(object):
Expand Down
12 changes: 6 additions & 6 deletions src/ralph/assets/tests/test_api.py
Expand Up @@ -1039,9 +1039,9 @@ def test_patch_configuration_module(self):
'name': 'test_2'
}
response = self.client.patch(url, data, format='json')
self.assertEqual(response.status_code, status.HTTP_200_OK)
self.conf_module_2.refresh_from_db()
self.assertEqual(self.conf_module_2.name, 'test_2')
self.assertEqual(
response.status_code, status.HTTP_405_METHOD_NOT_ALLOWED
)


class ConfigurationClassAPITests(RalphAPITestCase):
Expand Down Expand Up @@ -1104,9 +1104,9 @@ def test_patch_configuration_class(self):
'class_name': 'test_2'
}
response = self.client.patch(url, data, format='json')
self.assertEqual(response.status_code, status.HTTP_200_OK)
self.conf_class_1.refresh_from_db()
self.assertEqual(self.conf_class_1.class_name, 'test_2')
self.assertEqual(
response.status_code, status.HTTP_405_METHOD_NOT_ALLOWED
)


class EthernetAPITests(RalphAPITestCase):
Expand Down

0 comments on commit 655ba6b

Please sign in to comment.