changeset 2504:96f95afaf6f8

POC for ACL validation
author sharky93 <rishabhr123@gmail.com>
date Sun, 22 Sep 2013 13:34:06 +0530
parents 0ed4403dac04
children 49ea7807635a
files MoinMoin/items/__init__.py MoinMoin/themes/basic/static/css/basic.css MoinMoin/themes/basic/static/custom-less/basic.less MoinMoin/themes/basic/templates/modify.html
diffstat 4 files changed, 16 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/items/__init__.py	Sat Sep 21 23:46:23 2013 +0530
+++ b/MoinMoin/items/__init__.py	Sun Sep 22 13:34:06 2013 +0530
@@ -27,6 +27,7 @@
 from flask import request, Response, redirect, abort, escape
 
 from flatland import Form
+from flatland.validation import Validator
 
 from jinja2 import Markup
 
@@ -175,10 +176,21 @@
     submit_label = L_('OK')
 
 
+class ACLValidator(Validator):
+    """
+    Meta Validator - currently used for validating ACLs only
+    """
+    acl_fail_msg = L_("The ACL string is invalid")
+
+    def validate(self, element, state):
+        return self.note_error(element, state, 'acl_fail_msg')
+
+
 class BaseMetaForm(Form):
+
     itemtype = RequiredText.using(label=L_("Item type")).with_properties(placeholder=L_("Item type"))
     contenttype = RequiredText.using(label=L_("Content type")).with_properties(placeholder=L_("Content type"))
-    acl = RequiredText.using(label=L_("ACL")).with_properties(placeholder=L_("Access Control List"))
+    acl = RequiredText.using(label=L_("ACL")).with_properties(placeholder=L_("Access Control List")).validated_by(ACLValidator())
     # Disabled - Flatland doesn't distinguish emtpy value and nonexistent
     # value, while an emtpy acl and no acl have different semantics
     #acl = OptionalText.using(label=L_('ACL')).with_properties(placeholder=L_("Access Control List"))
--- a/MoinMoin/themes/basic/static/css/basic.css	Sat Sep 21 23:46:23 2013 +0530
+++ b/MoinMoin/themes/basic/static/css/basic.css	Sun Sep 22 13:34:06 2013 +0530
@@ -4310,6 +4310,7 @@
   background-color: #f2dede;
   border-color: #eed3d7;
   color: #b94a48;
+  padding-left: 0px;
 }
 .moin-flash-warning > a,
 .moin-flash-error > a,
--- a/MoinMoin/themes/basic/static/custom-less/basic.less	Sat Sep 21 23:46:23 2013 +0530
+++ b/MoinMoin/themes/basic/static/custom-less/basic.less	Sun Sep 22 13:34:06 2013 +0530
@@ -62,6 +62,7 @@
     list-style-type: none;
   }
   .alert-danger;
+  padding-left: 0px;
 }
 
 .moin-user-action-special {
--- a/MoinMoin/themes/basic/templates/modify.html	Sat Sep 21 23:46:23 2013 +0530
+++ b/MoinMoin/themes/basic/templates/modify.html	Sun Sep 22 13:34:06 2013 +0530
@@ -18,6 +18,7 @@
     <div id="checkmodifyview"> </div>
     {{ gen.form.open(form, method='post', enctype='multipart/form-data') }}
     {{ forms.render_errors(form) }}
+    {{ forms.render_errors(form['meta_form']['acl']) }}
     {#
        Workaround:
        For *Draw content, hide submit button and form['comment'], since *Draw