Anonymous avatar Anonymous committed 319a0ac

Don't allow circular paths in pages

Comments (0)

Files changed (2)

gnocchi/cms/admin.py

 from django.contrib import admin
-from gnocchi.cms import settings, models
+from gnocchi.cms import settings, models, forms
 from gnocchi.tools.admin import InlineAttributeAdmin
 
 import os.path
     list_filter = ('parent', 'is_published',)
     list_editable = ('is_published',)
 
+    form = forms.PageAdminForm
+
     class Media:
         js = (
             'ckeditor/ckeditor.js',

gnocchi/cms/forms.py

+from django import forms
+from gnocchi.cms import models
+
+class PageAdminForm(forms.ModelForm):
+
+    class Meta:
+        model = models.Page
+
+    def clean(self):
+        data = self.cleaned_data
+        if self.instance.pk:
+            visited = set(self.instance)
+            p = data['parent']
+            while p:
+                if p in visited:
+                    raise forms.ValidationError("Page path is circular!")
+                visited.add(p)
+                p = p.parent
+        return data
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.