summaryrefslogtreecommitdiffstats
path: root/extensions/BugmailFilter/lib
diff options
context:
space:
mode:
Diffstat (limited to 'extensions/BugmailFilter/lib')
-rw-r--r--extensions/BugmailFilter/lib/Constants.pm120
-rw-r--r--extensions/BugmailFilter/lib/FakeField.pm50
-rw-r--r--extensions/BugmailFilter/lib/Filter.pm217
3 files changed, 172 insertions, 215 deletions
diff --git a/extensions/BugmailFilter/lib/Constants.pm b/extensions/BugmailFilter/lib/Constants.pm
index a6636dda7..bed8a37d3 100644
--- a/extensions/BugmailFilter/lib/Constants.pm
+++ b/extensions/BugmailFilter/lib/Constants.pm
@@ -14,10 +14,10 @@ use warnings;
use base qw(Exporter);
our @EXPORT = qw(
- FAKE_FIELD_NAMES
- IGNORE_FIELDS
- FIELD_DESCRIPTION_OVERRIDE
- FILTER_RELATIONSHIPS
+ FAKE_FIELD_NAMES
+ IGNORE_FIELDS
+ FIELD_DESCRIPTION_OVERRIDE
+ FILTER_RELATIONSHIPS
);
use Bugzilla::Constants;
@@ -26,98 +26,54 @@ use Bugzilla::Constants;
# header but are not real fields
use constant FAKE_FIELD_NAMES => [
- {
- name => 'comment.created',
- description => 'Comment created',
- },
- {
- name => 'attachment.created',
- description => 'Attachment created',
- },
+ {name => 'comment.created', description => 'Comment created',},
+ {name => 'attachment.created', description => 'Attachment created',},
];
# these fields don't make any sense to filter on
use constant IGNORE_FIELDS => qw(
- assignee_last_login
- attach_data.thedata
- attachments.submitter
- cf_last_resolved
- commenter
- comment_tag
- creation_ts
- days_elapsed
- delta_ts
- everconfirmed
- last_visit_ts
- longdesc
- longdescs.count
- owner_idle_time
- reporter
- reporter_accessible
- setters.login_name
- tag
- votes
+ assignee_last_login
+ attach_data.thedata
+ attachments.submitter
+ cf_last_resolved
+ commenter
+ comment_tag
+ creation_ts
+ days_elapsed
+ delta_ts
+ everconfirmed
+ last_visit_ts
+ longdesc
+ longdescs.count
+ owner_idle_time
+ reporter
+ reporter_accessible
+ setters.login_name
+ tag
+ votes
);
# override the description of some fields
-use constant FIELD_DESCRIPTION_OVERRIDE => {
- bug_id => 'Bug Created',
-};
+use constant FIELD_DESCRIPTION_OVERRIDE => {bug_id => 'Bug Created',};
# relationship / int mappings
# _should_drop() also needs updating when this const is changed
use constant FILTER_RELATIONSHIPS => [
- {
- name => 'Assignee',
- value => 1,
- },
- {
- name => 'Not Assignee',
- value => 2,
- },
- {
- name => 'Reporter',
- value => 3,
- },
- {
- name => 'Not Reporter',
- value => 4,
- },
- {
- name => 'QA Contact',
- value => 5,
- },
- {
- name => 'Not QA Contact',
- value => 6,
- },
- {
- name => "CC'ed",
- value => 7,
- },
- {
- name => "Not CC'ed",
- value => 8,
- },
- {
- name => 'Watching',
- value => 9,
- },
- {
- name => 'Not Watching',
- value => 10,
- },
- {
- name => 'Mentoring',
- value => 11,
- },
- {
- name => 'Not Mentoring',
- value => 12,
- },
+ {name => 'Assignee', value => 1,},
+ {name => 'Not Assignee', value => 2,},
+ {name => 'Reporter', value => 3,},
+ {name => 'Not Reporter', value => 4,},
+ {name => 'QA Contact', value => 5,},
+ {name => 'Not QA Contact', value => 6,},
+ {name => "CC'ed", value => 7,},
+ {name => "Not CC'ed", value => 8,},
+ {name => 'Watching', value => 9,},
+ {name => 'Not Watching', value => 10,},
+ {name => 'Mentoring', value => 11,},
+ {name => 'Not Mentoring', value => 12,},
];
1;
diff --git a/extensions/BugmailFilter/lib/FakeField.pm b/extensions/BugmailFilter/lib/FakeField.pm
index e9f8b1808..cf82aec85 100644
--- a/extensions/BugmailFilter/lib/FakeField.pm
+++ b/extensions/BugmailFilter/lib/FakeField.pm
@@ -16,8 +16,8 @@ use Bugzilla::Extension::BugmailFilter::Constants;
# object
sub new {
- my ($class, $params) = @_;
- return bless($params, $class);
+ my ($class, $params) = @_;
+ return bless($params, $class);
}
sub name { $_[0]->{name} }
@@ -26,33 +26,35 @@ sub description { $_[0]->{description} }
# static methods
sub fake_fields {
- my $cache = Bugzilla->request_cache->{bugmail_filter};
- if (!$cache->{fake_fields}) {
- my @fields;
- foreach my $rh (@{ FAKE_FIELD_NAMES() }) {
- push @fields, Bugzilla::Extension::BugmailFilter::FakeField->new($rh);
- }
- $cache->{fake_fields} = \@fields;
+ my $cache = Bugzilla->request_cache->{bugmail_filter};
+ if (!$cache->{fake_fields}) {
+ my @fields;
+ foreach my $rh (@{FAKE_FIELD_NAMES()}) {
+ push @fields, Bugzilla::Extension::BugmailFilter::FakeField->new($rh);
}
- return $cache->{fake_fields};
+ $cache->{fake_fields} = \@fields;
+ }
+ return $cache->{fake_fields};
}
sub tracking_flag_fields {
- my $cache = Bugzilla->request_cache->{bugmail_filter};
- if (!$cache->{tracking_flag_fields}) {
- require Bugzilla::Extension::TrackingFlags::Constants;
- my @fields;
- my $tracking_types = Bugzilla::Extension::TrackingFlags::Constants::FLAG_TYPES();
- foreach my $tracking_type (@$tracking_types) {
- push @fields, Bugzilla::Extension::BugmailFilter::FakeField->new({
- name => 'tracking.' . $tracking_type->{name},
- description => $tracking_type->{description},
- sortkey => $tracking_type->{sortkey},
- });
- }
- $cache->{tracking_flag_fields} = \@fields;
+ my $cache = Bugzilla->request_cache->{bugmail_filter};
+ if (!$cache->{tracking_flag_fields}) {
+ require Bugzilla::Extension::TrackingFlags::Constants;
+ my @fields;
+ my $tracking_types
+ = Bugzilla::Extension::TrackingFlags::Constants::FLAG_TYPES();
+ foreach my $tracking_type (@$tracking_types) {
+ push @fields,
+ Bugzilla::Extension::BugmailFilter::FakeField->new({
+ name => 'tracking.' . $tracking_type->{name},
+ description => $tracking_type->{description},
+ sortkey => $tracking_type->{sortkey},
+ });
}
- return $cache->{tracking_flag_fields};
+ $cache->{tracking_flag_fields} = \@fields;
+ }
+ return $cache->{tracking_flag_fields};
}
1;
diff --git a/extensions/BugmailFilter/lib/Filter.pm b/extensions/BugmailFilter/lib/Filter.pm
index 7f2f4cb87..fa2c708cd 100644
--- a/extensions/BugmailFilter/lib/Filter.pm
+++ b/extensions/BugmailFilter/lib/Filter.pm
@@ -25,14 +25,14 @@ use Bugzilla::Util qw(trim);
use constant DB_TABLE => 'bugmail_filters';
use constant DB_COLUMNS => qw(
- id
- user_id
- product_id
- component_id
- field_name
- relationship
- changer_id
- action
+ id
+ user_id
+ product_id
+ component_id
+ field_name
+ relationship
+ changer_id
+ action
);
use constant LIST_ORDER => 'id';
@@ -40,13 +40,11 @@ use constant LIST_ORDER => 'id';
use constant UPDATE_COLUMNS => ();
use constant VALIDATORS => {
- user_id => \&_check_user,
- field_name => \&_check_field_name,
- action => \&Bugzilla::Object::check_boolean,
-};
-use constant VALIDATOR_DEPENDENCIES => {
- component_id => [ 'product_id' ],
+ user_id => \&_check_user,
+ field_name => \&_check_field_name,
+ action => \&Bugzilla::Object::check_boolean,
};
+use constant VALIDATOR_DEPENDENCIES => {component_id => ['product_id'],};
use constant AUDIT_CREATES => 0;
use constant AUDIT_UPDATES => 0;
@@ -56,163 +54,164 @@ use constant USE_MEMCACHED => 0;
# getters
sub user {
- my ($self) = @_;
- return Bugzilla::User->new({ id => $self->{user_id}, cache => 1 });
+ my ($self) = @_;
+ return Bugzilla::User->new({id => $self->{user_id}, cache => 1});
}
sub product {
- my ($self) = @_;
- return $self->{product_id}
- ? Bugzilla::Product->new({ id => $self->{product_id}, cache => 1 })
- : undef;
+ my ($self) = @_;
+ return $self->{product_id}
+ ? Bugzilla::Product->new({id => $self->{product_id}, cache => 1})
+ : undef;
}
sub product_name {
- my ($self) = @_;
- return $self->{product_name} //= $self->{product_id} ? $self->product->name : '';
+ my ($self) = @_;
+ return $self->{product_name}
+ //= $self->{product_id} ? $self->product->name : '';
}
sub component {
- my ($self) = @_;
- return $self->{component_id}
- ? Bugzilla::Component->new({ id => $self->{component_id}, cache => 1 })
- : undef;
+ my ($self) = @_;
+ return $self->{component_id}
+ ? Bugzilla::Component->new({id => $self->{component_id}, cache => 1})
+ : undef;
}
sub component_name {
- my ($self) = @_;
- return $self->{component_name} //= $self->{component_id} ? $self->component->name : '';
+ my ($self) = @_;
+ return $self->{component_name}
+ //= $self->{component_id} ? $self->component->name : '';
}
sub field_name {
- return $_[0]->{field_name} //= '';
+ return $_[0]->{field_name} //= '';
}
sub field_description {
- my ($self, $value) = @_;
- $self->{field_description} = $value if defined($value);
- return $self->{field_description};
+ my ($self, $value) = @_;
+ $self->{field_description} = $value if defined($value);
+ return $self->{field_description};
}
sub field {
- my ($self) = @_;
- return unless $self->{field_name};
- if (!$self->{field}) {
- if (substr($self->{field_name}, 0, 1) eq '~') {
- # this should never happen
- die "not implemented";
- }
- foreach my $field (
- @{ Bugzilla::Extension::BugmailFilter::FakeField->fake_fields() },
- @{ Bugzilla::Extension::BugmailFilter::FakeField->tracking_flag_fields() },
- ) {
- if ($field->{name} eq $self->{field_name}) {
- return $self->{field} = $field;
- }
- }
- $self->{field} = Bugzilla::Field->new({ name => $self->{field_name}, cache => 1 });
+ my ($self) = @_;
+ return unless $self->{field_name};
+ if (!$self->{field}) {
+ if (substr($self->{field_name}, 0, 1) eq '~') {
+
+ # this should never happen
+ die "not implemented";
}
- return $self->{field};
+ foreach my $field (
+ @{Bugzilla::Extension::BugmailFilter::FakeField->fake_fields()},
+ @{Bugzilla::Extension::BugmailFilter::FakeField->tracking_flag_fields()},
+ )
+ {
+ if ($field->{name} eq $self->{field_name}) {
+ return $self->{field} = $field;
+ }
+ }
+ $self->{field}
+ = Bugzilla::Field->new({name => $self->{field_name}, cache => 1});
+ }
+ return $self->{field};
}
sub relationship {
- return $_[0]->{relationship};
+ return $_[0]->{relationship};
}
sub changer_id {
- return $_[0]->{changer_id};
+ return $_[0]->{changer_id};
}
sub changer {
- my ($self) = @_;
- return $self->{changer_id}
- ? Bugzilla::User->new({ id => $self->{changer_id}, cache => 1 })
- : undef;
+ my ($self) = @_;
+ return $self->{changer_id}
+ ? Bugzilla::User->new({id => $self->{changer_id}, cache => 1})
+ : undef;
}
sub relationship_name {
- my ($self) = @_;
- foreach my $rel (@{ FILTER_RELATIONSHIPS() }) {
- return $rel->{name}
- if $rel->{value} == $self->{relationship};
- }
- return '?';
+ my ($self) = @_;
+ foreach my $rel (@{FILTER_RELATIONSHIPS()}) {
+ return $rel->{name} if $rel->{value} == $self->{relationship};
+ }
+ return '?';
}
sub is_exclude {
- return $_[0]->{action} == 1;
+ return $_[0]->{action} == 1;
}
sub is_include {
- return $_[0]->{action} == 0;
+ return $_[0]->{action} == 0;
}
# validators
sub _check_user {
- my ($class, $user) = @_;
- $user || ThrowCodeError('param_required', { param => 'user' });
+ my ($class, $user) = @_;
+ $user || ThrowCodeError('param_required', {param => 'user'});
}
sub _check_field_name {
- my ($class, $field_name) = @_;
- return undef unless $field_name;
- if (substr($field_name, 0, 1) eq '~') {
- $field_name = lc(trim($field_name));
- $field_name =~ /^~[a-z0-9_\.\-]+$/
- || ThrowUserError('bugmail_filter_invalid');
- length($field_name) <= 64
- || ThrowUserError('bugmail_filter_too_long');
- return $field_name;
- }
- foreach my $rh (@{ FAKE_FIELD_NAMES() }) {
- return $field_name if $rh->{name} eq $field_name;
- }
- return $field_name
- if $field_name =~ /^tracking\./;
- Bugzilla::Field->check({ name => $field_name, cache => 1});
+ my ($class, $field_name) = @_;
+ return undef unless $field_name;
+ if (substr($field_name, 0, 1) eq '~') {
+ $field_name = lc(trim($field_name));
+ $field_name =~ /^~[a-z0-9_\.\-]+$/ || ThrowUserError('bugmail_filter_invalid');
+ length($field_name) <= 64 || ThrowUserError('bugmail_filter_too_long');
return $field_name;
+ }
+ foreach my $rh (@{FAKE_FIELD_NAMES()}) {
+ return $field_name if $rh->{name} eq $field_name;
+ }
+ return $field_name if $field_name =~ /^tracking\./;
+ Bugzilla::Field->check({name => $field_name, cache => 1});
+ return $field_name;
}
# methods
sub matches {
- my ($self, $args) = @_;
-
- if (my $field_name = $self->{field_name}) {
- if ($args->{field}->{field_name} && substr($field_name, 0, 1) eq '~') {
- my $substring = quotemeta(substr($field_name, 1));
- if ($args->{field}->{filter_field} !~ /$substring/i) {
- return 0;
- }
- }
- elsif ($field_name eq 'flagtypes.name') {
- if ($args->{field}->{field_name} ne $field_name) {
- return 0;
- }
- }
- elsif ($field_name ne $args->{field}->{filter_field}) {
- return 0;
- }
- }
+ my ($self, $args) = @_;
- if ($self->{product_id} && $self->{product_id} != $args->{product_id}) {
+ if (my $field_name = $self->{field_name}) {
+ if ($args->{field}->{field_name} && substr($field_name, 0, 1) eq '~') {
+ my $substring = quotemeta(substr($field_name, 1));
+ if ($args->{field}->{filter_field} !~ /$substring/i) {
return 0;
+ }
}
-
- if ($self->{component_id} && $self->{component_id} != $args->{component_id}) {
+ elsif ($field_name eq 'flagtypes.name') {
+ if ($args->{field}->{field_name} ne $field_name) {
return 0;
+ }
}
-
- if ($self->{relationship} && !$args->{rel_map}->[$self->{relationship}]) {
- return 0;
+ elsif ($field_name ne $args->{field}->{filter_field}) {
+ return 0;
}
+ }
- if ($self->{changer_id} && $self->{changer_id} != $args->{changer_id}) {
- return 0;
- }
+ if ($self->{product_id} && $self->{product_id} != $args->{product_id}) {
+ return 0;
+ }
+
+ if ($self->{component_id} && $self->{component_id} != $args->{component_id}) {
+ return 0;
+ }
+
+ if ($self->{relationship} && !$args->{rel_map}->[$self->{relationship}]) {
+ return 0;
+ }
+
+ if ($self->{changer_id} && $self->{changer_id} != $args->{changer_id}) {
+ return 0;
+ }
- return 1;
+ return 1;
}
1;