Skip to content

Commit

Permalink
WIP: Allow enable/disable saved searches and dashboads on list pages
Browse files Browse the repository at this point in the history
  • Loading branch information
richieri-bps committed Feb 26, 2025
1 parent 7e1b73c commit 52e19ad
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 13 deletions.
4 changes: 3 additions & 1 deletion share/html/Admin/Global/SavedSearches.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,12 @@
<& /Elements/Header, Title => loc("Global Saved Searches") &>
<& /Elements/Tabs &>

<& /Elements/ListActions &>
<& /Elements/ListActions, actions => \@results &>
<& /Search/Elements/ShowSavedSearches, Rows => $ARGS{RowsPerPage} // RT->Config->Get('DefaultSearchResultRowsPerPage') // 50, %ARGS, ShowForm => 1, Object => RT->System &>

<%INIT>
Abort( loc("Permission Denied") )
unless $session{CurrentUser}->HasRight( Right => 'SeeSavedSearch', Object => RT->System );

my @results;
</%INIT>
76 changes: 64 additions & 12 deletions share/html/Search/Elements/ShowSavedSearches
Original file line number Diff line number Diff line change
Expand Up @@ -90,26 +90,76 @@
</form>
% }

% foreach my $object (@objects) {
% my $saved_searches = $object->SavedSearches( Type => $Type );
% $saved_searches->FindAllRows if $IncludeDisabled;
% my $title;
% if (ref $object eq 'RT::User' && $object->Id == $session{CurrentUser}->Id) {
% $title = loc("My saved searches");
% } else {
% $title = loc("[_1]'s saved searches", $object->Name);
% }
% $title =~ s/([\\'])/\\$1/g;
% $title = $m->interp->apply_escapes($title, 'h');
<%perl>
foreach my $object (@objects) {
my $saved_searches = $object->SavedSearches( Type => $Type );
$saved_searches->FindAllRows if $IncludeDisabled;
my $title;
if (ref $object eq 'RT::User' && $object->Id == $session{CurrentUser}->Id) {
$title = loc("My saved searches");
} else {
$title = loc("[_1]'s saved searches", $object->Name);
}
$title =~ s/([\\'])/\\$1/g;
$title = $m->interp->apply_escapes($title, 'h');

my $format = $Type ? qq{'__Results__/TITLE:$title', __Disabled__} : qq{'__Results__/TITLE:$title', __Type__,__Disabled__};
my $can_modify;
if (ref $object eq 'RT::User' && $object->Id == $session{CurrentUser}->Id
&& $session{CurrentUser}->HasRight( Object => $RT::System, Right => 'AdminOwnSavedSearch')
) {
$can_modify = 1;
} elsif (ref $object eq 'RT::System' && $session{CurrentUser}->HasRight( Object => $RT::System, Right => 'AdminSavedSearch' )) {
$can_modify = 1;
} elsif (ref $object eq 'RT::Group' && $session{CurrentUser}->HasRight( Object => $object, Right => 'AdminGroupSavedSearch' )) {
$can_modify = 1;
}
if ($can_modify) {
$format = $Type ? qq{'__Results__/TITLE:$title', '__CheckBox.{Enabled}__/TITLE:$enabled_title'} : qq{'__Results__/TITLE:$title', __Type__, '__CheckBox.{Enabled}__/TITLE:$enabled_title'};
}
</%perl>
<& /Elements/CollectionList,
%ARGS,
Format => $Type ? qq{'__Results__/TITLE:$title', __Disabled__} : qq{'__Results__/TITLE:$title', __Type__, __Disabled__},
Format => $format,
Collection => $saved_searches,
PassArguments => [qw(Type IncludeDisabled RowsPerPage id)],
&>
% }
<div class="row mt-2">
<div class="col-12">
<div align="right">
<input type="submit" name="Update" class="btn btn-primary" value="<&|/l&>Update</&>" />
</div>
</div>
</div>
<%INIT>
my @objects = $Object ? $Object : RT::SavedSearch->new($session{CurrentUser})->ObjectsForLoading();

my $enabled_title = loc('Enabled');
if ($Update) {
foreach my $object (@objects) {
my $saved_searches = $object->SavedSearches( Type => $Type );
$saved_searches->FindAllRows if $IncludeDisabled;
while (my $saved_search = $saved_searches->Next) {
if ($saved_search->Disabled && grep { $_ == $saved_search->Id } @Enabled) {
my ($ok, $msg) = $saved_search->SetDisabled(0);
push @{$session{'Actions'}}, $msg if $msg;
} elsif (!$saved_search->Disabled && !grep { $_ == $saved_search->Id } @Enabled) {
my ($ok, $msg) = $saved_search->SetDisabled(1);
push @{$session{'Actions'}}, $msg if $msg;
}
}
}
} else {
foreach my $object (@objects) {
my $saved_searches = $object->SavedSearches( Type => $Type );
$saved_searches->FindAllRows if $IncludeDisabled;
while (my $saved_search = $saved_searches->Next) {
push @Enabled, $saved_search->Id unless $saved_search->Disabled;
}
}
$DECODED_ARGS->{Enabled} = \@Enabled;
}
</%INIT>

<%ARGS>
Expand All @@ -118,4 +168,6 @@ $Type => ''
$Object => undef
$ShowForm => undef
$FormAction => undef
@Enabled => ()
$Update => undef
</%ARGS>

0 comments on commit 52e19ad

Please sign in to comment.