editsettings.cgi 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. #!/usr/bin/env perl -wT
  2. # -*- Mode: perl; indent-tabs-mode: nil -*-
  3. #
  4. # The contents of this file are subject to the Mozilla Public
  5. # License Version 1.1 (the "License"); you may not use this file
  6. # except in compliance with the License. You may obtain a copy of
  7. # the License at http://www.mozilla.org/MPL/
  8. #
  9. # Software distributed under the License is distributed on an "AS
  10. # IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
  11. # implied. See the License for the specific language governing
  12. # rights and limitations under the License.
  13. #
  14. # The Original Code is the Bugzilla Bug Tracking System.
  15. #
  16. # Contributor(s): Shane H. W. Travis <travis@sedsystems.ca>
  17. # Frédéric Buclin <LpSolit@gmail.com>
  18. use strict;
  19. use lib qw(. lib);
  20. use Bugzilla;
  21. use Bugzilla::Constants;
  22. use Bugzilla::Util;
  23. use Bugzilla::Error;
  24. use Bugzilla::User::Setting;
  25. use Bugzilla::Token;
  26. my $template = Bugzilla->template;
  27. my $user = Bugzilla->login(LOGIN_REQUIRED);
  28. my $cgi = Bugzilla->cgi;
  29. my $vars = {};
  30. print $cgi->header;
  31. $user->in_group('tweakparams')
  32. || ThrowUserError("auth_failure", {group => "tweakparams",
  33. action => "modify",
  34. object => "settings"});
  35. my $action = trim($cgi->param('action') || '');
  36. my $token = $cgi->param('token');
  37. if ($action eq 'update') {
  38. check_token_data($token, 'edit_settings');
  39. my $settings = Bugzilla::User::Setting::get_defaults();
  40. my $changed = 0;
  41. foreach my $name (keys %$settings) {
  42. my $old_enabled = $settings->{$name}->{'is_enabled'};
  43. my $old_value = $settings->{$name}->{'default_value'};
  44. my $enabled = defined $cgi->param("${name}-enabled") || 0;
  45. my $value = $cgi->param("${name}");
  46. my $setting = new Bugzilla::User::Setting($name);
  47. $setting->validate_value($value);
  48. if ($old_enabled != $enabled || $old_value ne $value) {
  49. Bugzilla::User::Setting::set_default($name, $value, $enabled);
  50. $changed = 1;
  51. }
  52. }
  53. $vars->{'message'} = 'default_settings_updated';
  54. $vars->{'changes_saved'} = $changed;
  55. delete_token($token);
  56. }
  57. # Don't use $settings as defaults may have changed.
  58. $vars->{'settings'} = Bugzilla::User::Setting::get_defaults();
  59. $vars->{'token'} = issue_session_token('edit_settings');
  60. $template->process("admin/settings/edit.html.tmpl", $vars)
  61. || ThrowTemplateError($template->error());