... | ... |
@@ -5,7 +5,7 @@ requires 'DBIx::Custom', '== 0.28'; |
5 | 5 |
requires 'Config::Tiny', '== 2.14'; |
6 | 6 |
requires 'Time::HiRes', '== 1.9725'; |
7 | 7 |
requires 'Test::Simple', '== 0.98'; |
8 |
-requires 'Validator::Custom', '== 0.22'; |
|
8 |
+requires 'Validator::Custom', '== 1.01'; |
|
9 | 9 |
requires 'DBIx::Connector', '== 0.53'; |
10 | 10 |
requires 'Module::Build', '== 0.4003'; |
11 | 11 |
requires 'Test::Harness', '== 3.26'; |
... | ... |
@@ -19,29 +19,31 @@ |
19 | 19 |
my $errors; |
20 | 20 |
if (lc $self->req->method eq 'post') { |
21 | 21 |
if ($op eq 'add') { |
22 |
- my $params = $api->params; |
|
23 |
- my $rule = [ |
|
24 |
- collaborator => [ |
|
25 |
- ['not_blank' => 'collaborator is empty.'], |
|
26 |
- # Check user |
|
27 |
- sub { |
|
28 |
- my $collaborator = shift || ''; |
|
29 |
- |
|
30 |
- if ($collaborator eq $user) { |
|
31 |
- return {result => 0, message => "User $collaborator is yourself"}; |
|
32 |
- } |
|
33 |
- else { |
|
34 |
- my $row = app->dbi->model('user')->select(id => $collaborator)->one; |
|
35 |
- |
|
36 |
- return $row ? 1 : {result => 0, message => "User $collaborator don't exists"}; |
|
37 |
- } |
|
38 |
- } |
|
39 |
- ] |
|
40 |
- ]; |
|
41 |
- my $vresult = app->vc->validate($params, $rule); |
|
42 |
- if ($vresult->is_ok) { |
|
43 |
- my $safe_params = $vresult->data; |
|
44 |
- my $collaborator = $safe_params->{collaborator}; |
|
22 |
+ my $collaborator = param('collaborator'); |
|
23 |
+ |
|
24 |
+ # Validator |
|
25 |
+ my $vc = app->vc; |
|
26 |
+ |
|
27 |
+ # Validation result |
|
28 |
+ my $validation = $vc->validation; |
|
29 |
+ |
|
30 |
+ # collaborator check |
|
31 |
+ if (!length $collaborator) { |
|
32 |
+ $validation->add_failed(collaborator => "collaborator is empty"); |
|
33 |
+ } |
|
34 |
+ elsif ($collaborator eq $user) { |
|
35 |
+ $validation->add_failed(collaborator => "User $collaborator is yourself"); |
|
36 |
+ } |
|
37 |
+ else { |
|
38 |
+ my $row = app->dbi->model('user')->select( |
|
39 |
+ where => {id => $collaborator} |
|
40 |
+ )->one; |
|
41 |
+ if (!$row) { |
|
42 |
+ $validation->add_failed(collaborator => "User $collaborator don't exists"); |
|
43 |
+ } |
|
44 |
+ } |
|
45 |
+ |
|
46 |
+ if ($validation->is_valid) { |
|
45 | 47 |
|
46 | 48 |
# Insert |
47 | 49 |
eval { |
... | ... |
@@ -64,7 +66,7 @@ |
64 | 66 |
} |
65 | 67 |
} |
66 | 68 |
else { |
67 |
- $errors = $vresult->messages; |
|
69 |
+ $errors = $validation->messages; |
|
68 | 70 |
} |
69 | 71 |
} |
70 | 72 |
elsif ($op eq 'remove') { |