Login
[x]
Log in using an account from:
Fedora Account System
Red Hat Associate
Red Hat Customer
Or login using a Red Hat Bugzilla account
Forgot Password
Login:
Hide Forgot
Create an Account
Red Hat Bugzilla – Attachment 296864 Details for
Bug 434941
New WebService Module Component.pm
[?]
New
Simple Search
Advanced Search
My Links
Browse
Requests
Reports
Current State
Search
Tabular reports
Graphical reports
Duplicates
Other Reports
User Changes
Plotly Reports
Bug Status
Bug Severity
Non-Defaults
|
Product Dashboard
Help
Page Help!
Bug Writing Guidelines
What's new
Browser Support Policy
5.0.4.rh83 Release notes
FAQ
Guides index
User guide
Web Services
Contact
Legal
This site requires JavaScript to be enabled to function correctly, please enable it.
[patch]
new WebService module Component.pm + POD
patch.diff (text/plain), 21.53 KB, created by
Noura El hawary
on 2008-03-05 09:12:20 UTC
(
hide
)
Description:
new WebService module Component.pm + POD
Filename:
MIME Type:
Creator:
Noura El hawary
Created:
2008-03-05 09:12:20 UTC
Size:
21.53 KB
patch
obsolete
>Index: xmlrpc.cgi >=================================================================== >RCS file: /cvs/qa/rh_bugzilla_3/xmlrpc.cgi,v >retrieving revision 1.1.1.1 >diff -u -r1.1.1.1 xmlrpc.cgi >--- xmlrpc.cgi 19 Nov 2007 22:11:21 -0000 1.1.1.1 >+++ xmlrpc.cgi 5 Mar 2008 09:08:28 -0000 >@@ -39,6 +39,7 @@ > 'Bug' => 'Bugzilla::WebService::Bug', > 'User' => 'Bugzilla::WebService::User', > 'Product' => 'Bugzilla::WebService::Product', >+ 'Component' => 'Bugzilla::WebService::Component', > %hook_dispatch > }) > ->on_action(\&Bugzilla::WebService::handle_login) >Index: Bugzilla/WebService/Component.pm >=================================================================== >RCS file: Bugzilla/WebService/Component.pm >diff -N Bugzilla/WebService/Component.pm >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ Bugzilla/WebService/Component.pm 5 Mar 2008 09:09:06 -0000 >@@ -0,0 +1,603 @@ >+# -*- Mode: perl; indent-tabs-mode: nil -*- >+# >+# The contents of this file are subject to the Mozilla Public >+# License Version 1.1 (the "License"); you may not use this file >+# except in compliance with the License. You may obtain a copy of >+# the License at http://www.mozilla.org/MPL/ >+# >+# Software distributed under the License is distributed on an "AS >+# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or >+# implied. See the License for the specific language governing >+# rights and limitations under the License. >+# >+# The Initial Developer of the Original Code is Netscape Communications >+# Corporation. Portions created by Netscape are >+# Copyright (C) 1998 Netscape Communications Corporation. All >+# Rights Reserved. >+# >+# The Original Code is the Bugzilla Bug Tracking System. >+# >+# Contributor(s): Noura Elhawary <nelhawar@redhat.com> >+# >+ >+package Bugzilla::WebService::Component; >+ >+use strict; >+use base qw(Bugzilla::WebService); >+use Bugzilla::Product; >+use Bugzilla::Component; >+use Bugzilla::User; >+use Bugzilla::Constants; >+use Bugzilla::Error; >+use Bugzilla::Util qw(trim); >+import SOAP::Data qw(type); >+ >+ >+# function to return component information when passed either, >+# component ids or component and product names or both togther. >+# exmaple of how it will be called: >+# $call = $rpc->call( 'Component.get', >+# {ids => [1,2], names => [{component => 'testingComponent',product => 'TestProduct'}, >+# {component => 'testComponent22' ,product => 'TestProduct'} >+# ] >+# } >+# ); >+ >+sub get { >+ my ($self, $params) = @_; >+ >+ my $accessible_components = _get_accessible_components($params); >+ >+ my @components; >+ >+ if (!Bugzilla->user->id) { >+ @components = >+ map { >+ { id => type('int')->value( $_->id ), >+ name => type('string')->value( $_->name ), >+ description => type('string')->value( $_->description ), >+ product_id => type('int')->value( $_->product_id ), >+ product_name => type('string')->value( $_->product->name ), >+ default_assignee => >+ type('string')->value( $_->default_assignee->{realname} ), >+ default_qa_contact => >+ type('string')->value( $_->default_qa_contact->{realname} ), >+ default_cc => [ map $_->name, @{ $_->initial_cc } ], >+ >+ } >+ } @$accessible_components; >+ } >+ else { >+ @components = >+ map { >+ { id => type('int')->value( $_->id ), >+ name => type('string')->value( $_->name ), >+ description => type('string')->value( $_->description ), >+ product_id => type('int')->value( $_->product_id ), >+ product_name => type('string')->value( $_->product->name ), >+ default_assignee => >+ type('string')->value( $_->default_assignee->{login_name} ), >+ default_qa_contact => >+ type('string')->value( $_->default_qa_contact->{login_name} ), >+ default_cc => [ map $_->login, @{ $_->initial_cc } ], >+ } >+ } @$accessible_components; >+ } >+ >+ return { components => \@components }; >+} >+ >+# function to update component information when passed either, >+# component ids or component and product names or both togther. >+# exmaple of how it will be called: >+# $call = $rpc->call( 'Component.update', >+# {ids => [1,2], names => [{component => 'testingComponent',product => 'TestProduct'}, >+# {component => 'testComponent22' ,product => 'ProductA'} >+# ] >+# update => { default_assignee => 'testuser@redhat.com', name => 'comp1' } >+# } >+# ); >+ >+sub update { >+ my ($self, $params) = @_; >+ >+ my $user = Bugzilla->login(LOGIN_REQUIRED); >+ >+ $user->in_group('editcomponents') >+ || scalar(@{$user->get_products_by_permission('editcomponents')}) >+ || ThrowUserError("auth_failure", {group => "editcomponents", >+ action => "edit", >+ object => "components"}); >+ >+ my $accessible_components = _get_accessible_components($params); >+ >+ # if the user tries to change component name for several >+ # components of the same product then throw an error >+ my %unique_product_comps; >+ foreach my $comp (@$accessible_components) { >+ if($unique_product_comps{$comp->product_id} && (grep {$_ =~ /name/ } keys %{$params->{update}})){ >+ ThrowUserError("multiple_components_update_not_allowed"); >+ } >+ else { >+ $unique_product_comps{$comp->product_id} = 1; >+ } >+ } >+ >+ my %mapped_returns = ( >+ initialowner => 'default_assignee', >+ initialqacontact => 'default_qa_contact', >+ cc_list => 'default_cc', >+ ); >+ >+ my %changes; >+ >+ foreach my $component_obj (@$accessible_components) { >+ foreach my $field (keys %{$params->{update}}) { >+ my $method = "set_" . $field; >+ if ($field eq "default_cc"){ >+ $method = "set_cc_list"; >+ } >+ $component_obj->$method($params->{update}{$field}); >+ } >+ } >+ # map the field names in the returned changes hash to the >+ # right field name for API consistency and convert >+ # the user ids in the changes hash to login names >+ foreach my $component_obj (@$accessible_components) { >+ my $returned_changes = $component_obj->update(); >+ foreach my $changed_field (keys %{$returned_changes}) { >+ my $mapped_field = $mapped_returns{$changed_field} >+ || $changed_field; >+ if ($mapped_field eq 'default_assignee' || $mapped_field eq 'default_qa_contact') { >+ $changes{$component_obj->id}{$mapped_field} = >+ [ map $_->{login_name}, @{Bugzilla::User->new_from_list($returned_changes->{$changed_field})} ] >+ } >+ elsif ($mapped_field eq 'default_cc') { >+ my $cc_list = $returned_changes->{$changed_field}; >+ my @old_cclist = split( /[,\s]+/, $cc_list->[0] ); >+ my @new_cclist = split( /[,\s]+/, $cc_list->[1] ); >+ >+ my $old_cclist = join( ', ', ( map $_->{login_name}, @{Bugzilla::User->new_from_list(\@old_cclist)}) ); >+ my $new_cclist = join( ', ', ( map $_->{login_name}, @{Bugzilla::User->new_from_list(\@new_cclist)}) ); >+ >+ $changes{$component_obj->id}{$mapped_field} = [$old_cclist, $new_cclist]; >+ >+ } >+ else { >+ $changes{$component_obj->id}{$mapped_field} = $returned_changes->{$changed_field}; >+ } >+ } >+ } >+ >+ return { components_updates => \%changes }; >+ >+} >+ >+# function to create a component >+# the function can be called like this with the >+# component, product, initialowner and description as required arguments >+# $call = $rpc->call('Component.create', { component=> 'TestingComponent', >+# product => 'TestProduct', description => 'testing component', >+# default_assignee => 'testuser@redhat.com', >+# default_qa_contact => 'admin@redhat.com', >+# default_cc => ['testuserb@redhat.com, 'testuserc@redhat.com'] }); >+# >+sub create { >+ my ($self, $params) = @_; >+ >+ my $user = Bugzilla->login(LOGIN_REQUIRED); >+ >+ $user->in_group('editcomponents') >+ || scalar(@{$user->get_products_by_permission('editcomponents')}) >+ || ThrowUserError("auth_failure", {group => "editcomponents", >+ action => "edit", >+ object => "components"}); >+ >+ my $product_name = trim($params->{product}); >+ my $component_name = trim($params->{component}); >+ my $default_assignee = trim($params->{default_assignee}); >+ my $default_qa_contact = trim($params->{default_qa_contact}); >+ my $description = trim($params->{description}); >+ my $default_cc = $params->{default_cc}; >+ >+ my $product = $user->check_can_admin_product($product_name); >+ >+ my $component = >+ Bugzilla::Component->create({ name => $component_name, >+ product => $product, >+ description => $description, >+ initialowner => $default_assignee, >+ initialqacontact => $default_qa_contact, >+ initial_cc => $default_cc }); >+ >+ >+ return { id => type('int')->value($component->id) }; >+ >+} >+ >+ >+# subroutine to hold repeated code between Component.get and >+# Component.update, this function returns the unique accessible >+# Component objects to the user from list of component ids and >+# Component/product names. >+sub _get_accessible_components { >+ my $params = shift; >+ >+ my @ids = ref($params->{ids}) ? @{$params->{ids}} : ($params->{ids}); >+ my $obj_by_ids = Bugzilla::Component->new_from_list(\@ids) if $params->{ids}; >+ >+ my @names = ref($params->{names}) =~ /ARRAY/ ? @{$params->{names}} : >+ ($params->{names}); >+ >+ # to get the component objects for product/component combination >+ # first obtain the product object from the passed product name >+ my @component_objs = map Bugzilla::Component->check( >+ { product => Bugzilla::Product->check( { name => $_->{product} } ), >+ name => $_->{component} >+ } >+ ), >+ @names if $params->{names}; >+ >+ my %unique_components = map { $_->id => $_ } @component_objs; >+ @component_objs = values %unique_components; >+ >+ >+ foreach my $obj (@$obj_by_ids){ >+ push (@component_objs, $obj) if !$unique_components{$obj->id}; >+ } >+ >+ my @accessible_components; >+ >+ # if user is not logged in then return the viewable product components >+ # this can only happen with Component.get as login is required >+ # for Component.update >+ if (!Bugzilla->user->id) { >+ my @viewable_products = @{Bugzilla->user->get_enterable_products}; >+ my %products = map { $_->id => $_ } @viewable_products; >+ for my $comp_obj (@component_objs) { >+ push (@accessible_components, $comp_obj) if $products{$comp_obj->product_id}; >+ } >+ >+ return \@accessible_components; >+ } >+ >+ for my $comp_obj (@component_objs) { >+ if (Bugzilla->user->can_enter_product($comp_obj->product->name, THROW_ERROR)){ >+ push @accessible_components, $comp_obj; >+ } >+ } >+ >+ return \@accessible_components; >+} >+ >+1; >+ >+__END__ >+ >+=head1 NAME >+ >+Bugzilla::WebService::Component - The Component API >+ >+=head1 DESCRIPTION >+ >+This part of the Bugzilla API allows you to get info about accessible components, >+create new components and also edit the attributes of existing components. >+ >+=head1 METHODS >+ >+See L<Bugzilla::WebService> for a description of what B<STABLE>, B<UNSTABLE>, >+and B<EXPERIMENTAL> mean, and for more information about error codes. >+ >+=head2 Get Components >+ >+=over >+ >+=item C<get> B<UNSTABLE> >+ >+=over >+ >+=item B<Description> >+ >+Returns information about L<Bugzilla::Component|Components> in accessible >+L<Bugzilla::Product|Products>. >+ >+=item B<Params> >+ >+At least one of the following two parameters must be specified: >+ >+=over >+ >+=item C<ids> (array) or (int) - An array of integers or a single integer, >+representing components ids. >+ >+=item C<names> (array) or (hash) - An array of hashes or a single hash, each hash >+has product name and component name. >+ >+=back >+ >+=item B<Returns> >+ >+Logged-in users will get information about all accessible product >+components that they passed. Non-Logged-in users will get information >+only about viewable product components that they passed with hidden >+login names. >+ >+The return value will be A hash containing one item, C<components>, >+that is an array of hashes. Each hash describes a component, >+and has the following items: >+ >+=over >+ >+=item id >+ >+C<int> The unique integer ID that Bugzilla uses to identify this component. >+Even if the name of the component changes, this ID will stay the same. >+ >+=item name >+ >+C<string> The name of the component. >+ >+=item description >+ >+C<string> The description of the component. >+ >+=item product_id >+ >+C<int> The id of the product that the component belongs to. >+ >+=item product_name >+ >+C<string> The name of the product that the component belongs to. >+ >+=item default_assignee >+ >+C<string> The login name of the default owner of the component if >+the user is logged in, if the user is not logged in then only the >+realname of the default owner will be returned. >+ >+=item default_qa_contact >+ >+C<string> The login name of the default qa contact of the component if >+the user is logged in, if the user is not logged in then only the >+realname of the default qa contact will be returned. >+ >+=item default_cc >+ >+C<array> The default CC list for this component. It is an array >+of login names if the user is logged in. If the user is not logged in >+then only the realname of the default cc list members will be returned. >+ >+=back >+ >+=item B<Errors> >+ >+=over >+ >+=item 51 (Invalid Object) >+ >+A non existing product or component name was passed to the function, as a result no >+product or component object existed for that invalid name. >+ >+=item 106 (Invalid Product) >+ >+You were required to specify a product, and either you didn't, or you >+specified an invalid product (or a product that you can't access). >+ >+=back >+ >+=back >+ >+=back >+ >+=head2 Create Component >+ >+=over >+ >+=item C<create> B<EXPERIMENTAL> >+ >+=over >+ >+=item B<Description> >+ >+Creates new component for an existing product. >+ >+=item B<Params> >+ >+A hash containing the following component fields: >+ >+=over >+ >+=item product >+ >+C<string> B<Required> The name of the product that the component >+will be added to. >+ >+=item component >+ >+C<string> B<Required> The name of the new component. >+ >+=item description >+ >+C<string> B<Required> The description of the new component. >+ >+=item default_assignee >+ >+C<string> B<Required> The initial owner of the new component. >+ >+=item default_qa_contact >+ >+C<string> B<Optional> The initial qa contact for the new component. >+ >+=item default_cc >+ >+C<array> B<Optional> Array of the initial cclist for the new component. >+ >+=back >+ >+=item B<Returns> >+ >+A hash containing one item, C<id>, which is the id of the newly >+created component >+ >+=item B<Errors> >+ >+=over >+ >+=item 304 (Authorization Required) >+Logged-in user not authorized to create components. >+ >+=item 106 (Product Access Denied) >+Logged-in user doesn't have access to the specified product to create >+components for it. >+ >+=item 106 (Product Not Specified) >+Logged-in user didn't specify any product names for the component they want >+to create. >+ >+=item 106 (Product Doesn't Exist) >+The specified product doesn't exist. >+ >+=item 105 (Component Name Is Too Long) >+The name of the component is longer than 64 characters. >+ >+=item 105 (Component Requires Default Assignee) >+User didn't specify a default assignee for the new component. >+ >+=item 105 (Blank Component Description Not Allowed) >+User didn't specify a description for the new component. >+ >+=item 105 (Blank Component Name Not Allowed) >+User didn't specifiy name for the new component. >+ >+=item 105 (Component Already Exists) >+Trying to create a component which has similar name to an existing component. >+ >+=item 504 (Invalid Username) >+Invalid login name was provided for the component's default assignee, >+default qa contact or one of the default cc. >+ >+=back >+ >+=back >+ >+=back >+ >+=head2 Update Components >+ >+=over >+ >+=item C<update> B<UNSTABLE> >+ >+=over >+ >+=item B<Description> >+ >+Updates single or multiple components information. >+ >+=item B<Params> >+ >+A hash containing either C<ids>, that is an array of integers or >+a single integer representing the components ids, >+or C<names>, that is an array of hashes, each hash has >+product name and component name, or both together, and C<update> >+that is a hash containg the component fields that will be updated, >+the update has may contain any of the following items: >+ >+=over >+ >+=item name >+ >+C<string> The name of the component. >+ >+=item description >+ >+C<string> The description of the component. >+ >+=item default_assignee >+ >+C<string> The login name of the default owner of the component. >+ >+=item default_qa_contact >+ >+C<string> The login name of the default qa contact of the component. >+ >+=item default_cc >+ >+C<array> A list of the login names in the default cc list of the component. >+ >+=back >+ >+=item B<Returns> >+ >+A hash containing one item, C<updated_components>, which is a hash of hashes, >+with component ids as the hash keys pointing to hashes that contains >+the changes that were made to the component information. The hash may contain >+any of the following: >+ >+=over >+ >+=item name >+ >+C<array> An array of (strings) that holds the old and the new >+names of the component. >+ >+=item description >+ >+C<array> An array of (strings) that holds the old and the new >+descriptions of the component. >+ >+=item default_assignee >+ >+C<array> An Array of (strings) that holds the old and the new >+login names of the default owner of the component. >+ >+=item default_qa_contact >+ >+C<array> An array of (strings) that holds the old and the new >+login names of the default qa contact of the component. >+ >+=item default_cc >+ >+C<array> An array of (strings) that holds the old and the new >+lists of the login names in the default cc list of the component. >+ >+=back >+ >+=item B<Errors> >+ >+=over >+ >+=item 51 (Invalid Object) >+ >+A non existing product or component name was passed to the function, as a result no >+product or component object existed for that invalid name. >+ >+=item 106 (Invalid Product) >+ >+You were required to specify a product, and either you didn't, or you >+specified an invalid product (or a product that you can't access). >+ >+=item 304 (Authorization Required) >+Logged-in user not authorized to edit components. >+ >+=item 105 (Component Already Exists) >+Trying to change component name to similar name of an existing component >+of the same product. >+ >+=item 504 (Invalid Username) >+Invalid login name was provided for the component's default assignee, >+default qa contact or one of the default cc. >+ >+=item 105 (Component Name Is Too Long) >+The name of the component is longer than 64 characters. >+ >+=item 105 (Multiple Components Update Not Allowed) >+Can not do multiple components update when changing the name >+of multiple components of the same product. >+ >+=back >+ >+=back >+ >+=back >+ >Index: Bugzilla/WebService/Constants.pm >=================================================================== >RCS file: /cvs/qa/rh_bugzilla_3/Bugzilla/WebService/Constants.pm,v >retrieving revision 1.8 >diff -u -r1.8 Constants.pm >--- Bugzilla/WebService/Constants.pm 5 Mar 2008 08:43:06 -0000 1.8 >+++ Bugzilla/WebService/Constants.pm 5 Mar 2008 09:09:19 -0000 >@@ -71,11 +71,18 @@ > # Component errors > require_component => 105, > component_name_too_long => 105, >+ component_need_initialowner => 105, >+ component_blank_description => 105, >+ component_blank_name => 105, >+ component_already_exists => 105, >+ multiple_components_update_not_allowed => 105, > # Invalid Product > no_products => 106, > entry_access_denied => 106, > product_access_denied => 106, > product_disabled => 106, >+ product_not_specified => 106, >+ product_doesnt_exist => 106, > # Invalid Summary > require_summary => 107, > # Not authorized to edit the bug >Index: template/en/default/global/user-error.html.tmpl >=================================================================== >RCS file: /cvs/qa/rh_bugzilla_3/template/en/default/global/user-error.html.tmpl,v >retrieving revision 1.17 >diff -u -r1.17 user-error.html.tmpl >--- template/en/default/global/user-error.html.tmpl 5 Mar 2008 09:03:36 -0000 1.17 >+++ template/en/default/global/user-error.html.tmpl 5 Mar 2008 09:09:35 -0000 >@@ -1616,7 +1616,12 @@ > You can not change users password or login info when changing > several users at once, as these values need to be unique for > each user. >- >+ >+ [% ELSIF error == "multiple_components_update_not_allowed" %] >+ [% title = "Multiple Components Update Not allowed" %] >+ You can not update the name for multiple components of the >+ same product. >+ > [% ELSE %] > > [%# Try to find hooked error messages %]
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Flags:
dkl
: review+
Actions:
View
|
Diff
Attachments on
bug 434941
:
295907
|
296371
| 296864