RSS

trunk : 6117

mkanat%bugzilla.org
2008-07-01 08:19:20
Revision ID: cvs-1:mkanatbugzilla.org-20080701131920-7dd7af58venh5dfa
Bug 437617: Make "type" a method of Bugzilla::WebService Patch By Max Kanat-Alexander <mkanat@bugzilla.org> r=dkl, a=mkanat

collapse all collapse all

added added

removed removed

20
use strict;
20
use strict;
21
use Bugzilla::WebService::Constants;
21
use Bugzilla::WebService::Constants;
22
use Date::Parse;
22
use Date::Parse;
 
 
23
use XMLRPC::Lite;
23
 
24
 
24
sub fail_unimplemented {
25
sub fail_unimplemented {
25
    my $this = shift;
26
    my $this = shift;
62
    return $class->LOGIN_EXEMPT->{$method};
63
    return $class->LOGIN_EXEMPT->{$method};
63
}
64
}
64
 
65
 
 
 
66
sub type {
 
 
67
    my ($self, $type, $value) = @_;
 
 
68
    if ($type eq 'dateTime') {
 
 
69
        $value = $self->datetime_format($value);
 
 
70
    }
 
 
71
    return XMLRPC::Data->type($type)->value($value);
 
 
72
}
 
 
73
 
65
1;
74
1;
66
 
75
 
67
package Bugzilla::WebService::XMLRPC::Transport::HTTP::CGI;
76
package Bugzilla::WebService::XMLRPC::Transport::HTTP::CGI;
22
 
22
 
23
use strict;
23
use strict;
24
use base qw(Bugzilla::WebService);
24
use base qw(Bugzilla::WebService);
25
import SOAP::Data qw(type);
 
 
26
 
25
 
27
use Bugzilla::Constants;
26
use Bugzilla::Constants;
28
use Bugzilla::Error;
27
use Bugzilla::Error;
87
        # This is done in this fashion in order to produce a stable API.
86
        # This is done in this fashion in order to produce a stable API.
88
        # The internals of Bugzilla::Bug are not stable enough to just
87
        # The internals of Bugzilla::Bug are not stable enough to just
89
        # return them directly.
88
        # return them directly.
90
        my $creation_ts = $self->datetime_format($bug->creation_ts);
 
 
91
        my $delta_ts    = $self->datetime_format($bug->delta_ts);
 
 
92
        my %item;
89
        my %item;
93
        $item{'creation_time'}    = type('dateTime')->value($creation_ts);
90
        $item{'creation_time'}    = $self->type('dateTime', $bug->creation_ts);
94
        $item{'last_change_time'} = type('dateTime')->value($delta_ts);
91
        $item{'last_change_time'} = $self->type('dateTime', $bug->delta_ts);
95
        $item{'internals'}        = $bug;
92
        $item{'internals'}        = $bug;
96
        $item{'id'}               = type('int')->value($bug->bug_id);
93
        $item{'id'}               = $self->type('int', $bug->bug_id);
97
        $item{'summary'}          = type('string')->value($bug->short_desc);
94
        $item{'summary'}          = $self->type('string', $bug->short_desc);
98
 
95
 
99
        if (Bugzilla->params->{'usebugaliases'}) {
96
        if (Bugzilla->params->{'usebugaliases'}) {
100
            $item{'alias'} = type('string')->value($bug->alias);
97
            $item{'alias'} = $self->type('string', $bug->alias);
101
        }
98
        }
102
        else {
99
        else {
103
            # For API reasons, we always want the value to appear, we just
100
            # For API reasons, we always want the value to appear, we just
131
 
128
 
132
        foreach my $changeset (@$activity) {
129
        foreach my $changeset (@$activity) {
133
            my %bug_history;
130
            my %bug_history;
134
            $bug_history{when} = type('dateTime')->value(
131
            $bug_history{when} = $self->type('dateTime',
135
                $self->datetime_format($changeset->{when}));
132
                $self->datetime_format($changeset->{when}));
136
            $bug_history{who}  = type('string')->value($changeset->{who});
133
            $bug_history{who}  = $self->type('string', $changeset->{who});
137
            $bug_history{changes} = [];
134
            $bug_history{changes} = [];
138
            foreach my $change (@{ $changeset->{changes} }) {
135
            foreach my $change (@{ $changeset->{changes} }) {
139
                my $attach_id = delete $change->{attachid};
136
                my $attach_id = delete $change->{attachid};
140
                if ($attach_id) {
137
                if ($attach_id) {
141
                    $change->{attachment_id} = type('int')->value($attach_id);
138
                    $change->{attachment_id} = $self->type('int', $attach_id);
142
                }
139
                }
143
                $change->{removed} = type('string')->value($change->{removed});
140
                $change->{removed} = $self->type('string', $change->{removed});
144
                $change->{added}   = type('string')->value($change->{added});
141
                $change->{added}   = $self->type('string', $change->{added});
145
                $change->{field_name} = type('string')->value(
142
                $change->{field_name} = $self->type('string',
146
                    delete $change->{fieldname});
143
                    delete $change->{fieldname});
147
                # This is going to go away in the future from GetBugActivity
144
                # This is going to go away in the future from GetBugActivity
148
                # so we shouldn't put it in the API.
145
                # so we shouldn't put it in the API.
157
        # then they get to know which bug activity relates to which value  
154
        # then they get to know which bug activity relates to which value  
158
        # they passed
155
        # they passed
159
        if (Bugzilla->params->{'usebugaliases'}) {
156
        if (Bugzilla->params->{'usebugaliases'}) {
160
            $item{alias} = type('string')->value($bug->alias);
157
            $item{alias} = $self->type('string', $bug->alias);
161
        }
158
        }
162
        else {
159
        else {
163
            # For API reasons, we always want the value to appear, we just
160
            # For API reasons, we always want the value to appear, we just
189
 
186
 
190
    Bugzilla::BugMail::Send($bug->bug_id, { changer => $bug->reporter->login });
187
    Bugzilla::BugMail::Send($bug->bug_id, { changer => $bug->reporter->login });
191
 
188
 
192
    return { id => type('int')->value($bug->bug_id) };
189
    return { id => $self->type('int', $bug->bug_id) };
193
}
190
}
194
 
191
 
195
sub legal_values {
192
sub legal_values {
232
 
229
 
233
    my @result;
230
    my @result;
234
    foreach my $val (@$values) {
231
    foreach my $val (@$values) {
235
        push(@result, type('string')->value($val));
232
        push(@result, $self->type('string', $val));
236
    }
233
    }
237
 
234
 
238
    return { values => \@result };
235
    return { values => \@result };
22
use base qw(Bugzilla::WebService);
22
use base qw(Bugzilla::WebService);
23
use Bugzilla::Constants;
23
use Bugzilla::Constants;
24
use Bugzilla::Hook;
24
use Bugzilla::Hook;
25
import SOAP::Data qw(type);
 
 
26
 
25
 
27
use Time::Zone;
26
use Time::Zone;
28
 
27
 
33
};
32
};
34
 
33
 
35
sub version {
34
sub version {
36
    return { version => type('string')->value(BUGZILLA_VERSION) };
35
    my $self = shift;
 
 
36
    return { version => $self->type('string', BUGZILLA_VERSION) };
37
}
37
}
38
 
38
 
39
sub extensions {
39
sub extensions {
 
 
40
    my $self = shift;
40
    my $extensions = Bugzilla::Hook::enabled_plugins();
41
    my $extensions = Bugzilla::Hook::enabled_plugins();
41
    foreach my $name (keys %$extensions) {
42
    foreach my $name (keys %$extensions) {
42
        my $info = $extensions->{$name};
43
        my $info = $extensions->{$name};
43
        foreach my $data (keys %$info)
44
        foreach my $data (keys %$info) {
44
        {
45
            $extensions->{$name}->{$data} = 
45
            $extensions->{$name}->{$data} = type('string')->value($info->{$data});
46
                $self->type('string', $info->{$data});
46
        }
47
        }
47
    }
48
    }
48
    return { extensions => $extensions };
49
    return { extensions => $extensions };
49
}
50
}
50
 
51
 
51
sub timezone {
52
sub timezone {
 
 
53
    my $self = shift;
52
    my $offset = tz_offset();
54
    my $offset = tz_offset();
53
    $offset = (($offset / 60) / 60) * 100;
55
    $offset = (($offset / 60) / 60) * 100;
54
    $offset = sprintf('%+05d', $offset);
56
    $offset = sprintf('%+05d', $offset);
55
    return { timezone => type('string')->value($offset) };
57
    return { timezone => $self->type('string', $offset) };
56
}
58
}
57
 
59
 
58
1;
60
1;
21
use base qw(Bugzilla::WebService);
21
use base qw(Bugzilla::WebService);
22
use Bugzilla::Product;
22
use Bugzilla::Product;
23
use Bugzilla::User;
23
use Bugzilla::User;
24
import SOAP::Data qw(type);
 
 
25
 
24
 
26
##################################################
25
##################################################
27
# Add aliases here for method name compatibility #
26
# Add aliases here for method name compatibility #
63
    my @products = 
62
    my @products = 
64
        map {{
63
        map {{
65
               internals   => $_,
64
               internals   => $_,
66
               id          => type('int')->value($_->id),
65
               id          => $self->type('int', $_->id),
67
               name        => type('string')->value($_->name),
66
               name        => $self->type('string', $_->name),
68
               description => type('string')->value($_->description), 
67
               description => $self->type('string', $_->description),
69
             }
68
             }
70
        } @requested_accessible;
69
        } @requested_accessible;
71
 
70
 
22
use strict;
22
use strict;
23
use base qw(Bugzilla::WebService);
23
use base qw(Bugzilla::WebService);
24
 
24
 
25
import SOAP::Data qw(type); 
 
 
26
 
 
 
27
use Bugzilla;
25
use Bugzilla;
28
use Bugzilla::Constants;
26
use Bugzilla::Constants;
29
use Bugzilla::Error;
27
use Bugzilla::Error;
63
    $cgi->param('Bugzilla_remember', $remember);
61
    $cgi->param('Bugzilla_remember', $remember);
64
 
62
 
65
    Bugzilla->login;
63
    Bugzilla->login;
66
    return { id => type('int')->value(Bugzilla->user->id) };
64
    return { id => $self->type('int', Bugzilla->user->id) };
67
}
65
}
68
 
66
 
69
sub logout {
67
sub logout {
118
        cryptpassword => $password
116
        cryptpassword => $password
119
    });
117
    });
120
 
118
 
121
    return { id => type('int')->value($user->id) };
119
    return { id => $self->type('int', $user->id) };
122
}
120
}
123
 
121
 
124
 
122
 
149
            ThrowUserError('user_access_by_match_denied');
147
            ThrowUserError('user_access_by_match_denied');
150
        }
148
        }
151
        @users = map {filter $params, {
149
        @users = map {filter $params, {
152
                     id => type('int')->value($_->id),
150
                     id        => $self->type('int', $_->id),
153
                     real_name => type('string')->value($_->name), 
151
                     real_name => $self->type('string', $_->name), 
154
                     name => type('string')->value($_->login),
152
                     name      => $self->type('string', $_->login),
155
                 }} @user_objects;
153
                 }} @user_objects;
156
 
154
 
157
        return { users => \@users };
155
        return { users => \@users };
195
    if (Bugzilla->user->in_group('editusers')) {
193
    if (Bugzilla->user->in_group('editusers')) {
196
        @users =
194
        @users =
197
            map {filter $params, {
195
            map {filter $params, {
198
                id => type('int')->value($_->id),
196
                id        => $self->type('int', $_->id),
199
                real_name => type('string')->value($_->name),
197
                real_name => $self->type('string', $_->name),
200
                name => type('string')->value($_->login),
198
                name      => $self->type('string', $_->login),
201
                email => type('string')->value($_->email),
199
                email     => $self->type('string', $_->email),
202
                can_login => type('boolean')->value(!($_->is_disabled)),
200
                can_login => $self->type('boolean', $_->is_disabled ? 0 : 1),
203
                email_enabled => type('boolean')->value($_->email_enabled),
201
                email_enabled     => $self->type('boolean', $_->email_enabled),
204
                login_denied_text => type('string')->value($_->disabledtext),
202
                login_denied_text => $self->type('string', $_->disabledtext),
205
            }} @user_objects;
203
            }} @user_objects;
206
 
204
 
207
    }    
205
    }    
208
    else {
206
    else {
209
        @users =
207
        @users =
210
            map {filter $params, {
208
            map {filter $params, {
211
                id => type('int')->value($_->id),
209
                id        => $self->type('int', $_->id),
212
                real_name => type('string')->value($_->name),
210
                real_name => $self->type('string', $_->name),
213
                name => type('string')->value($_->login),
211
                name      => $self->type('string', $_->login),
214
                email => type('string')->value($_->email),
212
                email     => $self->type('string', $_->email),
215
                can_login => type('boolean')->value(!($_->is_disabled)),
213
                can_login => $self->type('boolean', $_->is_disabled ? 0 : 1),
216
            }} @user_objects;
214
            }} @user_objects;
217
    }
215
    }
218
 
216
 

Loggerhead runs on Bazaar branches