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 295904 Details for
Bug 427905
replace XMLRPC function addComponent with Component.create()
[?]
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]
v1 for function Bugzilla::WebService::Component::create()
patch.diff (text/plain), 11.21 KB, created by
Noura El hawary
on 2008-02-26 13:37:45 UTC
(
hide
)
Description:
v1 for function Bugzilla::WebService::Component::create()
Filename:
MIME Type:
Creator:
Noura El hawary
Created:
2008-02-26 13:37:45 UTC
Size:
11.21 KB
patch
obsolete
>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 26 Feb 2008 06:57:46 -0000 >@@ -0,0 +1,295 @@ >+# -*- 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 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 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}; >+ $mapped_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 }; >+ >+} >+ >+# 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 $obj_by_ids = Bugzilla::Component->new_from_list($params->{ids}) >+ if $params->{ids}; >+ >+ my @component_objs; >+ >+ # 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} >+ } >+ ), >+ @{ $params->{names} } >+ if $params->{names}; >+ >+ my %unique_components; >+ map { $unique_components{$_->id} = $_ } @component_objs; >+ >+ >+ foreach my $obj (@$obj_by_ids){ >+ push (@component_objs, $obj) if !$unique_components{$obj->id}; >+ } >+ >+ my @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 list accessible components and >+get information about them. >+ >+=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 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 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.5 >diff -3 -p -u -r1.5 Constants.pm >--- Bugzilla/WebService/Constants.pm 12 Feb 2008 19:45:14 -0000 1.5 >+++ Bugzilla/WebService/Constants.pm 26 Feb 2008 06:57:54 -0000 >@@ -71,6 +71,8 @@ use constant WS_ERROR_CODE => { > # Component errors > require_component => 105, > component_name_too_long => 105, >+ component_already_exists => 105, >+ multiple_components_update_not_allowed => 105, > # Invalid Product > no_products => 106, > entry_access_denied => 106, >@@ -86,6 +88,7 @@ use constant WS_ERROR_CODE => { > account_disabled => 301, > auth_invalid_email => 302, > extern_id_conflict => -303, >+ auth_failure => 304, > > # User errors are 500-600. > account_exists => 500, >Index: template/en/default/global/user-error.html.tmpl >=================================================================== >RCS file: /cvsroot/mozilla/webtools/bugzilla/template/en/default/global/user-error.html.tmpl,v >retrieving revision 1.244 >diff -3 -p -u -r1.244 user-error.html.tmpl >--- template/en/default/global/user-error.html.tmpl 6 Feb 2008 16:15:41 -0000 1.244 >+++ template/en/default/global/user-error.html.tmpl 26 Feb 2008 06:58:14 -0000 >@@ -1595,6 +1595,11 @@ > [% title = "Illegal User ID" %] > User ID '[% userid FILTER html %]' is not valid integer. > >+ [% 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
Actions:
View
|
Diff
Attachments on
bug 427905
:
295904
|
295905