[Rt-commit] rt branch, 4.4/add-groups-users-cf-filter, created. rt-4.4.3-26-g58cb1c137
Maureen Mirville
maureen at bestpractical.com
Tue Sep 11 14:00:24 EDT 2018
The branch, 4.4/add-groups-users-cf-filter has been created
at 58cb1c137cb1d77d5c84cac1b5b8e2ad74496001 (commit)
- Log -----------------------------------------------------------------
commit 64b2a045cbb9a942704d4f5785c1a93b37c44107
Author: Maureen E. Mirville <maureen at bestpractical.com>
Date: Wed Jul 25 09:49:42 2018 -0400
Allow multiple search criteria on Group Admin page
diff --git a/share/html/Admin/Groups/index.html b/share/html/Admin/Groups/index.html
index 416bd5dd8..a6eee9061 100644
--- a/share/html/Admin/Groups/index.html
+++ b/share/html/Admin/Groups/index.html
@@ -64,11 +64,21 @@ 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="GroupsAdmin">
<&|/l&>Find groups whose</&> <& /Elements/SelectGroups &><br />
+<&|/l&>And groups whose</&> <& /Elements/SelectGroups,
+ SelectFieldName => 'GroupField2',
+ SelectOpName => 'GroupOp2',
+ InputStringName => 'GroupString2',
+&><br />
+<&|/l&>And groups whose</&> <& /Elements/SelectGroups,
+ SelectFieldName => 'GroupField3',
+ SelectOpName => 'GroupOp3',
+ InputStringName => 'GroupString3',
+&><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 +94,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 +110,29 @@ 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 @groups = ();
+ push @groups, { field => $GroupField, op => $GroupOp, string => $GroupString };
+ push @groups, { field => $GroupField2, op => $GroupOp2, string => $GroupString2 } if length $GroupString2;
+ push @groups, { field => $GroupField3, op => $GroupOp3, string => $GroupString3 } 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;
@@ -129,8 +148,14 @@ my $Rows = RT->Config->Get('AdminSearchResultRows')->{'Groups'} || 50;
<%ARGS>
$Format => undef,
-$GroupString => '' unless defined $GroupString
+$GroupString => ''
$GroupOp => '='
$GroupField => 'Name'
+$GroupString2 => ''
+$GroupOp2 => '='
+$GroupField2 => 'Name'
+$GroupString3 => ''
+$GroupOp3 => '='
+$GroupField3 => 'Name'
$FindDisabledGroups => 0
</%ARGS>
diff --git a/share/html/Elements/SelectGroups b/share/html/Elements/SelectGroups
index 418f5d1c0..6522eacab 100644
--- a/share/html/Elements/SelectGroups
+++ b/share/html/Elements/SelectGroups
@@ -45,7 +45,7 @@
%# those contributions and any derivatives thereof.
%#
%# END BPS TAGGED BLOCK }}}
-<select name="GroupField">
+<select name="<% $SelectFieldName %>">
% foreach my $col (RT::Group->BasicColumns) {
<option <% ($GroupField eq $col->[0]) ? 'selected="selected"' : '' %> value="<% $col->[0] %>"><% loc($col->[1]) %></option>
% }
@@ -54,8 +54,8 @@
<option <% ($GroupField eq $val) ? 'selected="selected"' : '' %> value="<% $val %>"><&|/l&>CustomField</&>: <% $CF->Name %></option>
% }
</select>
-<& /Elements/SelectMatch, Name => 'GroupOp', Default => $GroupOp &>
-<input size="8" name="GroupString" value="<% $GroupString %>" />
+<& /Elements/SelectMatch, Name => $SelectOpName, Default => $GroupOp &>
+<input size="8" name="<% $InputStringName %>" value="<% $GroupString %>" />
<%INIT>
my $CFs = RT::CustomFields->new($session{'CurrentUser'});
$CFs->LimitToChildType('RT::Group');
@@ -65,4 +65,7 @@ $CFs->OrderBy( FIELD => 'Name' );
$GroupField => ''
$GroupOp => ''
$GroupString => ''
+$SelectFieldName => 'GroupField'
+$SelectOpName => 'GroupOp'
+$InputStringName => 'GroupString'
</%ARGS>
commit d85190fc81898e090ddd170ce0918f93d8862bdb
Author: Maureen E. Mirville <maureen at bestpractical.com>
Date: Fri Jul 27 11:46:48 2018 -0400
Add tests for multiple search criteria on Group Admin page
diff --git a/t/web/admin_groups.t b/t/web/admin_groups.t
index 075fb6282..04c742d8c 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,61 @@ ok( $m->login(), 'logged in' );
$m->content_contains('test group', 'did not find new name');
}
+{
+ diag "Test group searches";
+ 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];
+
+ 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 );
+ ok ( $id, $msg.': '.$group_name );
+ push ( @groups, $group );
+ }
+ $groups[0]->AddCustomFieldValue( Field => $cf_1->id, Value => 'one' );
+
+ $groups[1]->AddCustomFieldValue( Field => $cf_1->id, Value => 'one' );
+ $groups[1]->AddCustomFieldValue( Field => $cf_2->id, Value => 'two' );
+
+ $groups[2]->AddCustomFieldValue( Field => $cf_1->id, Value => 'one' );
+ $groups[2]->AddCustomFieldValue( Field => $cf_2->id, Value => 'two' );
+ $groups[2]->AddCustomFieldValue( Field => $cf_3->id, Value => 'three' );
+
+ $m->get_ok( $url . '/Admin/Groups/index.html' );
+ ok( $m->form_name( 'GroupsAdmin' ), '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( $groups[1]->Name );
+ $m->content_contains( $groups[2]->Name );
+ $m->content_lacks( $groups[0]->Name );
+ $m->content_lacks( $groups[3]->Name );
+}
+
+
+done_testing;
commit 3e5427fdabfa7b0ef907478a7dc97ef068156693
Author: Maureen E. Mirville <maureen at bestpractical.com>
Date: Wed Jul 25 12:04:43 2018 -0400
Allow multiple search criteria on Users Admin page
diff --git a/share/html/Admin/Users/index.html b/share/html/Admin/Users/index.html
index f3f4d7b2b..716271e32 100644
--- a/share/html/Admin/Users/index.html
+++ b/share/html/Admin/Users/index.html
@@ -69,16 +69,28 @@ 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="UsersAdmin">
% 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/SelectUsers, %ARGS, Fields => \@fields,
+ SelectFieldName => 'UserField2',
+ SelectOpName => 'UserOp2',
+ InputStringName => 'UserString2',
+ UserString => $UserString2,
+&><br />
+<&|/l&>And all users whose</&> <& /Elements/SelectUsers, %ARGS, Fields => \@fields,
+ SelectFieldName => 'UserField3',
+ SelectOpName => 'UserOp3',
+ InputStringName => 'UserString3',
+ UserString => $UserString3,
+&><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 +106,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 +118,28 @@ $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 @users_queries = ();
+ push @users_queries, { field => $UserField, op => $UserOp, string => $UserString };
+ push @users_queries, { field => $UserField2, op => $UserOp2, string => $UserString2 } if length $UserString2;
+ push @users_queries, { field => $UserField3, op => $UserOp3, string => $UserString3 } 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 +182,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/SelectUsers b/share/html/Elements/SelectUsers
index 8f01c3696..ea15aa6e8 100644
--- a/share/html/Elements/SelectUsers
+++ b/share/html/Elements/SelectUsers
@@ -45,7 +45,7 @@
%# those contributions and any derivatives thereof.
%#
%# END BPS TAGGED BLOCK }}}
-<select name="UserField">
+<select name="<% $SelectFieldName %>">
% foreach my $col (@fields) {
<option <% ($UserField eq $col->[0]) ? 'selected="selected"' : '' |n %> value="<% $col->[0] %>"><% loc($col->[1]) %></option>
% }
@@ -54,8 +54,8 @@
<option <% ($UserField eq $val) ? 'selected="selected"' : '' |n %> value="<% $val %>"><&|/l&>CustomField</&>: <% $CF->Name %></option>
% }
</select>
-<& /Elements/SelectMatch, Name => 'UserOp', Default => $UserOp &>
-<input size="8" name="UserString" value="<% $UserString %>" />
+<& /Elements/SelectMatch, Name => $SelectOpName, Default => $UserOp &>
+<input size="8" name="<% $InputStringName %>" value="<% $UserString %>" />
<%INIT>
my $CFs = RT::CustomFields->new($session{'CurrentUser'});
$CFs->LimitToChildType('RT::User');
@@ -78,4 +78,7 @@ $UserField => ''
$UserOp => ''
$UserString => ''
$Fields => undef
+$SelectFieldName => 'UserField'
+$SelectOpName => 'UserOp'
+$InputStringName => 'UserString'
</%ARGS>
commit 58cb1c137cb1d77d5c84cac1b5b8e2ad74496001
Author: Maureen E. Mirville <maureen at bestpractical.com>
Date: Fri Jul 27 16:28:56 2018 -0400
Add tests for multiple search criteria on Users Admin page
diff --git a/t/web/admin_user.t b/t/web/admin_user.t
index 04b13a993..ffc287e7a 100644
--- a/t/web/admin_user.t
+++ b/t/web/admin_user.t
@@ -74,6 +74,64 @@ $m->submit_form_ok(
is( $form->find_input('PrivateKey')->value,
'C798591AA831DBFB', 'set private key' );
+
+diag "Test user searches";
+
+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];
+
+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 );
+}
+
+$users[0]->AddCustomFieldValue( Field => $cf_1->id, Value => 'one' );
+
+$users[1]->AddCustomFieldValue( Field => $cf_1->id, Value => 'one' );
+$users[1]->AddCustomFieldValue( Field => $cf_2->id, Value => 'two' );
+
+$users[2]->AddCustomFieldValue( Field => $cf_1->id, Value => 'one' );
+$users[2]->AddCustomFieldValue( Field => $cf_2->id, Value => 'two' );
+$users[2]->AddCustomFieldValue( Field => $cf_3->id, Value => 'three' );
+
+$m->get_ok( $url . '/Admin/Users/index.html' );
+ok( $m->form_name( 'UsersAdmin' ), '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( $users[1]->Name );
+$m->content_contains( $users[2]->Name );
+$m->content_lacks( $users[0]->Name );
+$m->content_lacks( $users[3]->Name );
+
# TODO more /Admin/Users tests
done_testing;
-----------------------------------------------------------------------
More information about the rt-commit
mailing list