[Bps-public-commit] r17253 - in RT-FormTools: lib/RT/Extension

clkao at bestpractical.com clkao at bestpractical.com
Tue Dec 16 04:45:35 EST 2008


Author: clkao
Date: Tue Dec 16 04:45:34 2008
New Revision: 17253

Modified:
   RT-FormTools/html/FormTools/Form
   RT-FormTools/lib/RT/Extension/FormTools.pm

Log:
allowed field validation to be registered.

Modified: RT-FormTools/html/FormTools/Form
==============================================================================
--- RT-FormTools/html/FormTools/Form	(original)
+++ RT-FormTools/html/FormTools/Form	Tue Dec 16 04:45:34 2008
@@ -16,6 +16,21 @@
 my $real_next = delete $request_args{_form_tools_next};
 if ($validation && $real_next) {
     my $queue = $m->notes('queue');
+    # registered validation
+    if (my $validation = $m->notes('validation')) {
+        while (my ($key, $validator) = each (%$validation)) {
+            if (!ref $validator) {
+                my $code = RT::Extension::FormTools->can($validator);
+                my ($ok, $res) = $code->($request_args{$key});
+                push @results, "$key: $res" unless $ok;
+            }
+            else {
+                warn "unknown validator for $key, ignoring."
+            }
+        }
+    }
+
+    # cf validation based on record pattern
     foreach my $key (keys %request_args) {
         next if $key =~ /Values-Magic$/;
         next unless ($key =~ /CustomField-(\d+)/ );

Modified: RT-FormTools/lib/RT/Extension/FormTools.pm
==============================================================================
--- RT-FormTools/lib/RT/Extension/FormTools.pm	(original)
+++ RT-FormTools/lib/RT/Extension/FormTools.pm	Tue Dec 16 04:45:34 2008
@@ -74,4 +74,12 @@
     return ($valid, @res);
 }
 
+sub email_is_privileged {
+    my $email = shift;
+    my $user = RT::User->new($RT::SystemUser);
+    $user->LoadByEmail($email);
+    return (1) if ($user->id && $user->Privileged);
+    return (0, "Invalid account: $email");
+}
+
 1;



More information about the Bps-public-commit mailing list