Skip to content

Commit 5db6eeb

Browse files
committed
Bug 579089: Change default Hardware / OS values to be "Unspecified/Unspecified"
1 parent 4aa44c4 commit 5db6eeb

File tree

14 files changed

+283
-57
lines changed

14 files changed

+283
-57
lines changed

Bugzilla/Bug.pm

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -702,10 +702,15 @@ sub create {
702702
unless defined $params->{bug_severity};
703703
$params->{priority} = Bugzilla->params->{defaultpriority}
704704
unless defined $params->{priority};
705-
$params->{op_sys} = Bugzilla->params->{defaultopsys}
706-
unless defined $params->{op_sys};
707-
$params->{rep_platform} = Bugzilla->params->{defaultplatform}
708-
unless defined $params->{rep_platform};
705+
706+
# BMO - per-product hw/os defaults
707+
if (!defined $params->{rep_platform} || !defined $params->{op_sys}) {
708+
if (my $product = Bugzilla::Product->new({ name => $params->{product}, cache => 1 })) {
709+
$params->{rep_platform} //= $product->default_product;
710+
$params->{op_sys} //= $product->default_op_sys;
711+
}
712+
}
713+
709714
# Make sure a comment is always defined.
710715
$params->{comment} = '' unless defined $params->{comment};
711716

Bugzilla/UserAgent.pm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ use constant OS_MAP => (
183183
);
184184

185185
sub detect_platform {
186-
my $userAgent = $ENV{'HTTP_USER_AGENT'} || '';
186+
my $userAgent = shift || Bugzilla->cgi->user_agent || '';
187187
my @detected;
188188
my $iterator = natatime(2, PLATFORMS_MAP);
189189
while (my($re, $ra) = $iterator->()) {
@@ -195,7 +195,7 @@ sub detect_platform {
195195
}
196196

197197
sub detect_op_sys {
198-
my $userAgent = $ENV{'HTTP_USER_AGENT'} || '';
198+
my $userAgent = shift || Bugzilla->cgi->user_agent || '';
199199
my @detected;
200200
my $iterator = natatime(2, OS_MAP);
201201
while (my($re, $ra) = $iterator->()) {

Bugzilla/WebService/Product.pm

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,9 @@ sub _product_to_hash {
202202
$self->_milestone_to_hash($_, $params)
203203
} @{$product->milestones}];
204204
}
205+
# BMO - add default hw/os
206+
$field_data->{default_platform} = $self->type('string', $product->default_platform);
207+
$field_data->{default_op_sys} = $self->type('string', $product->default_op_sys);
205208
return filter($params, $field_data);
206209
}
207210

enter_bug.cgi

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -313,10 +313,12 @@ else {
313313
$default{'component_'} = formvalue('component');
314314
$default{'priority'} = formvalue('priority', Bugzilla->params->{'defaultpriority'});
315315
$default{'bug_severity'} = formvalue('bug_severity', Bugzilla->params->{'defaultseverity'});
316-
$default{'rep_platform'} = formvalue('rep_platform',
317-
Bugzilla->params->{'defaultplatform'} || detect_platform());
318-
$default{'op_sys'} = formvalue('op_sys',
319-
Bugzilla->params->{'defaultopsys'} || detect_op_sys());
316+
317+
# BMO - use per-product default hw/os
318+
$default{'rep_platform'} = formvalue('rep_platform', $product->default_platform // detect_platform());
319+
$default{'op_sys'} = formvalue('op_sys', $product->default_op_sys // detect_op_sys());
320+
$vars->{'rep_platform'} = detect_platform();
321+
$vars->{'rep_op_sys'} = detect_op_sys();
320322

321323
$vars->{'alias'} = formvalue('alias');
322324
$vars->{'short_desc'} = formvalue('short_desc');

extensions/BMO/Extension.pm

Lines changed: 112 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,13 @@ use Bugzilla::Error;
3131
use Bugzilla::Field;
3232
use Bugzilla::Field::Choice;
3333
use Bugzilla::Group;
34+
use Bugzilla::Install::Filesystem;
3435
use Bugzilla::Mailer;
3536
use Bugzilla::Product;
3637
use Bugzilla::Status;
3738
use Bugzilla::Token;
38-
use Bugzilla::Install::Filesystem;
3939
use Bugzilla::User;
40+
use Bugzilla::UserAgent qw(detect_platform detect_op_sys);
4041
use Bugzilla::User::Setting;
4142
use Bugzilla::Util;
4243

@@ -62,12 +63,17 @@ our $VERSION = '0.1';
6263
#
6364

6465
BEGIN {
65-
*Bugzilla::Bug::last_closed_date = \&_last_closed_date;
66-
*Bugzilla::Product::default_security_group = \&_default_security_group;
67-
*Bugzilla::Product::default_security_group_obj = \&_default_security_group_obj;
68-
*Bugzilla::Product::group_always_settable = \&_group_always_settable;
66+
*Bugzilla::Bug::last_closed_date = \&_last_closed_date;
67+
*Bugzilla::Bug::reporters_hw_os = \&_bug_reporters_hw_os;
68+
*Bugzilla::Product::default_security_group = \&_default_security_group;
69+
*Bugzilla::Product::default_security_group_obj = \&_default_security_group_obj;
70+
*Bugzilla::Product::group_always_settable = \&_group_always_settable;
71+
*Bugzilla::Product::default_platform_id = \&_product_default_platform_id;
72+
*Bugzilla::Product::default_op_sys_id = \&_product_default_op_sys_id;
73+
*Bugzilla::Product::default_platform = \&_product_default_platform;
74+
*Bugzilla::Product::default_op_sys = \&_product_default_op_sys;
6975
*Bugzilla::check_default_product_security_group = \&_check_default_product_security_group;
70-
*Bugzilla::Attachment::is_bounty_attachment = \&_is_bounty_attachment;
76+
*Bugzilla::Attachment::is_bounty_attachment = \&_is_bounty_attachment;
7177
}
7278

7379
sub template_before_process {
@@ -641,6 +647,43 @@ sub quicksearch_map {
641647
}
642648
}
643649

650+
sub object_columns {
651+
my ($self, $args) = @_;
652+
return unless $args->{class}->isa('Bugzilla::Product');
653+
push @{ $args->{columns} }, qw( default_platform_id default_op_sys_id );
654+
}
655+
656+
sub object_update_columns {
657+
my ($self, $args) = @_;
658+
return unless $args->{object}->isa('Bugzilla::Product');
659+
push @{ $args->{columns} }, qw( default_platform_id default_op_sys_id );
660+
}
661+
662+
sub object_before_create {
663+
my ($self, $args) = @_;
664+
return unless $args->{class}->isa('Bugzilla::Product');
665+
666+
my $cgi = Bugzilla->cgi;
667+
my $params = $args->{params};
668+
foreach my $field (qw( default_platform_id default_op_sys_id )) {
669+
$params->{$field} = $cgi->param($field);
670+
}
671+
}
672+
673+
sub object_end_of_set_all {
674+
my ($self, $args) = @_;
675+
my $object = $args->{object};
676+
return unless $object->isa('Bugzilla::Product');
677+
678+
my $cgi = Bugzilla->cgi;
679+
my $params = $args->{params};
680+
foreach my $field (qw( default_platform_id default_op_sys_id )) {
681+
my $value = $cgi->param($field);
682+
detaint_natural($value);
683+
$object->set($field, $value);
684+
}
685+
}
686+
644687
sub object_end_of_create {
645688
my ($self, $args) = @_;
646689
my $class = $args->{class};
@@ -675,6 +718,52 @@ sub object_end_of_create {
675718
}
676719
}
677720

721+
sub _bug_reporters_hw_os {
722+
my ($self) = @_;
723+
return $self->{ua_hw_os} if exists $self->{ua_hw_os};
724+
my $memcached = Bugzilla->memcached;
725+
my $hw_os = $memcached->get({ key => 'bug.ua.' . $self->id });
726+
if (!$hw_os) {
727+
(my $ua) = Bugzilla->dbh->selectrow_array(
728+
"SELECT user_agent FROM bug_user_agent WHERE bug_id = ?",
729+
undef,
730+
$self->id);
731+
$hw_os = $ua
732+
? [ detect_platform($ua), detect_op_sys($ua) ]
733+
: [];
734+
$memcached->set({ key => 'bug.ua.' . $self->id, value => $hw_os });
735+
}
736+
return $self->{ua_hw_os} = $hw_os;
737+
}
738+
739+
sub _product_default_platform_id { $_[0]->{default_platform_id} }
740+
sub _product_default_op_sys_id { $_[0]->{default_op_sys_id} }
741+
742+
sub _product_default_platform {
743+
my ($self) = @_;
744+
if (!exists $self->{default_platform}) {
745+
$self->{default_platform} = $self->default_platform_id
746+
? Bugzilla::Field::Choice
747+
->type('rep_platform')
748+
->new($_[0]->{default_platform_id})
749+
->name
750+
: undef;
751+
}
752+
return $self->{default_platform};
753+
}
754+
sub _product_default_op_sys {
755+
my ($self) = @_;
756+
if (!exists $self->{default_op_sys}) {
757+
$self->{default_op_sys} = $self->default_op_sys_id
758+
? Bugzilla::Field::Choice
759+
->type('op_sys')
760+
->new($_[0]->{default_op_sys_id})
761+
->name
762+
: undef;
763+
}
764+
return $self->{default_op_sys};
765+
}
766+
678767
sub _get_named_query {
679768
my ($sharer_id, $group_id, $definition) = @_;
680769
my $dbh = Bugzilla->dbh;
@@ -701,11 +790,11 @@ sub _get_named_query {
701790
return $namedquery_id;
702791
}
703792

704-
# Automatically CC users to bugs based on group & product
705793
sub bug_end_of_create {
706794
my ($self, $args) = @_;
707795
my $bug = $args->{'bug'};
708796

797+
# automatically CC users to bugs based on group & product
709798
foreach my $group_name (keys %group_auto_cc) {
710799
my $group_obj = Bugzilla::Group->new({ name => $group_name });
711800
if ($group_obj && $bug->in_group($group_obj)) {
@@ -717,6 +806,21 @@ sub bug_end_of_create {
717806
}
718807
}
719808
}
809+
810+
# store user-agent
811+
if (my $ua = Bugzilla->cgi->user_agent) {
812+
trick_taint($ua);
813+
Bugzilla->dbh->do(
814+
"INSERT INTO bug_user_agent (bug_id, user_agent) VALUES (?, ?)",
815+
undef,
816+
$bug->id, $ua
817+
);
818+
}
819+
}
820+
821+
sub db_sanitize {
822+
print "deleting reporter's user-agents...\n";
823+
Bugzilla->dbh->do("TRUNCATE TABLE bug_user_agent");
720824
}
721825

722826
# bugs in an ASSIGNED state must be assigned to a real person
@@ -872,7 +976,7 @@ sub db_schema_abstract_schema {
872976
REFERENCES => {
873977
TABLE => 'bugs',
874978
COLUMN => 'bug_id',
875-
DELETE => 'cascade',
979+
DELETE => 'CASCADE',
876980
},
877981
},
878982
user_agent => {

extensions/BMO/template/en/default/hook/admin/params/editparams-current_panel.html.tmpl

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,14 @@
66
# defined by the Mozilla Public License, v. 2.0.
77
#%]
88

9-
[% IF panel.name == "groupsecurity" %]
10-
[% panel.param_descs.delete_comments_group =
11-
'The name of the group of users who can delete comments by using the "deleted" comment tag.'
12-
%]
13-
[% END -%]
9+
[%
10+
IF panel.name == "groupsecurity";
11+
panel.param_descs.delete_comments_group =
12+
'The name of the group of users who can delete comments by using the "deleted" comment tag.';
13+
14+
ELSIF panel.name == "bugfields";
15+
panel.param_descs.defaultplatform = "This parameter is ignored on BMO, use per-product defaults instead.";
16+
panel.param_descs.defaultopsys = "This parameter is ignored on BMO, use per-product defaults instead.";
17+
18+
END;
19+
%]
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
[%# This Source Code Form is subject to the terms of the Mozilla Public
2+
# License, v. 2.0. If a copy of the MPL was not distributed with this
3+
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
4+
#
5+
# This Source Code Form is "Incompatible With Secondary Licenses", as
6+
# defined by the Mozilla Public License, v. 2.0.
7+
#%]
8+
9+
<tr>
10+
<th align="right">Default Platform</th>
11+
<td>
12+
[% INCLUDE default_select
13+
field_name = 'default_platform_id'
14+
field_value = product.default_platform_id
15+
field_values = bug_fields.rep_platform.legal_values
16+
%]
17+
[%= INCLUDE default_select
18+
field_name = 'default_op_sys_id'
19+
field_value = product.default_op_sys_id
20+
field_values = bug_fields.op_sys.legal_values
21+
%]
22+
</td>
23+
</tr>
24+
25+
[% BLOCK default_select %]
26+
<select name="[% field_name FILTER html %]">
27+
<option value="" [% " selected" IF field_value == "" %]>Detect</option>
28+
[% FOREACH v IN field_values %]
29+
[% NEXT UNLESS v.is_active %]
30+
<option value="[% v.id FILTER html %]" [% " selected" IF field_value == v.id %]>
31+
[% v.value FILTER html %]
32+
</option>
33+
[% END %]
34+
</select>
35+
[% END %]
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
[%# This Source Code Form is subject to the terms of the Mozilla Public
2+
# License, v. 2.0. If a copy of the MPL was not distributed with this
3+
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
4+
#
5+
# This Source Code Form is "Incompatible With Secondary Licenses", as
6+
# defined by the Mozilla Public License, v. 2.0.
7+
#%]
8+
9+
[% IF changes.default_platform_id.defined %]
10+
<p>Default Platform updated</p>
11+
[% END %]
12+
[% IF changes.default_op_sys_id.defined %]
13+
<p>Default Op-Sys updated</p>
14+
[% END %]
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
[%# This Source Code Form is subject to the terms of the Mozilla Public
2+
# License, v. 2.0. If a copy of the MPL was not distributed with this
3+
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
4+
#
5+
# This Source Code Form is "Incompatible With Secondary Licenses", as
6+
# defined by the Mozilla Public License, v. 2.0.
7+
#%]
8+
9+
[%# because the "from reporter" button adds likely unnecessary noise to a bug,
10+
# we only show it on unconfirmed or untriaged bugs %]
11+
[%
12+
RETURN UNLESS
13+
(bug.status.value == "UNCONFIRMED" || bug.component == "Untriaged")
14+
&& bug.check_can_change_field('op_sys', 0, 1);
15+
hw_os = bug.reporters_hw_os;
16+
RETURN UNLESS hw_os.size;
17+
RETURN IF bug.rep_platform == hw_os.0 && bug.op_sys == hw_os.1;
18+
19+
title = "Set platform to reporter's: " _ hw_os.0 _ " / " _ hw_os.1;
20+
%]
21+
22+
[% onclick = BLOCK %]
23+
$('#rep_platform').val('[% hw_os.0 FILTER js FILTER html %]');
24+
$('#op_sys').val('[% hw_os.1 FILTER js FILTER html %]');
25+
$('#rep_hw_os').hide();
26+
[% END %]
27+
[%
28+
IF bug_modal;
29+
INCLUDE modal;
30+
ELSE;
31+
INCLUDE classic;
32+
END;
33+
%]
34+
35+
[% BLOCK classic %]
36+
<span id="rep_hw_os">
37+
(<a href="javascript:void(0)" title="[% title FILTER html %]" onclick="[% onclick FILTER none %]">from reporter</a>)
38+
</span>
39+
[% END %]
40+
41+
[% BLOCK modal %]
42+
<button id="rep_hw_os" type="button" class="minor" title="[% title FILTER html %]" onclick="[% onclick FILTER none %]">
43+
From&nbsp;Reporter
44+
</button>
45+
[% END %]

extensions/BugModal/template/en/default/bug_modal/edit.html.tmpl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
[%
1010
USE Bugzilla;
1111

12+
bug_modal = 1;
13+
1214
# only edit one bug
1315
UNLESS bug.defined;
1416
bug = bugs.0;
@@ -620,6 +622,12 @@
620622
field_type = constants.FIELD_TYPE_SINGLE_SELECT
621623
inline = 1
622624
%]
625+
[% WRAPPER bug_modal/field.html.tmpl
626+
container = 1
627+
inline = 1
628+
%]
629+
[% Hook.process("after_op_sys", 'bug/edit.html.tmpl') %]
630+
[% END %]
623631
[% END %]
624632

625633
[%# keywords %]

0 commit comments

Comments
 (0)