]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Bug 257767: Option to have fields in CSV files separated by semicolons instead of...
authorlpsolit%gmail.com <>
Wed, 20 Jul 2005 09:23:33 +0000 (09:23 +0000)
committerlpsolit%gmail.com <>
Wed, 20 Jul 2005 09:23:33 +0000 (09:23 +0000)
Bugzilla/User/Setting.pm
checksetup.pl
editsettings.cgi
template/en/default/filterexceptions.pl
template/en/default/global/code-error.html.tmpl
template/en/default/global/setting-descs.none.tmpl
template/en/default/list/list.csv.tmpl
template/en/default/reports/chart.csv.tmpl
template/en/default/reports/report-table.csv.tmpl
userprefs.cgi

index df1ba28f879617f1573ca6faef0f4f40c36dc536..a5ce9411f00e078ca7b0bfd0b40bc8c53c01ac4a 100644 (file)
@@ -27,6 +27,7 @@ use base qw(Exporter);
      add_setting);
 
 use Bugzilla::Error;
+use Bugzilla::Util qw{trick_taint};
 
 ###############################
 ###  Module Initialization  ###
@@ -224,6 +225,19 @@ sub legal_values {
     return $self->{'legal_values'};
 }
 
+sub validate_value {
+    my $self = shift;
+
+    if (grep(/^$_[0]$/, @{$self->legal_values()})) {
+        trick_taint($_[0]);
+    }
+    else {
+        ThrowCodeError('setting_value_invalid',
+                       {'name'  => $self->{'_setting_name'},
+                        'value' => $_[0]});
+    }
+}
+
 sub reset_to_default {
     my ($self) = @_;
 
@@ -346,6 +360,15 @@ Description: Returns all legal values for this setting
 Params:      none
 Returns:     A reference to an array containing all legal values
 
+=item C<validate_value>
+
+Description: Determines whether a value is valid for the setting
+             by checking against the list of legal values.
+             Untaints the parameter if the value is indeed valid,
+             and throws a setting_value_invalid code error if not.
+Params:      An lvalue containing a candidate for a setting value
+Returns:     nothing
+
 =item C<reset_to_default>
 
 Description: If a user chooses to use the global default for a given 
index a19083ad9294875d8f2ee22bb07d313847423ea2..c219afda821ebc200ad99a5aae29d030a188d3c5 100755 (executable)
@@ -4051,6 +4051,9 @@ add_setting ("comment_sort_order", {"oldest_to_newest" => 1,
                                     "newest_to_oldest_desc_first" => 3}, 
              "oldest_to_newest" );
 
+# 2005-06-29 wurblzap@gmail.com -- Bug 257767
+add_setting ('csv_colsepchar', {',' => 1, ';' => 2 }, ',' );
+
 ###########################################################################
 # Create Administrator  --ADMIN--
 ###########################################################################
index b5e810ba9f38a23f81f5f3edf9af728f86bec6eb..80a8921d561518aaf09d0ac986c44ab36394c0b1 100755 (executable)
@@ -54,11 +54,9 @@ sub SaveSettings{
         my $old_value   = $vars->{'settings'}->{$name}->{'default_value'};
         my $enabled = defined $cgi->param("${name}-enabled") || 0;
         my $value = $cgi->param("${name}");
+        my $setting = new Bugzilla::User::Setting($name);
 
-        # remove taint
-        if ($value =~ /^(\w+)$/ ) {
-            $value = $1;
-        }
+        $setting->validate_value($value);
 
         if ( ($old_enabled != $enabled) ||
              ($old_value ne $value) ) {
index bfa46948160c9fed69a874ea179ca859cdb7cafc..053b712b404fb5d64f8a2dcf1438e4a561849ff7 100644 (file)
 'reports/report-table.csv.tmpl' => [
   'num_bugs',
   'data.$tbl.$col.$row',
-  'title',
+  'colsepchar',
 ],
 
 'reports/report-table.html.tmpl' => [
 
 'reports/chart.csv.tmpl' => [
   'data.$j.$i', 
+  'colsepchar',
 ],
 
 'reports/create-chart.html.tmpl' => [
 
 'list/list.csv.tmpl' => [
   'bug.bug_id', 
+  'colsepchar',
 ],
 
 'list/list.js.tmpl' => [
index 36a752949a22a0a3808b86cf2493243e4064ce3a..608e9a08fea16f352f61a5f726c7301430c7bd24 100644 (file)
     option. Setting names must begin with a letter, and contain only
     letters, digits, or the symbols '_', '-', '.', or ':'.
 
+  [% ELSIF error == "setting_value_invalid" %]
+    The value "<code>[% value FILTER html %]</code>" is not in the list of
+    legal values for the <em>[% name FILTER html %]</em> setting.
+
   [% ELSIF error == "token_generation_error" %]
     Something is seriously wrong with the token generation system.
 
index 1a31754a8eb8968be198b58db5d7e37c9fd87bf5..f4992aa4817931549bc1d3b0fa7af179530b770c 100644 (file)
@@ -21,6 +21,7 @@
 
 [% setting_descs = { 
    "comment_sort_order"               => "When viewing $terms.abug, show comments in this order",
+   "csv_colsepchar"                   => "Field separator character for CSV files",
    "display_quips"                    => "Show a quip at the top of each bug list",
    "newest_to_oldest"                 => "Newest to Oldest",
    "newest_to_oldest_desc_first"      => "Newest to Oldest, but keep Description at the top",
index 2731b6613f4730375a5834fbc1e468ae2e8cfe8b..76df4f4da72b9a78e74cd1ff131f590913fa3e81 100644 (file)
 [% PROCESS global/variables.none.tmpl %]
 [% USE date %]
 
-bug_id,
+[% colsepchar = user.settings.csv_colsepchar.value %]
+
+bug_id
 [% FOREACH column = displaycolumns %]
-  [% column FILTER csv %],
+  [% colsepchar %][% column FILTER csv %]
 [% END %]
 
 [% FOREACH bug = bugs %]
-  [% bug.bug_id %],
+  [% bug.bug_id %]
     [% FOREACH column = displaycolumns %]
+      [% colsepchar %]
       [% IF column == "opendate" OR column == "changeddate" %]
         [% rawcolumn = column.replace("date", "time") %]
         [% bug.$column = date.format(bug.$rawcolumn, "%Y-%m-%d %H:%M:%S") %]
       [% END %]
-      [% bug.$column FILTER csv %],
+      [% bug.$column FILTER csv %]
     [% END %]
 
 [% END %]
index 83620bf08c744c249ed2ad819390f6057030a3d7..87866dfd6eedc5807c4e5e2f49ef7860d4b8bd8b 100644 (file)
   # Contributor(s): Gervase Markham <gerv@gerv.net>
   #%]
 
+[% colsepchar = user.settings.csv_colsepchar.value %]
+
 [% data = chart.data %]
-Date\Series,
+Date\Series
 [% FOREACH label = chart.labels %]
-  [% label FILTER csv %][% "," UNLESS loop.last %]
+  [% colsepchar %][% label FILTER csv %]
 [% END %]
 [%# The data, which is in the correct format for GD, is conceptually the wrong
   # way round for CSV output. So, we need to invert it here, which is why 
@@ -32,7 +34,10 @@ Date\Series,
 [% WHILE i < data.0.size %]
   [% j = 0 %]
   [% WHILE j < data.size %]
-    [% data.$j.$i %][% "," UNLESS (j == data.size - 1) %]
+    [% IF j > 0 %]
+      [% colsepchar %]
+    [% END %]
+    [% data.$j.$i %]
     [% j = j + 1 %]
   [% END %]
   [% i = i + 1 %]
index 42fcd6686aac1bce13bca66c127617b98b6362ff..96dca3d58f2c8b8f25a43c570fafc5110d07fd09 100644 (file)
   #%]
 [% PROCESS global/variables.none.tmpl %]
 
+[% colsepchar = user.settings.csv_colsepchar.value %]
+
 [% num_bugs = BLOCK %]Number of [% terms.bugs %][% END %]
 [% tbl_field_disp = field_descs.$tbl_field || tbl_field %]
 [% col_field_disp = field_descs.$col_field || col_field %]
 [% row_field_disp = field_descs.$row_field || row_field %]
 
-[% title = BLOCK %]
-  [% IF tbl_field %]
-    [% tbl_field_disp FILTER csv %]: [% tbl FILTER csv %]
-
-  [% END %]
-  [% IF row_field %]
-    [% row_field_disp FILTER csv %]
-  [% END %]
-  [% " / " IF col_field AND row_field %]
-  [% col_field_disp FILTER csv %]
+[% IF tbl_field %]
+  [% tbl_field_disp FILTER csv %]: [% tbl FILTER csv %]
 [% END %]
-
-[% title %],
+[% IF row_field %]
+  [% row_field_disp FILTER csv %]
+[% END %]
+[% " / " IF col_field AND row_field %]
+[% col_field_disp FILTER csv %]
 [% IF col_field -%]
-[% FOREACH col = col_names -%]
-  [% IF col_field == 'bug_status' %]
-    [% status_descs.$col FILTER csv -%]
-  [% ELSIF col_field == 'resolution' %]
-    [% resolution_descs.$col FILTER csv -%]
-  [% ELSE %]
-    [% col FILTER csv -%],
-  [% END %]
-[% END -%]
+  [% FOREACH col = col_names -%]
+    [% colsepchar %]
+    [% IF col_field == 'bug_status' %]
+      [% status_descs.$col FILTER csv -%]
+    [% ELSIF col_field == 'resolution' %]
+      [% resolution_descs.$col FILTER csv -%]
+    [% ELSE %]
+      [% col FILTER csv -%]
+    [% END %]
+  [% END -%]
 [% ELSE -%]
-  [% num_bugs %],
+  [% colsepchar %][% num_bugs %]
 [% END %]
 
 [% FOREACH row = row_names %]
-[% IF row_field == 'bug_status' %]
+  [% IF row_field == 'bug_status' %]
     [% status_descs.$row FILTER csv -%]
   [% ELSIF row_field == 'resolution' %]
     [% resolution_descs.$row FILTER csv -%]
   [% ELSE %]
-    [% row FILTER csv -%],
+    [% row FILTER csv -%]
   [% END %]
   [% FOREACH col = col_names %]
+    [% colsepchar %]
     [% IF data.$tbl AND data.$tbl.$col AND data.$tbl.$col.$row %]
-      [% data.$tbl.$col.$row -%],
+      [% data.$tbl.$col.$row -%]
     [% ELSE %]
-      [% -%]0,
+      [% -%]0
     [% END %]
   [% END %]
 
index 07042beac6d040edc1b3c157706a80a7d6cd7f39..5f52a3ca72648e6ea1c317f54032f5fb95e60254 100755 (executable)
@@ -152,18 +152,16 @@ sub SaveSettings {
     foreach my $name (@setting_list) {
         next if ! ($settings->{$name}->{'is_enabled'});
         my $value = $cgi->param($name);
+        my $setting = new Bugzilla::User::Setting($name);
 
-        # de-taint the value.
-        if ($value =~ /^([-\w]+)$/ ) {
-            $value = $1;
-        }
         if ($value eq "${name}-isdefault" ) {
             if (! $settings->{$name}->{'is_default'}) {
-                 $settings->{$name}->reset_to_default;
+                $settings->{$name}->reset_to_default;
             }
         }
         else {
-           $settings->{$name}->set($value);
+            $setting->validate_value($value);
+            $settings->{$name}->set($value);
         }
     }
     $vars->{'settings'} = Bugzilla->user->settings(1);