Commit c9e867f7 authored by lpsolit%gmail.com's avatar lpsolit%gmail.com

Bug 298688: Forbid the deletion of values used by default for the priority,…

Bug 298688: Forbid the deletion of values used by default for the priority, severity, platform and OS and update data/params when editing them - Patch by Frédéric Buclin <LpSolit@gmail.com> r=GavinS a=justdave
parent b2966165
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
# The Original Code is the Bugzilla Bug Tracking System. # The Original Code is the Bugzilla Bug Tracking System.
# #
# Contributor(s): Max Kanat-Alexander <mkanat@bugzilla.org> # Contributor(s): Max Kanat-Alexander <mkanat@bugzilla.org>
# Frédéric Buclin <LpSolit@gmail.com>
# This is a script to edit the values of fields that have drop-down # This is a script to edit the values of fields that have drop-down
# or select boxes. It is largely a copy of editmilestones.cgi, but # or select boxes. It is largely a copy of editmilestones.cgi, but
...@@ -20,11 +21,12 @@ ...@@ -20,11 +21,12 @@
use strict; use strict;
use lib "."; use lib ".";
require "globals.pl";
use Bugzilla; use Bugzilla;
use Bugzilla::Util; use Bugzilla::Util;
use Bugzilla::Error; use Bugzilla::Error;
use Bugzilla::Constants; use Bugzilla::Constants;
use Bugzilla::Config qw(:DEFAULT :locations); use Bugzilla::Config qw(:DEFAULT :admin :locations);
# List of different tables that contain the changeable field values # List of different tables that contain the changeable field values
# (the old "enums.") Keep them in alphabetical order by their # (the old "enums.") Keep them in alphabetical order by their
...@@ -115,6 +117,13 @@ my $value = trim($cgi->param('value') || ''); ...@@ -115,6 +117,13 @@ my $value = trim($cgi->param('value') || '');
my $sortkey = trim($cgi->param('sortkey') || '0'); my $sortkey = trim($cgi->param('sortkey') || '0');
my $action = trim($cgi->param('action') || ''); my $action = trim($cgi->param('action') || '');
# Gives the name of the parameter associated with the field
# and representing its default value.
my %defaults = {};
$defaults{'op_sys'} = 'defaultopsys';
$defaults{'rep_platform'} = 'defaultplatform';
$defaults{'priority'} = 'defaultpriority';
$defaults{'bug_severity'} = 'defaultseverity';
# #
# field = '' -> Show nice list of fields # field = '' -> Show nice list of fields
...@@ -148,6 +157,7 @@ unless ($action) { ...@@ -148,6 +157,7 @@ unless ($action) {
{Slice =>{}}); {Slice =>{}});
$vars->{'field'} = $field; $vars->{'field'} = $field;
$vars->{'values'} = $fieldvalues; $vars->{'values'} = $fieldvalues;
$vars->{'default'} = Param($defaults{$field});
$template->process("admin/fieldvalues/list.html.tmpl", $template->process("admin/fieldvalues/list.html.tmpl",
$vars) $vars)
|| ThrowTemplateError($template->error()); || ThrowTemplateError($template->error());
...@@ -237,6 +247,7 @@ if ($action eq 'del') { ...@@ -237,6 +247,7 @@ if ($action eq 'del') {
$vars->{'value'} = $value; $vars->{'value'} = $value;
$vars->{'field'} = $field; $vars->{'field'} = $field;
$vars->{'param_name'} = $defaults{$field};
$template->process("admin/fieldvalues/confirm-delete.html.tmpl", $template->process("admin/fieldvalues/confirm-delete.html.tmpl",
$vars) $vars)
|| ThrowTemplateError($template->error()); || ThrowTemplateError($template->error());
...@@ -250,6 +261,11 @@ if ($action eq 'del') { ...@@ -250,6 +261,11 @@ if ($action eq 'del') {
# #
if ($action eq 'delete') { if ($action eq 'delete') {
ValueMustExist($field, $value); ValueMustExist($field, $value);
if ($value eq Param($defaults{$field})) {
ThrowUserError('fieldvalue_is_default', {field => $field,
value => $value,
param_name => $defaults{$field}})
}
trick_taint($field); trick_taint($field);
trick_taint($value); trick_taint($value);
...@@ -368,6 +384,19 @@ if ($action eq 'update') { ...@@ -368,6 +384,19 @@ if ($action eq 'update') {
$dbh->bz_unlock_tables(); $dbh->bz_unlock_tables();
# If the old value was the default value for the field,
# update data/params accordingly.
# This update is done while tables are unlocked due to the
# annoying call to GetVersionTable in Bugzilla/Config/Common.pm.
if ($value ne $valueold
&& $valueold eq Param($defaults{$field}))
{
SetParam($defaults{$field}, $value);
WriteParams();
unlink "$datadir/versioncache";
$vars->{'default_value_updated'} = 1;
}
$vars->{'value'} = $value; $vars->{'value'} = $value;
$vars->{'field'} = $field; $vars->{'field'} = $field;
$template->process("admin/fieldvalues/updated.html.tmpl", $template->process("admin/fieldvalues/updated.html.tmpl",
......
...@@ -20,6 +20,8 @@ ...@@ -20,6 +20,8 @@
# value_count: number; The number of values left for this field, including # value_count: number; The number of values left for this field, including
# this value. # this value.
# field: string; The name of the field. # field: string; The name of the field.
# param_name: string; The name of the parameter (defaultxxx) associated
# with the field.
#%] #%]
[% title = BLOCK %]Delete Value '[% value FILTER html %]' from the [% title = BLOCK %]Delete Value '[% value FILTER html %]' from the
...@@ -27,6 +29,7 @@ ...@@ -27,6 +29,7 @@
[% PROCESS global/header.html.tmpl [% PROCESS global/header.html.tmpl
title = title title = title
style_urls = ['skins/standard/admin.css']
%] %]
<table border="1" cellpadding="4" cellspacing="0"> <table border="1" cellpadding="4" cellspacing="0">
...@@ -58,19 +61,32 @@ ...@@ -58,19 +61,32 @@
<h2>Confirmation</h2> <h2>Confirmation</h2>
[% IF bug_count %] [% IF (Param(param_name) == value) || bug_count || (value_count == 1) %]
<p>Sorry, but the '[% value FILTER html %]' value cannot be deleted
from the '[% field FILTER html %]' field for the following reason(s):</p>
Sorry, there <ul class="warningmessages">
[% IF Param(param_name) == value %]
<li>'[% value FILTER html %]' is the default value for
the '[% field FILTER html %]' field.
[% IF user.groups.tweakparams %]
You first have to <a href="editparams.cgi?section=bugfields#
[%- param_name FILTER url_quote %]">change the default value</a> for
this field before you can delete this value.
[% END %]
[% END %]
[% IF bug_count %]
<li>There
[% IF bug_count > 1 %] [% IF bug_count > 1 %]
are [% bug_count FILTER html %] [%+ terms.bugs %] are [% bug_count FILTER html %] [%+ terms.bugs %]
[% ELSE %] [% ELSE %]
is [% bug_count FILTER html %] [%+ terms.bug %] is 1 [% terms.bug %]
[% END %] [% END %]
with this field value. You must change the field value on
that still have this field value. You must change the field value on
<a title="List of [% terms.bugs %] where '[% field FILTER html %]' is '[% value FILTER html %]'" <a title="List of [% terms.bugs %] where '[% field FILTER html %]' is '[% value FILTER html %]'"
href="buglist.cgi?[% field FILTER url_quote %]=[%- value FILTER url_quote %]"> href="buglist.cgi?[% field FILTER url_quote %]=[% value FILTER url_quote %]">
[% IF bug_count > 1 %] [% IF bug_count > 1 %]
those [% terms.bugs %] those [% terms.bugs %]
[% ELSE %] [% ELSE %]
...@@ -78,19 +94,17 @@ ...@@ -78,19 +94,17 @@
[% END %] [% END %]
</a> </a>
to another value before you can delete this value. to another value before you can delete this value.
[% END %]
[% END %] [% IF value_count == 1 %]
<li>'[% value FILTER html %]' is the last value for
[% IF value_count == 1 %] '[%- field FILTER html %]', and so it can not be deleted.
[% END %]
<p>Sorry, but '[% value FILTER html %]' is the last value for </ul>
'[%- field FILTER html %]', and so it can not be deleted.</p>
[% ELSE %]
[% IF bug_count == 0 %] [% ELSE %]
<p>Do you really want to delete this value?<p> <p>Do you really want to delete this value?</p>
<form method="post" action="editvalues.cgi"> <form method="post" action="editvalues.cgi">
<input type="submit" value="Yes, delete"> <input type="submit" value="Yes, delete">
...@@ -99,8 +113,6 @@ ...@@ -99,8 +113,6 @@
<input type="hidden" name="value" value="[% value FILTER html %]"> <input type="hidden" name="value" value="[% value FILTER html %]">
</form> </form>
[% END %]
[% END %] [% END %]
[% PROCESS admin/fieldvalues/footer.html.tmpl [% PROCESS admin/fieldvalues/footer.html.tmpl
......
...@@ -50,18 +50,28 @@ ...@@ -50,18 +50,28 @@
name => "sortkey" name => "sortkey"
heading => "Sortkey" heading => "Sortkey"
}, },
] {
%] name => "action"
[% columns.push({
heading => "Action" heading => "Action"
content => "Delete" content => "Delete"
contentlink => delete_contentlink contentlink => delete_contentlink
}) %] } ]
%]
[% overrides.action = [ {
match_value => "$default"
match_field => 'name'
override_content => 1
content => "(Default value)"
override_contentlink => 1
contentlink => undef
} ]
%]
[% PROCESS admin/table.html.tmpl [% PROCESS admin/table.html.tmpl
columns = columns columns = columns
data = values data = values
overrides = overrides
%] %]
<p> <p>
......
...@@ -24,6 +24,8 @@ ...@@ -24,6 +24,8 @@
# value & updated_value: the name of the field value # value & updated_value: the name of the field value
# sortkey & updated_sortkey: the field value sortkey # sortkey & updated_sortkey: the field value sortkey
# field: string; the field that the value belongs to # field: string; the field that the value belongs to
# default_value_updated: boolean; whether the default value for
# this field has been updated
#%] #%]
[% title = BLOCK %]Updating Value '[% value FILTER html %]' of the [% title = BLOCK %]Updating Value '[% value FILTER html %]' of the
...@@ -34,6 +36,10 @@ ...@@ -34,6 +36,10 @@
[% IF updated_value %] [% IF updated_value %]
<p>Updated field value to: '[% value FILTER html %]'.</p> <p>Updated field value to: '[% value FILTER html %]'.</p>
[% IF default_value_updated %]
<p>Note that this value is the default for this field.
All references to the default value will now point to this new value.</p>
[% END %]
[% END %] [% END %]
[% IF updated_sortkey %] [% IF updated_sortkey %]
......
...@@ -384,6 +384,15 @@ ...@@ -384,6 +384,15 @@
The value '[% value FILTER html %]' does not exist for The value '[% value FILTER html %]' does not exist for
the '[% field FILTER html %]' field. the '[% field FILTER html %]' field.
[% ELSIF error == "fieldvalue_is_default" %]
[% title = "Specified Field Value Is Default" %]
'[% value FILTER html %]' is the default value for
the '[% field FILTER html %]' field and cannot be deleted.
[% IF user.groups.tweakparams %]
You have to <a href="editparams.cgi?section=bugfields#
[%- param_name FILTER url_quote %]">change</a> the default value first.
[% END %]
[% ELSIF error == "fieldvalue_name_too_long" %] [% ELSIF error == "fieldvalue_name_too_long" %]
[% title = "Field Value Is Too Long" %] [% title = "Field Value Is Too Long" %]
The value of a field is limited to 60 characters. The value of a field is limited to 60 characters.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment