--- a/Allura/allura/lib/validators.py
+++ b/Allura/allura/lib/validators.py
@@ -1,4 +1,5 @@
from bson import ObjectId
+import formencode as fe
from formencode import validators as fev
class Ming(fev.FancyValidator):
@@ -18,3 +19,12 @@
def _from_python(self, value, state):
return value._id
+
+class UniqueOAuthApplicationName(fev.UnicodeString):
+
+ def _to_python(self, value, state):
+ from allura import model as M
+ app = M.OAuthConsumerToken.query.get(name=value)
+ if app is not None:
+ raise fe.Invalid('That name is already taken, please choose another', value, state)
+ return value