зеркало из https://github.com/mozilla/pjs.git
Bug 349368: Allow custom fields to be edited from editfields.cgi - Patch by Fr�d�ric Buclin <LpSolit@gmail.com> r=mkanat a=justdave
This commit is contained in:
Родитель
6356cf87a4
Коммит
5435127bfd
|
@ -284,7 +284,7 @@ Params: This function takes named parameters in a hashref:
|
|||
C<in_new_bugmail> - boolean - Whether this field appears at the
|
||||
top of the bugmail for a newly-filed bug.
|
||||
|
||||
The following parameters are only available on field creation:
|
||||
The following parameters are optional:
|
||||
C<custom> - boolean - True if this is a Custom Field. The field
|
||||
will be added to the C<bugs> table if it does not exist.
|
||||
C<sortkey> - integer - The sortkey of the field.
|
||||
|
@ -300,28 +300,43 @@ Returns: a C<Bugzilla::Field> object.
|
|||
|
||||
sub create_or_update {
|
||||
my ($params) = @_;
|
||||
my $dbh = Bugzilla->dbh;
|
||||
|
||||
my $custom = $params->{custom} ? 1 : 0;
|
||||
my $name = $params->{name};
|
||||
my $custom = $params->{custom} ? 1 : 0;
|
||||
my $in_new_bugmail = $params->{in_new_bugmail} ? 1 : 0;
|
||||
my $sortkey = $params->{sortkey} || 0;
|
||||
my $enter_bug = $params->{editable_on_enter_bug} ? 1 : 0;
|
||||
my $is_obsolete = $params->{is_obsolete} ? 1 : 0;
|
||||
|
||||
# Some day we'll allow invocants to specify the field type.
|
||||
# We don't care about $params->{type} yet.
|
||||
my $type = $custom ? FIELD_TYPE_FREETEXT : FIELD_TYPE_UNKNOWN;
|
||||
|
||||
my $field = new Bugzilla::Field({name => $name});
|
||||
|
||||
my $dbh = Bugzilla->dbh;
|
||||
if ($field) {
|
||||
# Both fields are mandatory.
|
||||
my @columns = ('description', 'mailhead');
|
||||
my @values = ($params->{desc}, $in_new_bugmail);
|
||||
|
||||
if (exists $params->{sortkey}) {
|
||||
push(@columns, 'sortkey');
|
||||
push(@values, $params->{sortkey} || 0);
|
||||
}
|
||||
if (exists $params->{editable_on_enter_bug}) {
|
||||
push(@columns, 'enter_bug');
|
||||
push(@values, $params->{editable_on_enter_bug} ? 1 : 0);
|
||||
}
|
||||
if (exists $params->{is_obsolete}) {
|
||||
push(@columns, 'obsolete');
|
||||
push(@values, $params->{is_obsolete} ? 1 : 0);
|
||||
}
|
||||
my $columns = join(', ', map {"$_ = ?"} @columns);
|
||||
# Update the already-existing definition.
|
||||
$dbh->do("UPDATE fielddefs SET description = ?, mailhead = ?
|
||||
WHERE id = ?",
|
||||
undef, $params->{desc}, $in_new_bugmail, $field->id);
|
||||
$dbh->do("UPDATE fielddefs SET $columns WHERE id = ?",
|
||||
undef, (@values, $field->id));
|
||||
}
|
||||
else {
|
||||
my $sortkey = $params->{sortkey} || 0;
|
||||
my $enter_bug = $params->{editable_on_enter_bug} ? 1 : 0;
|
||||
my $is_obsolete = $params->{is_obsolete} ? 1 : 0;
|
||||
|
||||
$sortkey ||= $dbh->selectrow_array(
|
||||
"SELECT MAX(sortkey) + 100 FROM fielddefs") || 100;
|
||||
|
||||
|
|
|
@ -98,17 +98,55 @@ elsif ($action eq 'new') {
|
|||
}
|
||||
elsif ($action eq 'edit') {
|
||||
my $name = $cgi->param('name') || ThrowUserError('customfield_missing_name');
|
||||
trick_taint($name);
|
||||
my @field = Bugzilla->get_fields({'name' => $name, 'custom' => 1});
|
||||
scalar(@field) || ThrowUserError('customfield_nonexistent', {'name' => $name});
|
||||
# Custom field names must start with "cf_".
|
||||
if ($name !~ /^cf_/) {
|
||||
$name = 'cf_' . $name;
|
||||
}
|
||||
my $field = new Bugzilla::Field({'name' => $name});
|
||||
$field || ThrowUserError('customfield_nonexistent', {'name' => $name});
|
||||
|
||||
$vars->{'field'} = $field[0];
|
||||
$vars->{'field'} = $field;
|
||||
|
||||
$template->process('admin/custom_fields/edit.html.tmpl', $vars)
|
||||
|| ThrowTemplateError($template->error());
|
||||
}
|
||||
elsif ($action eq 'update') {
|
||||
die "not yet implemented...\n";
|
||||
my $name = $cgi->param('name');
|
||||
my $desc = clean_text($cgi->param('desc') || '');
|
||||
my $sortkey = $cgi->param('sortkey') || 0;
|
||||
|
||||
# Validate fields.
|
||||
$name || ThrowUserError('customfield_missing_name');
|
||||
# Custom field names must start with "cf_".
|
||||
if ($name !~ /^cf_/) {
|
||||
$name = 'cf_' . $name;
|
||||
}
|
||||
my $field = new Bugzilla::Field({'name' => $name});
|
||||
$field || ThrowUserError('customfield_nonexistent', {'name' => $name});
|
||||
|
||||
$desc || ThrowUserError('customfield_missing_description', {'name' => $name});
|
||||
trick_taint($desc);
|
||||
|
||||
my $skey = $sortkey;
|
||||
detaint_natural($sortkey)
|
||||
|| ThrowUserError('customfield_invalid_sortkey', {'name' => $name,
|
||||
'sortkey' => $skey});
|
||||
|
||||
$vars->{'name'} = $field->name;
|
||||
$vars->{'desc'} = $desc;
|
||||
$vars->{'sortkey'} = $sortkey;
|
||||
$vars->{'custom'} = 1;
|
||||
$vars->{'in_new_bugmail'} = $cgi->param('new_bugmail') ? 1 : 0;
|
||||
$vars->{'editable_on_enter_bug'} = $cgi->param('enter_bug') ? 1 : 0;
|
||||
$vars->{'is_obsolete'} = $cgi->param('obsolete') ? 1 : 0;
|
||||
|
||||
Bugzilla::Field::create_or_update($vars);
|
||||
|
||||
$vars->{'custom_fields'} = [Bugzilla->get_fields({'custom' => 1})];
|
||||
$vars->{'message'} = 'custom_field_updated';
|
||||
|
||||
$template->process('admin/custom_fields/list.html.tmpl', $vars)
|
||||
|| ThrowTemplateError($template->error());
|
||||
}
|
||||
elsif ($action eq 'del') {
|
||||
die "not yet implemented...\n";
|
||||
|
|
|
@ -89,7 +89,7 @@
|
|||
<br>
|
||||
<input type="hidden" name="action" value="update">
|
||||
<input type="hidden" name="name" value="[% field.name FILTER html %]">
|
||||
<input type="submit" id="edit" value="Submit" disabled="disabled">
|
||||
<input type="submit" id="edit" value="Submit">
|
||||
</form>
|
||||
|
||||
<p>
|
||||
|
|
|
@ -165,6 +165,11 @@
|
|||
The new custom field '[% name FILTER html %]' has been
|
||||
successfully created.
|
||||
|
||||
[% ELSIF message_tag == "custom_field_updated" %]
|
||||
[% title = "Custom Field Updated" %]
|
||||
Properties of the '[% name FILTER html %]' field have been
|
||||
successfully updated.
|
||||
|
||||
[% ELSIF message_tag == "emailold_change_cancelled" %]
|
||||
[% title = "Cancel Request to Change Email Address" %]
|
||||
The request to change the email address for your account to
|
||||
|
|
Загрузка…
Ссылка в новой задаче