summaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
authorByron Jones <glob@mozilla.com>2016-02-02 06:02:07 +0100
committerByron Jones <glob@mozilla.com>2016-02-02 06:02:07 +0100
commit92ec0f389512426625149f1d5fd89ece9a099151 (patch)
tree72cc6118fe80667404ec059ef9e5db85e117185b /scripts
parent939604e747a383cb03f15a1144bb5c9e89dab606 (diff)
downloadbugzilla-92ec0f389512426625149f1d5fd89ece9a099151.tar.gz
bugzilla-92ec0f389512426625149f1d5fd89ece9a099151.tar.xz
Bug 1244996 - add a script to manage a user's settings
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/user-prefs.pl57
1 files changed, 57 insertions, 0 deletions
diff --git a/scripts/user-prefs.pl b/scripts/user-prefs.pl
new file mode 100755
index 000000000..ca1b33d7d
--- /dev/null
+++ b/scripts/user-prefs.pl
@@ -0,0 +1,57 @@
+#!/usr/bin/perl -w
+
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+# This Source Code Form is "Incompatible With Secondary Licenses", as
+# defined by the Mozilla Public License, v. 2.0.
+
+use strict;
+use 5.10.1;
+
+use FindBin qw( $RealBin );
+use lib ("$RealBin/..", "$RealBin/../lib");
+
+use Bugzilla;
+use Bugzilla::Constants;
+use Bugzilla::User;
+use Bugzilla::User::APIKey;
+
+Bugzilla->usage_mode(USAGE_MODE_CMDLINE);
+
+my ($login, $action, $param, $value) = @ARGV;
+($login && $action && $action =~ /^(get|set)$/)
+ or die "syntax: $0 <bugzilla-login> <get|set> [param] [value]\n";
+
+my $user = Bugzilla::User->check({ name => $login });
+my $settings = $user->settings;
+
+if ($action eq 'get') {
+ if ($param eq '') {
+ foreach my $name (sort keys %$settings) {
+ printf "%s=%s\n", $name, $settings->{$name}->{value};
+ }
+ } elsif (exists $settings->{$param}) {
+ say $settings->{$param}->{value};
+ } else {
+ die "Invalid parameter name: $param\n";
+ }
+} else {
+ if ($param eq '') {
+ die "Parameter name required\n";
+ } elsif (!exists $settings->{$param}) {
+ die "Invalid parameter name: $param\n";
+ } elsif (!defined($value) || $value eq '') {
+ die "Missing parameter value\n";
+ } else {
+ my $setting = $settings->{$param};
+ # not using validate_value here so we can print out a list of the legal values
+ my $legal_values = $setting->legal_values;
+ if (! grep { $value eq $_ } @$legal_values) {
+ die "Invalid value '$value' for param $param.\nAccepted values: " . join(' ', @$legal_values) . "\n";
+ }
+ $setting->set($value);
+ say "'$param' set to '$value'";
+ }
+}