]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Bug 437617: Make "type" a method of Bugzilla::WebService
authormkanat%bugzilla.org <>
Tue, 1 Jul 2008 13:19:20 +0000 (13:19 +0000)
committermkanat%bugzilla.org <>
Tue, 1 Jul 2008 13:19:20 +0000 (13:19 +0000)
Patch By Max Kanat-Alexander <mkanat@bugzilla.org> r=dkl, a=mkanat

Bugzilla/WebService.pm
Bugzilla/WebService/Bug.pm
Bugzilla/WebService/Bugzilla.pm
Bugzilla/WebService/Product.pm
Bugzilla/WebService/User.pm

index 94dbb621778ab2695a2ed3a65f8c0c8830c6c00c..7812a237be82ab963075effc3f7dbfe9d372813a 100755 (executable)
@@ -20,6 +20,7 @@ package Bugzilla::WebService;
 use strict;
 use Bugzilla::WebService::Constants;
 use Date::Parse;
+use XMLRPC::Lite;
 
 sub fail_unimplemented {
     my $this = shift;
@@ -62,6 +63,14 @@ sub login_exempt {
     return $class->LOGIN_EXEMPT->{$method};
 }
 
+sub type {
+    my ($self, $type, $value) = @_;
+    if ($type eq 'dateTime') {
+        $value = $self->datetime_format($value);
+    }
+    return XMLRPC::Data->type($type)->value($value);
+}
+
 1;
 
 package Bugzilla::WebService::XMLRPC::Transport::HTTP::CGI;
index 3323fd5ddb4ae6d9c08314256c4d57404b9700c7..1cdf44d83ad6ad6ac2771eb4148d3a923b21dd73 100755 (executable)
@@ -22,7 +22,6 @@ package Bugzilla::WebService::Bug;
 
 use strict;
 use base qw(Bugzilla::WebService);
-import SOAP::Data qw(type);
 
 use Bugzilla::Constants;
 use Bugzilla::Error;
@@ -87,17 +86,15 @@ sub get {
         # This is done in this fashion in order to produce a stable API.
         # The internals of Bugzilla::Bug are not stable enough to just
         # return them directly.
-        my $creation_ts = $self->datetime_format($bug->creation_ts);
-        my $delta_ts    = $self->datetime_format($bug->delta_ts);
         my %item;
-        $item{'creation_time'}    = type('dateTime')->value($creation_ts);
-        $item{'last_change_time'} = type('dateTime')->value($delta_ts);
+        $item{'creation_time'}    = $self->type('dateTime', $bug->creation_ts);
+        $item{'last_change_time'} = $self->type('dateTime', $bug->delta_ts);
         $item{'internals'}        = $bug;
-        $item{'id'}               = type('int')->value($bug->bug_id);
-        $item{'summary'}          = type('string')->value($bug->short_desc);
+        $item{'id'}               = $self->type('int', $bug->bug_id);
+        $item{'summary'}          = $self->type('string', $bug->short_desc);
 
         if (Bugzilla->params->{'usebugaliases'}) {
-            $item{'alias'} = type('string')->value($bug->alias);
+            $item{'alias'} = $self->type('string', $bug->alias);
         }
         else {
             # For API reasons, we always want the value to appear, we just
@@ -131,18 +128,18 @@ sub get_history {
 
         foreach my $changeset (@$activity) {
             my %bug_history;
-            $bug_history{when} = type('dateTime')->value(
+            $bug_history{when} = $self->type('dateTime',
                 $self->datetime_format($changeset->{when}));
-            $bug_history{who}  = type('string')->value($changeset->{who});
+            $bug_history{who}  = $self->type('string', $changeset->{who});
             $bug_history{changes} = [];
             foreach my $change (@{ $changeset->{changes} }) {
                 my $attach_id = delete $change->{attachid};
                 if ($attach_id) {
-                    $change->{attachment_id} = type('int')->value($attach_id);
+                    $change->{attachment_id} = $self->type('int', $attach_id);
                 }
-                $change->{removed} = type('string')->value($change->{removed});
-                $change->{added}   = type('string')->value($change->{added});
-                $change->{field_name} = type('string')->value(
+                $change->{removed} = $self->type('string', $change->{removed});
+                $change->{added}   = $self->type('string', $change->{added});
+                $change->{field_name} = $self->type('string',
                     delete $change->{fieldname});
                 # This is going to go away in the future from GetBugActivity
                 # so we shouldn't put it in the API.
@@ -157,7 +154,7 @@ sub get_history {
         # then they get to know which bug activity relates to which value  
         # they passed
         if (Bugzilla->params->{'usebugaliases'}) {
-            $item{alias} = type('string')->value($bug->alias);
+            $item{alias} = $self->type('string', $bug->alias);
         }
         else {
             # For API reasons, we always want the value to appear, we just
@@ -189,7 +186,7 @@ sub create {
 
     Bugzilla::BugMail::Send($bug->bug_id, { changer => $bug->reporter->login });
 
-    return { id => type('int')->value($bug->bug_id) };
+    return { id => $self->type('int', $bug->bug_id) };
 }
 
 sub legal_values {
@@ -232,7 +229,7 @@ sub legal_values {
 
     my @result;
     foreach my $val (@$values) {
-        push(@result, type('string')->value($val));
+        push(@result, $self->type('string', $val));
     }
 
     return { values => \@result };
index 7b58af254029a0db122823e5e44f1d010a859221..af64f4e3af1f28ee24d31e8c6c84551007a73348 100755 (executable)
@@ -22,7 +22,6 @@ use strict;
 use base qw(Bugzilla::WebService);
 use Bugzilla::Constants;
 use Bugzilla::Hook;
-import SOAP::Data qw(type);
 
 use Time::Zone;
 
@@ -33,26 +32,29 @@ use constant LOGIN_EXEMPT => {
 };
 
 sub version {
-    return { version => type('string')->value(BUGZILLA_VERSION) };
+    my $self = shift;
+    return { version => $self->type('string', BUGZILLA_VERSION) };
 }
 
 sub extensions {
+    my $self = shift;
     my $extensions = Bugzilla::Hook::enabled_plugins();
     foreach my $name (keys %$extensions) {
         my $info = $extensions->{$name};
-        foreach my $data (keys %$info)
-        {
-            $extensions->{$name}->{$data} = type('string')->value($info->{$data});
+        foreach my $data (keys %$info) {
+            $extensions->{$name}->{$data} = 
+                $self->type('string', $info->{$data});
         }
     }
     return { extensions => $extensions };
 }
 
 sub timezone {
+    my $self = shift;
     my $offset = tz_offset();
     $offset = (($offset / 60) / 60) * 100;
     $offset = sprintf('%+05d', $offset);
-    return { timezone => type('string')->value($offset) };
+    return { timezone => $self->type('string', $offset) };
 }
 
 1;
index 995e0adc02144efc26473a11a17366d4bdb7291f..0f15a7e30fe1474911204135fd517a825eeab2ee 100755 (executable)
@@ -21,7 +21,6 @@ use strict;
 use base qw(Bugzilla::WebService);
 use Bugzilla::Product;
 use Bugzilla::User;
-import SOAP::Data qw(type);
 
 ##################################################
 # Add aliases here for method name compatibility #
@@ -63,9 +62,9 @@ sub get {
     my @products = 
         map {{
                internals   => $_,
-               id          => type('int')->value($_->id),
-               name        => type('string')->value($_->name),
-               description => type('string')->value($_->description), 
+               id          => $self->type('int', $_->id),
+               name        => $self->type('string', $_->name),
+               description => $self->type('string', $_->description),
              }
         } @requested_accessible;
 
index fcc91c2dd3943bb9bcc5f0030a004b8d41d0f4ff..35e4daad4f22ba618d864afb3929ddaaf9b72ee5 100755 (executable)
@@ -22,8 +22,6 @@ package Bugzilla::WebService::User;
 use strict;
 use base qw(Bugzilla::WebService);
 
-import SOAP::Data qw(type); 
-
 use Bugzilla;
 use Bugzilla::Constants;
 use Bugzilla::Error;
@@ -63,7 +61,7 @@ sub login {
     $cgi->param('Bugzilla_remember', $remember);
 
     Bugzilla->login;
-    return { id => type('int')->value(Bugzilla->user->id) };
+    return { id => $self->type('int', Bugzilla->user->id) };
 }
 
 sub logout {
@@ -118,7 +116,7 @@ sub create {
         cryptpassword => $password
     });
 
-    return { id => type('int')->value($user->id) };
+    return { id => $self->type('int', $user->id) };
 }
 
 
@@ -149,9 +147,9 @@ sub get {
             ThrowUserError('user_access_by_match_denied');
         }
         @users = map {filter $params, {
-                     id => type('int')->value($_->id),
-                     real_name => type('string')->value($_->name), 
-                     name => type('string')->value($_->login),
+                     id        => $self->type('int', $_->id),
+                     real_name => $self->type('string', $_->name), 
+                     name      => $self->type('string', $_->login),
                  }} @user_objects;
 
         return { users => \@users };
@@ -195,24 +193,24 @@ sub get {
     if (Bugzilla->user->in_group('editusers')) {
         @users =
             map {filter $params, {
-                id => type('int')->value($_->id),
-                real_name => type('string')->value($_->name),
-                name => type('string')->value($_->login),
-                email => type('string')->value($_->email),
-                can_login => type('boolean')->value(!($_->is_disabled)),
-                email_enabled => type('boolean')->value($_->email_enabled),
-                login_denied_text => type('string')->value($_->disabledtext),
+                id        => $self->type('int', $_->id),
+                real_name => $self->type('string', $_->name),
+                name      => $self->type('string', $_->login),
+                email     => $self->type('string', $_->email),
+                can_login => $self->type('boolean', $_->is_disabled ? 0 : 1),
+                email_enabled     => $self->type('boolean', $_->email_enabled),
+                login_denied_text => $self->type('string', $_->disabledtext),
             }} @user_objects;
 
     }    
     else {
         @users =
             map {filter $params, {
-                id => type('int')->value($_->id),
-                real_name => type('string')->value($_->name),
-                name => type('string')->value($_->login),
-                email => type('string')->value($_->email),
-                can_login => type('boolean')->value(!($_->is_disabled)),
+                id        => $self->type('int', $_->id),
+                real_name => $self->type('string', $_->name),
+                name      => $self->type('string', $_->login),
+                email     => $self->type('string', $_->email),
+                can_login => $self->type('boolean', $_->is_disabled ? 0 : 1),
             }} @user_objects;
     }