diff options
author | lpsolit%gmail.com <> | 2008-01-28 06:14:14 +0100 |
---|---|---|
committer | lpsolit%gmail.com <> | 2008-01-28 06:14:14 +0100 |
commit | c87cca60cfe149bf4ffe7ed1746189b936e87bac (patch) | |
tree | 0881e18732fa8baea267bf85cb94f8b2370141a1 /editsettings.cgi | |
parent | 132fcaa16d4035e3551a75c63d4de23dc11bb835 (diff) | |
download | bugzilla-c87cca60cfe149bf4ffe7ed1746189b936e87bac.tar.gz bugzilla-c87cca60cfe149bf4ffe7ed1746189b936e87bac.tar.xz |
Bug 325487: Admin pages should require less "clicks" (remove useless confirmation pages) - Patch by Frédéric Buclin <LpSolit@gmail.com> r=justdave r=mkanat a=LpSolit
Diffstat (limited to 'editsettings.cgi')
-rwxr-xr-x | editsettings.cgi | 91 |
1 files changed, 27 insertions, 64 deletions
diff --git a/editsettings.cgi b/editsettings.cgi index cf87e6326..d375a3d5d 100755 --- a/editsettings.cgi +++ b/editsettings.cgi @@ -14,7 +14,7 @@ # The Original Code is the Bugzilla Bug Tracking System. # # Contributor(s): Shane H. W. Travis <travis@sedsystems.ca> -# +# Frédéric Buclin <LpSolit@gmail.com> use strict; use lib qw(. lib); @@ -27,84 +27,47 @@ use Bugzilla::User::Setting; use Bugzilla::Token; my $template = Bugzilla->template; -local our $vars = {}; - -############################### -### Subroutine Definitions ### -############################### - -sub LoadSettings { - - $vars->{'settings'} = Bugzilla::User::Setting::get_defaults(); +my $user = Bugzilla->login(LOGIN_REQUIRED); +my $cgi = Bugzilla->cgi; +my $vars = {}; - my @setting_list = keys %{$vars->{'settings'}}; - $vars->{'setting_names'} = \@setting_list; -} +print $cgi->header; -sub SaveSettings{ +$user->in_group('tweakparams') + || ThrowUserError("auth_failure", {group => "tweakparams", + action => "modify", + object => "settings"}); - my $cgi = Bugzilla->cgi; +my $action = trim($cgi->param('action') || ''); +my $token = $cgi->param('token'); - $vars->{'settings'} = Bugzilla::User::Setting::get_defaults(); - my @setting_list = keys %{$vars->{'settings'}}; +if ($action eq 'update') { + check_token_data($token, 'edit_settings'); + my $settings = Bugzilla::User::Setting::get_defaults(); + my $changed = 0; - foreach my $name (@setting_list) { - my $changed = 0; - my $old_enabled = $vars->{'settings'}->{$name}->{'is_enabled'}; - my $old_value = $vars->{'settings'}->{$name}->{'default_value'}; + foreach my $name (keys %$settings) { + my $old_enabled = $settings->{$name}->{'is_enabled'}; + my $old_value = $settings->{$name}->{'default_value'}; my $enabled = defined $cgi->param("${name}-enabled") || 0; my $value = $cgi->param("${name}"); my $setting = new Bugzilla::User::Setting($name); $setting->validate_value($value); - if ( ($old_enabled != $enabled) || - ($old_value ne $value) ) { + if ($old_enabled != $enabled || $old_value ne $value) { Bugzilla::User::Setting::set_default($name, $value, $enabled); + $changed = 1; } } -} - -################### -### Live code ### -################### - -my $user = Bugzilla->login(LOGIN_REQUIRED); - -my $cgi = Bugzilla->cgi; -print $cgi->header; - -$user->in_group('tweakparams') - || ThrowUserError("auth_failure", {group => "tweakparams", - action => "modify", - object => "settings"}); - -my $action = trim($cgi->param('action') || 'load'); -my $token = $cgi->param('token'); - -if ($action eq 'update') { - check_token_data($token, 'edit_settings'); - SaveSettings(); + $vars->{'message'} = 'default_settings_updated'; + $vars->{'changes_saved'} = $changed; delete_token($token); - $vars->{'changes_saved'} = 1; - - $template->process("admin/settings/updated.html.tmpl", $vars) - || ThrowTemplateError($template->error()); - - exit; } -if ($action eq 'load') { - LoadSettings(); - $vars->{'token'} = issue_session_token('edit_settings'); - - $template->process("admin/settings/edit.html.tmpl", $vars) - || ThrowTemplateError($template->error()); +# Don't use $settings as defaults may have changed. +$vars->{'settings'} = Bugzilla::User::Setting::get_defaults(); +$vars->{'token'} = issue_session_token('edit_settings'); - exit; -} - -# -# No valid action found -# -ThrowUserError('no_valid_action', {'field' => "settings"}); +$template->process("admin/settings/edit.html.tmpl", $vars) + || ThrowTemplateError($template->error()); |