[Rt-commit] rt branch, 4.4/add-groups-users-cf-filter, created. rt-4.4.3-26-g5e61b8fbe
Maureen Mirville
maureen at bestpractical.com
Fri Jul 27 16:43:14 EDT 2018
The branch, 4.4/add-groups-users-cf-filter has been created
at 5e61b8fbe838aa8e5dcced638478a034c8afe407 (commit)
- Log -----------------------------------------------------------------
commit 97a1108d505fceeaa2731fa7713f736d6e3b5cf1
Author: Maureen E. Mirville <maureen at bestpractical.com>
Date: Wed Jul 25 09:49:42 2018 -0400
Add more filtering to Groups search on Admin>Groups>select
diff --git a/share/html/Admin/Groups/index.html b/share/html/Admin/Groups/index.html
index 416bd5dd8..0a2f2a919 100644
--- a/share/html/Admin/Groups/index.html
+++ b/share/html/Admin/Groups/index.html
@@ -64,11 +64,13 @@ jQuery(function(){
</script>
</form>
-<form method="post" action="<% RT->Config->Get('WebPath') %>/Admin/Groups/index.html">
+<form method="post" action="<% RT->Config->Get('WebPath') %>/Admin/Groups/index.html" name="Admin_Groups">
<&|/l&>Find groups whose</&> <& /Elements/SelectGroups &><br />
+<&|/l&>And groups whose</&> <& /Elements/SelectGroups2 &><br />
+<&|/l&>And groups whose</&> <& /Elements/SelectGroups3 &><br />
<input type="checkbox" class="checkbox" id="FindDisabledGroups" name="FindDisabledGroups" value="1" <% $FindDisabledGroups? 'checked="checked"': '' |n %> />
<label for="FindDisabledGroups"><&|/l&>Include disabled groups in listing.</&></label><br />
-<div align="right"><input type="submit" class="button" value="<&|/l&>Go!</&>" /></div>
+<div align="right"><input type="submit" class="button" name="Go" value="<&|/l&>Go!</&>" /></div>
</form>
% unless ( $Groups->Count ) {
@@ -84,7 +86,7 @@ jQuery(function(){
Format => $Format,
Collection => $Groups,
AllowSorting => 1,
- PassArguments => [qw(Format Rows Page Order OrderBy GroupString GroupOp GroupField FindDisabledGroups)],
+ PassArguments => [qw(Format Rows Page Order OrderBy GroupString GroupOp GroupField GroupString2 GroupOp2 GroupField2 GroupString3 GroupOp3 GroupField3 FindDisabledGroups)],
&>
% }
@@ -100,20 +102,32 @@ if ($FindDisabledGroups) {
if (length $GroupString) {
$caption = loc("Groups matching search criteria");
- if ($GroupField =~ /^CustomField-(\d+)/) {
- $Groups->LimitCustomField(
- CUSTOMFIELD => $1,
- OPERATOR => $GroupOp,
- VALUE => $GroupString,
- );
- }
- else {
- $Groups->Limit(
- FIELD => $GroupField,
- OPERATOR => $GroupOp,
- VALUE => $GroupString,
- CASESENSITIVE => 0
- );
+ my %group1 = ( field => $GroupField, op => $GroupOp, string => $GroupString );
+ my %group2 = ( field => $GroupField2, op => $GroupOp2, string => $GroupString2 );
+ my %group3 = ( field => $GroupField3, op => $GroupOp3, string => $GroupString3 );
+ my @groups = ( \%group1 );
+
+ push ( @groups, \%group2 ) if length $GroupString2;
+ push ( @groups, \%group3 ) if length $GroupString3;
+
+ foreach my $group ( @groups ) {
+ if ( $group->{'field'} =~ /^CustomField-(\d+)/ ) {
+ $Groups->LimitCustomField(
+ CUSTOMFIELD => $1,
+ OPERATOR => $group->{'op'},
+ VALUE => $group->{'string'},
+ ENTRYAGGREGATOR => 'AND',
+ );
+ }
+ else {
+ $Groups->Limit(
+ FIELD => $group->{'field'},
+ OPERATOR => $group->{'op'},
+ VALUE => $group->{'string'},
+ CASESENSITIVE => 0,
+ ENTRYAGGREGATOR => 'AND',
+ );
+ }
}
RT::Interface::Web::Redirect(RT->Config->Get('WebURL')."Admin/Groups/Modify.html?id=".$Groups->First->id)
if $Groups->Count == 1 and $Groups->First;
@@ -132,5 +146,11 @@ $Format => undef,
$GroupString => '' unless defined $GroupString
$GroupOp => '='
$GroupField => 'Name'
+$GroupString2 => '' unless defined $GroupString2
+$GroupOp2 => '='
+$GroupField2 => 'Name'
+$GroupString3 => '' unless defined $GroupString3
+$GroupOp3 => '='
+$GroupField3 => 'Name'
$FindDisabledGroups => 0
</%ARGS>
diff --git a/share/html/Elements/SelectGroups2 b/share/html/Elements/SelectGroups2
new file mode 100644
index 000000000..057735b70
--- /dev/null
+++ b/share/html/Elements/SelectGroups2
@@ -0,0 +1,68 @@
+%# BEGIN BPS TAGGED BLOCK {{{
+%#
+%# COPYRIGHT:
+%#
+%# This software is Copyright (c) 1996-2018 Best Practical Solutions, LLC
+%# <sales at bestpractical.com>
+%#
+%# (Except where explicitly superseded by other copyright notices)
+%#
+%#
+%# LICENSE:
+%#
+%# This work is made available to you under the terms of Version 2 of
+%# the GNU General Public License. A copy of that license should have
+%# been provided with this software, but in any event can be snarfed
+%# from www.gnu.org.
+%#
+%# This work is distributed in the hope that it will be useful, but
+%# WITHOUT ANY WARRANTY; without even the implied warranty of
+%# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+%# General Public License for more details.
+%#
+%# You should have received a copy of the GNU General Public License
+%# along with this program; if not, write to the Free Software
+%# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+%# 02110-1301 or visit their web page on the internet at
+%# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html.
+%#
+%#
+%# CONTRIBUTION SUBMISSION POLICY:
+%#
+%# (The following paragraph is not intended to limit the rights granted
+%# to you to modify and distribute this software under the terms of
+%# the GNU General Public License and is only of importance to you if
+%# you choose to contribute your changes and enhancements to the
+%# community by submitting them to Best Practical Solutions, LLC.)
+%#
+%# By intentionally submitting any modifications, corrections or
+%# derivatives to this work, or any other work intended for use with
+%# Request Tracker, to Best Practical Solutions, LLC, you confirm that
+%# you are the copyright holder for those contributions and you grant
+%# Best Practical Solutions, LLC a nonexclusive, worldwide, irrevocable,
+%# royalty-free, perpetual, license to use, copy, create derivative
+%# works based on those contributions, and sublicense and distribute
+%# those contributions and any derivatives thereof.
+%#
+%# END BPS TAGGED BLOCK }}}
+<select name="GroupField2">
+% foreach my $col (RT::Group->BasicColumns) {
+<option <% ($GroupField2 eq $col->[0]) ? 'selected="selected"' : '' %> value="<% $col->[0] %>"><% loc($col->[1]) %></option>
+% }
+% while (my $CF = $CFs->Next) {
+% my $val = "CustomField-" . $CF->Id;
+<option <% ($GroupField2 eq $val) ? 'selected="selected"' : '' %> value="<% $val %>"><&|/l&>CustomField</&>: <% $CF->Name %></option>
+% }
+</select>
+<& /Elements/SelectMatch, Name => 'GroupOp2', Default => $GroupOp2 &>
+<input size="8" name="GroupString2" value="<% $GroupString2 %>" />
+<%INIT>
+my $CFs = RT::CustomFields->new($session{'CurrentUser'});
+$CFs->LimitToChildType('RT::Group');
+$CFs->OrderBy( FIELD => 'Name' );
+</%INIT>
+<%ARGS>
+$GroupField2 => ''
+$GroupOp2 => ''
+$GroupString2 => ''
+</%ARGS>
diff --git a/share/html/Elements/SelectGroups3 b/share/html/Elements/SelectGroups3
new file mode 100644
index 000000000..73e3bac90
--- /dev/null
+++ b/share/html/Elements/SelectGroups3
@@ -0,0 +1,68 @@
+%# BEGIN BPS TAGGED BLOCK {{{
+%#
+%# COPYRIGHT:
+%#
+%# This software is Copyright (c) 1996-2018 Best Practical Solutions, LLC
+%# <sales at bestpractical.com>
+%#
+%# (Except where explicitly superseded by other copyright notices)
+%#
+%#
+%# LICENSE:
+%#
+%# This work is made available to you under the terms of Version 2 of
+%# the GNU General Public License. A copy of that license should have
+%# been provided with this software, but in any event can be snarfed
+%# from www.gnu.org.
+%#
+%# This work is distributed in the hope that it will be useful, but
+%# WITHOUT ANY WARRANTY; without even the implied warranty of
+%# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+%# General Public License for more details.
+%#
+%# You should have received a copy of the GNU General Public License
+%# along with this program; if not, write to the Free Software
+%# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+%# 02110-1301 or visit their web page on the internet at
+%# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html.
+%#
+%#
+%# CONTRIBUTION SUBMISSION POLICY:
+%#
+%# (The following paragraph is not intended to limit the rights granted
+%# to you to modify and distribute this software under the terms of
+%# the GNU General Public License and is only of importance to you if
+%# you choose to contribute your changes and enhancements to the
+%# community by submitting them to Best Practical Solutions, LLC.)
+%#
+%# By intentionally submitting any modifications, corrections or
+%# derivatives to this work, or any other work intended for use with
+%# Request Tracker, to Best Practical Solutions, LLC, you confirm that
+%# you are the copyright holder for those contributions and you grant
+%# Best Practical Solutions, LLC a nonexclusive, worldwide, irrevocable,
+%# royalty-free, perpetual, license to use, copy, create derivative
+%# works based on those contributions, and sublicense and distribute
+%# those contributions and any derivatives thereof.
+%#
+%# END BPS TAGGED BLOCK }}}
+<select name="GroupField3">
+% foreach my $col (RT::Group->BasicColumns) {
+<option <% ($GroupField3 eq $col->[0]) ? 'selected="selected"' : '' %> value="<% $col->[0] %>"><% loc($col->[1]) %></option>
+% }
+% while (my $CF = $CFs->Next) {
+% my $val = "CustomField-" . $CF->Id;
+<option <% ($GroupField3 eq $val) ? 'selected="selected"' : '' %> value="<% $val %>"><&|/l&>CustomField</&>: <% $CF->Name %></option>
+% }
+</select>
+<& /Elements/SelectMatch, Name => 'GroupOp3', Default => $GroupOp3 &>
+<input size="8" name="GroupString3" value="<% $GroupString3 %>" />
+<%INIT>
+my $CFs = RT::CustomFields->new($session{'CurrentUser'});
+$CFs->LimitToChildType('RT::Group');
+$CFs->OrderBy( FIELD => 'Name' );
+</%INIT>
+<%ARGS>
+$GroupField3 => ''
+$GroupOp3 => ''
+$GroupString3 => ''
+</%ARGS>
commit af2303e908dfc53a10561a0fc7480d74c8cf268e
Author: Maureen E. Mirville <maureen at bestpractical.com>
Date: Fri Jul 27 11:46:48 2018 -0400
Add tests for filtering Groups search on Admin>Groups>select
diff --git a/t/web/admin_groups.t b/t/web/admin_groups.t
index 075fb6282..8d56a4569 100644
--- a/t/web/admin_groups.t
+++ b/t/web/admin_groups.t
@@ -1,7 +1,7 @@
use strict;
use warnings;
-use RT::Test tests => 26;
+use RT::Test tests => undef;
my ( $url, $m ) = RT::Test->started_ok;
ok( $m->login(), 'logged in' );
@@ -56,3 +56,69 @@ ok( $m->login(), 'logged in' );
$m->content_contains('test group', 'did not find new name');
}
+diag "# Test /Admin/Groups/index.html search filtering";
+{
+ diag "Create group CustomFields";
+ my @cf_names = qw( CF1 CF2 CF3 );
+ my @cfs = ();
+ foreach my $cf_name ( @cf_names ) {
+ my $cf = RT::CustomField->new( RT->SystemUser );
+ my ( $id, $msg ) = $cf->Create(
+ Name => $cf_name,
+ TypeComposite => 'Freeform-1',
+ LookupType => RT::Group->CustomFieldLookupType,
+ );
+ ok( $id, $msg );
+ # Create a global ObjectCustomField record
+ my $object = $cf->RecordClassFromLookupType->new( RT->SystemUser );
+ ( $id, $msg ) = $cf->AddToObject( $object );
+ ok( $id, $msg );
+ push ( @cfs, $cf );
+ }
+ my $cf_1 = $cfs[0];
+ my $cf_2 = $cfs[1];
+ my $cf_3 = $cfs[2];
+
+ diag "Create groups and add some CustomField values";
+ my @group_names = qw( Group1 Group2 Group3 Group4 );
+ my @groups = ();
+ foreach my $group_name ( @group_names ) {
+ my $group = RT::Group->new( RT->SystemUser );
+ my ( $id, $msg ) = $group->CreateUserDefinedGroup( Name => $group_name );
+ isnt ( $id, 0, $msg.': '.$group_name );
+ push ( @groups, $group );
+ }
+ my $group_1 = $groups[0];
+ $group_1->AddCustomFieldValue( Field => $cf_1->id, Value => 'one' );
+
+ my $group_2 = $groups[1];
+ $group_2->AddCustomFieldValue( Field => $cf_1->id, Value => 'one' );
+ $group_2->AddCustomFieldValue( Field => $cf_2->id, Value => 'two' );
+
+ my $group_3 = $groups[2];
+ $group_3->AddCustomFieldValue( Field => $cf_1->id, Value => 'one' );
+ $group_3->AddCustomFieldValue( Field => $cf_2->id, Value => 'two' );
+ $group_3->AddCustomFieldValue( Field => $cf_3->id, Value => 'three' );
+
+ my $group_4 = $groups[3];
+
+ diag "Filter groups search on Admin > Groups > select page";
+ $m->get_ok( $url . '/Admin/Groups/index.html' );
+ ok( $m->form_name( 'Admin_Groups' ), 'found the filter admin groups form');
+ $m->select( GroupField => 'Name', GroupOp => 'LIKE' );
+ $m->field( GroupString => 'Group' );
+ $m->select( GroupField2 => 'CustomField: '.$cf_1->Name, GroupOp2 => 'LIKE' );
+ $m->field( GroupString2 => 'one' );
+ $m->select( GroupField3 => 'CustomField: '.$cf_2->Name, GroupOp3 => 'LIKE' );
+ $m->field( GroupString3 => 'two' );
+ $m->click( 'Go' );
+
+ diag "Verify results contain Groups 2 & 3, but not 1 & 4";
+ $m->content_contains( $group_2->Name );
+ $m->content_contains( $group_3->Name );
+ $m->content_lacks( $group_1->Name );
+ $m->content_lacks( $group_4->Name );
+}
+
+
+done_testing;
commit de465454116256794f4545f16b17bebf159317b6
Author: Maureen E. Mirville <maureen at bestpractical.com>
Date: Wed Jul 25 12:04:43 2018 -0400
Add more filtering to Users search on Admin>Users>select
diff --git a/share/html/Admin/Users/index.html b/share/html/Admin/Users/index.html
index f3f4d7b2b..6f8946753 100644
--- a/share/html/Admin/Users/index.html
+++ b/share/html/Admin/Users/index.html
@@ -69,16 +69,18 @@ jQuery(function(){
</script>
</form>
-<form method="post" action="<% RT->Config->Get('WebPath') %>/Admin/Users/index.html">
+<form method="post" action="<% RT->Config->Get('WebPath') %>/Admin/Users/index.html" name="Admin_Users">
% foreach my $field( qw(Format Rows Page Order OrderBy) ) {
% next unless defined $ARGS{ $field } && length $ARGS{ $field };
<input type="hidden" name="<% $field %>" value="<% $ARGS{ $field } %>" />
% }
<&|/l&>Find all users whose</&> <& /Elements/SelectUsers, %ARGS, Fields => \@fields &><br />
+<&|/l&>And all users whose</&> <& /Elements/SelectUsers2, %ARGS, Fields => \@fields &><br />
+<&|/l&>And all users whose</&> <& /Elements/SelectUsers3, %ARGS, Fields => \@fields &><br />
<input type="checkbox" class="checkbox" id="FindDisabledUsers" name="FindDisabledUsers" value="1" <% $FindDisabledUsers? 'checked="checked"': '' %> />
<label for="FindDisabledUsers"><&|/l&>Include disabled users in search.</&></label>
<br />
-<div align="right"><input type="submit" class="button" value="<&|/l&>Go!</&>" /></div>
+<div align="right"><input type="submit" class="button" value="<&|/l&>Go!</&>" name="Go" /></div>
</form>
% unless ( $users->Count ) {
@@ -94,7 +96,7 @@ jQuery(function(){
Format => $Format,
Collection => $users,
AllowSorting => 1,
- PassArguments => [qw(Format Rows Page Order OrderBy UserString UserOp UserField IdLike EmailLike FindDisabledUsers)],
+ PassArguments => [qw(Format Rows Page Order OrderBy UserString UserOp UserField UserString2 UserOp2 UserField2 UserString3 UserOp3 UserField3 IdLike EmailLike FindDisabledUsers)],
&>
% }
@@ -106,19 +108,31 @@ $users->FindAllRows if $FindDisabledUsers;
if ( defined($UserString) && length $UserString ) {
$caption = loc("Users matching search criteria");
- if ( $UserField =~ /^CustomField-(\d+)/ ) {
- $users->LimitCustomField(
- CUSTOMFIELD => $1,
- OPERATOR => $UserOp,
- VALUE => $UserString,
- );
- }
- else {
- $users->Limit(
- FIELD => $UserField,
- OPERATOR => $UserOp,
- VALUE => $UserString,
- );
+ my %user1 = ( field => $UserField, op => $UserOp, string => $UserString );
+ my %user2 = ( field => $UserField2, op => $UserOp2, string => $UserString2 );
+ my %user3 = ( field => $UserField3, op => $UserOp3, string => $UserString3 );
+ my @users_queries = ( \%user1 );
+
+ push ( @users_queries, \%user2 ) if length $UserString2;
+ push ( @users_queries, \%user3 ) if length $UserString3;
+
+ foreach my $user ( @users_queries ) {
+ if ( $user->{'field'} =~ /^CustomField-(\d+)/ ) {
+ $users->LimitCustomField(
+ CUSTOMFIELD => $1,
+ OPERATOR => $user->{'op'},
+ VALUE => $user->{'string'},
+ ENTRYAGGREGATOR => 'AND',
+ );
+ }
+ else {
+ $users->Limit(
+ FIELD => $user->{'field'},
+ OPERATOR => $user->{'op'},
+ VALUE => $user->{'string'},
+ ENTRYAGGREGATOR => 'AND',
+ );
+ }
}
RT::Interface::Web::Redirect(RT->Config->Get('WebURL')."Admin/Users/Modify.html?id=".$users->First->id)
if $users->Count == 1;
@@ -161,6 +175,12 @@ $Format => undef,
$UserString => undef
$UserOp => '='
$UserField => 'Name'
+$UserString2 => undef
+$UserOp2 => '='
+$UserField2 => 'Name'
+$UserString3 => undef
+$UserOp3 => '='
+$UserField3 => 'Name'
$IdLike => undef
$EmailLike => undef
diff --git a/share/html/Elements/SelectUsers2 b/share/html/Elements/SelectUsers2
new file mode 100644
index 000000000..e598c8315
--- /dev/null
+++ b/share/html/Elements/SelectUsers2
@@ -0,0 +1,81 @@
+%# BEGIN BPS TAGGED BLOCK {{{
+%#
+%# COPYRIGHT:
+%#
+%# This software is Copyright (c) 1996-2018 Best Practical Solutions, LLC
+%# <sales at bestpractical.com>
+%#
+%# (Except where explicitly superseded by other copyright notices)
+%#
+%#
+%# LICENSE:
+%#
+%# This work is made available to you under the terms of Version 2 of
+%# the GNU General Public License. A copy of that license should have
+%# been provided with this software, but in any event can be snarfed
+%# from www.gnu.org.
+%#
+%# This work is distributed in the hope that it will be useful, but
+%# WITHOUT ANY WARRANTY; without even the implied warranty of
+%# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+%# General Public License for more details.
+%#
+%# You should have received a copy of the GNU General Public License
+%# along with this program; if not, write to the Free Software
+%# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+%# 02110-1301 or visit their web page on the internet at
+%# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html.
+%#
+%#
+%# CONTRIBUTION SUBMISSION POLICY:
+%#
+%# (The following paragraph is not intended to limit the rights granted
+%# to you to modify and distribute this software under the terms of
+%# the GNU General Public License and is only of importance to you if
+%# you choose to contribute your changes and enhancements to the
+%# community by submitting them to Best Practical Solutions, LLC.)
+%#
+%# By intentionally submitting any modifications, corrections or
+%# derivatives to this work, or any other work intended for use with
+%# Request Tracker, to Best Practical Solutions, LLC, you confirm that
+%# you are the copyright holder for those contributions and you grant
+%# Best Practical Solutions, LLC a nonexclusive, worldwide, irrevocable,
+%# royalty-free, perpetual, license to use, copy, create derivative
+%# works based on those contributions, and sublicense and distribute
+%# those contributions and any derivatives thereof.
+%#
+%# END BPS TAGGED BLOCK }}}
+<select name="UserField2">
+% foreach my $col (@fields) {
+<option <% ($UserField2 eq $col->[0]) ? 'selected="selected"' : '' |n %> value="<% $col->[0] %>"><% loc($col->[1]) %></option>
+% }
+% while (my $CF = $CFs->Next) {
+% my $val = "CustomField-" . $CF->Id;
+<option <% ($UserField2 eq $val) ? 'selected="selected"' : '' |n %> value="<% $val %>"><&|/l&>CustomField</&>: <% $CF->Name %></option>
+% }
+</select>
+<& /Elements/SelectMatch, Name => 'UserOp2', Default => $UserOp2 &>
+<input size="8" name="UserString2" value="<% $UserString2 %>" />
+<%INIT>
+my $CFs = RT::CustomFields->new($session{'CurrentUser'});
+$CFs->LimitToChildType('RT::User');
+$CFs->OrderBy( FIELD => 'Name' );
+
+my @fields = RT::User->BasicColumns;
+
+if ( $Fields and ref $Fields eq 'ARRAY' ) {
+ if ( ref $Fields->[0] eq 'ARRAY' ) {
+ @fields = @$Fields;
+ }
+ else {
+ # make the name equal the label
+ @fields = [ @$Fields, @$Fields ];
+ }
+}
+</%INIT>
+<%ARGS>
+$UserField2 => ''
+$UserOp2 => ''
+$UserString2 => ''
+$Fields => undef
+</%ARGS>
diff --git a/share/html/Elements/SelectUsers3 b/share/html/Elements/SelectUsers3
new file mode 100644
index 000000000..e7c84c4c0
--- /dev/null
+++ b/share/html/Elements/SelectUsers3
@@ -0,0 +1,81 @@
+%# BEGIN BPS TAGGED BLOCK {{{
+%#
+%# COPYRIGHT:
+%#
+%# This software is Copyright (c) 1996-2018 Best Practical Solutions, LLC
+%# <sales at bestpractical.com>
+%#
+%# (Except where explicitly superseded by other copyright notices)
+%#
+%#
+%# LICENSE:
+%#
+%# This work is made available to you under the terms of Version 2 of
+%# the GNU General Public License. A copy of that license should have
+%# been provided with this software, but in any event can be snarfed
+%# from www.gnu.org.
+%#
+%# This work is distributed in the hope that it will be useful, but
+%# WITHOUT ANY WARRANTY; without even the implied warranty of
+%# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+%# General Public License for more details.
+%#
+%# You should have received a copy of the GNU General Public License
+%# along with this program; if not, write to the Free Software
+%# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+%# 02110-1301 or visit their web page on the internet at
+%# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html.
+%#
+%#
+%# CONTRIBUTION SUBMISSION POLICY:
+%#
+%# (The following paragraph is not intended to limit the rights granted
+%# to you to modify and distribute this software under the terms of
+%# the GNU General Public License and is only of importance to you if
+%# you choose to contribute your changes and enhancements to the
+%# community by submitting them to Best Practical Solutions, LLC.)
+%#
+%# By intentionally submitting any modifications, corrections or
+%# derivatives to this work, or any other work intended for use with
+%# Request Tracker, to Best Practical Solutions, LLC, you confirm that
+%# you are the copyright holder for those contributions and you grant
+%# Best Practical Solutions, LLC a nonexclusive, worldwide, irrevocable,
+%# royalty-free, perpetual, license to use, copy, create derivative
+%# works based on those contributions, and sublicense and distribute
+%# those contributions and any derivatives thereof.
+%#
+%# END BPS TAGGED BLOCK }}}
+<select name="UserField3">
+% foreach my $col (@fields) {
+<option <% ($UserField3 eq $col->[0]) ? 'selected="selected"' : '' |n %> value="<% $col->[0] %>"><% loc($col->[1]) %></option>
+% }
+% while (my $CF = $CFs->Next) {
+% my $val = "CustomField-" . $CF->Id;
+<option <% ($UserField3 eq $val) ? 'selected="selected"' : '' |n %> value="<% $val %>"><&|/l&>CustomField</&>: <% $CF->Name %></option>
+% }
+</select>
+<& /Elements/SelectMatch, Name => 'UserOp3', Default => $UserOp3 &>
+<input size="8" name="UserString3" value="<% $UserString3 %>" />
+<%INIT>
+my $CFs = RT::CustomFields->new($session{'CurrentUser'});
+$CFs->LimitToChildType('RT::User');
+$CFs->OrderBy( FIELD => 'Name' );
+
+my @fields = RT::User->BasicColumns;
+
+if ( $Fields and ref $Fields eq 'ARRAY' ) {
+ if ( ref $Fields->[0] eq 'ARRAY' ) {
+ @fields = @$Fields;
+ }
+ else {
+ # make the name equal the label
+ @fields = [ @$Fields, @$Fields ];
+ }
+}
+</%INIT>
+<%ARGS>
+$UserField3 => ''
+$UserOp3 => ''
+$UserString3 => ''
+$Fields => undef
+</%ARGS>
commit 5e61b8fbe838aa8e5dcced638478a034c8afe407
Author: Maureen E. Mirville <maureen at bestpractical.com>
Date: Fri Jul 27 16:28:56 2018 -0400
Add tests for filtering Users search on Admin>Users>select
diff --git a/t/web/admin_user.t b/t/web/admin_user.t
index 04b13a993..5fbe8eb74 100644
--- a/t/web/admin_user.t
+++ b/t/web/admin_user.t
@@ -74,6 +74,72 @@ $m->submit_form_ok(
is( $form->find_input('PrivateKey')->value,
'C798591AA831DBFB', 'set private key' );
+
+diag "# Test /Admin/Users/index.html search filtering";
+
+diag "Create user CustomFields";
+my @cf_names = qw( CF1 CF2 CF3 );
+my @cfs = ();
+foreach my $cf_name ( @cf_names ) {
+ my $cf = RT::CustomField->new( RT->SystemUser );
+ my ( $id, $msg ) = $cf->Create(
+ Name => $cf_name,
+ TypeComposite => 'Freeform-1',
+ LookupType => RT::User->CustomFieldLookupType,
+ );
+ ok( $id, $msg );
+ # Create a global ObjectCustomField record
+ my $object = $cf->RecordClassFromLookupType->new( RT->SystemUser );
+ ( $id, $msg ) = $cf->AddToObject( $object );
+ ok( $id, $msg );
+ push ( @cfs, $cf );
+}
+my $cf_1 = $cfs[0];
+my $cf_2 = $cfs[1];
+my $cf_3 = $cfs[2];
+
+diag "Create users and add some CustomField values";
+my @user_names = qw( user1 user2 user3 user4 );
+my @users = ();
+foreach my $user_name ( @user_names ) {
+ my $user = RT::Test->load_or_create_user(
+ Name => $user_name, Password => 'password',
+ );
+ ok( $user && $user->id, 'Created '.$user->Name.' with id '.$user->Id );
+ push ( @users, $user );
+}
+
+my $user_1 = $users[0];
+$user_1->AddCustomFieldValue( Field => $cf_1->id, Value => 'one' );
+
+my $user_2 = $users[1];
+$user_2->AddCustomFieldValue( Field => $cf_1->id, Value => 'one' );
+$user_2->AddCustomFieldValue( Field => $cf_2->id, Value => 'two' );
+
+my $user_3 = $users[2];
+$user_3->AddCustomFieldValue( Field => $cf_1->id, Value => 'one' );
+$user_3->AddCustomFieldValue( Field => $cf_2->id, Value => 'two' );
+$user_3->AddCustomFieldValue( Field => $cf_3->id, Value => 'three' );
+
+my $user_4 = $users[3];
+
+diag "Filter users search on Admin > Users > select page";
+$m->get_ok( $url . '/Admin/Users/index.html' );
+ok( $m->form_name( 'Admin_Users' ), 'found the filter admin users form');
+$m->select( UserField => 'Name', UserOp => 'LIKE' );
+$m->field( UserString => 'user' );
+$m->select( UserField2 => 'CustomField: '.$cf_1->Name, UserOp2 => 'LIKE' );
+$m->field( UserString2 => 'one' );
+$m->select( UserField3 => 'CustomField: '.$cf_2->Name, UserOp3 => 'LIKE' );
+$m->field( UserString3 => 'two' );
+$m->click( 'Go' );
+
+diag "Verify results contain users 2 & 3, but not 1 & 4";
+$m->content_contains( $user_2->Name );
+$m->content_contains( $user_3->Name );
+$m->content_lacks( $user_1->Name );
+$m->content_lacks( $user_4->Name );
+
# TODO more /Admin/Users tests
done_testing;
-----------------------------------------------------------------------
More information about the rt-commit
mailing list