From e50fc49676a9dfdc958b17b2c4d0bf3fa72e8b69 Mon Sep 17 00:00:00 2001 From: Frédéric Buclin Date: Sat, 7 Jan 2012 14:13:16 +0100 Subject: Bug 443210: Implement Bugzilla.parameters to access parameters used in Bugzilla r/a=mkanat --- Bugzilla/WebService/Bugzilla.pm | 134 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 134 insertions(+) (limited to 'Bugzilla') diff --git a/Bugzilla/WebService/Bugzilla.pm b/Bugzilla/WebService/Bugzilla.pm index efc822311..865996efa 100644 --- a/Bugzilla/WebService/Bugzilla.pm +++ b/Bugzilla/WebService/Bugzilla.pm @@ -15,6 +15,7 @@ # Contributor(s): Marc Schumann # Max Kanat-Alexander # Mads Bondo Dydensborg +# Frédéric Buclin package Bugzilla::WebService::Bugzilla; @@ -22,22 +23,66 @@ use strict; use base qw(Bugzilla::WebService); use Bugzilla::Constants; use Bugzilla::Util qw(datetime_from); +use Bugzilla::WebService::Util qw(filter_wants); use DateTime; # Basic info that is needed before logins use constant LOGIN_EXEMPT => { + parameters => 1, timezone => 1, version => 1, }; use constant READ_ONLY => qw( extensions + parameters timezone time version ); +# Logged-out users do not need to know more than that. +use constant PARAMETERS_LOGGED_OUT => qw( + maintainer + requirelogin +); + +# These parameters are guessable from the web UI when the user +# is logged in. So it's safe to access them. +use constant PARAMETERS_LOGGED_IN => qw( + allowemailchange + attachment_base + commentonchange_resolution + commentonduplicate + cookiepath + defaultopsys + defaultplatform + defaultpriority + defaultseverity + duplicate_or_move_bug_status + emailregexpdesc + emailsuffix + letsubmitterchoosemilestone + letsubmitterchoosepriority + mailfrom + maintainer + maxattachmentsize + maxlocalattachment + musthavemilestoneonaccept + noresolveonopenblockers + password_complexity + rememberlogin + requirelogin + search_allow_no_criteria + urlbase + use_see_also + useclassification + useqacontact + usestatuswhiteboard + usetargetmilestone +); + sub version { my $self = shift; return { version => $self->type('string', BUGZILLA_VERSION) }; @@ -81,6 +126,25 @@ sub time { }; } +sub parameters { + my ($self, $args) = @_; + my $user = Bugzilla->login(); + my $params = Bugzilla->params; + $args ||= {}; + + my @params_list = $user->in_group('tweakparams') + ? keys(%$params) + : $user->id ? PARAMETERS_LOGGED_IN : PARAMETERS_LOGGED_OUT; + + my %parameters; + foreach my $param (@params_list) { + next unless filter_wants($args, $param); + $parameters{$param} = $self->type('string', $params->{$param}); + } + + return { parameters => \%parameters }; +} + 1; __END__ @@ -268,3 +332,73 @@ local timezone. =back =back + +=head2 parameters + +B + +=over + +=item B + +Returns parameter values currently used in this Bugzilla. + +=item B (none) + +=item B + +A hash with a single item C which contains a hash with +the name of the parameters as keys and their value as values. All +values are returned as strings. +The list of parameters returned by this method depends on the user +credentials: + +A logged-out user can only access the C and C parameters. + +A logged-in user can access the following parameters (listed alphabetically): + C, + C, + C, + C, + C, + C, + C, + C, + C, + C, + C, + C, + C, + C, + C, + C, + C, + C, + C, + C, + C, + C, + C, + C, + C, + C, + C, + C, + C, + C. + +A user in the tweakparams group can access all existing parameters. +New parameters can appear or obsolete parameters can disappear depending +on the version of Bugzilla and on extensions being installed. +The list of parameters returned by this method is not stable and will +never be stable. + +=item B + +=over + +=item Added in Bugzilla B<5.0>. + +=back + +=back -- cgit v1.2.3-24-g4f1b