[Rt-devel] [PATCH] SelfService: show saved searches
Jason Long
jlong at messiah.edu
Thu Jan 3 16:34:37 EST 2008
Consider this an early draft. Applicable against 3.6-RELEASE.
If it seems useful, but needs some improvement, just let me know.
This patch adds a tab to the Self-Service screen called "Queries".
This Queries tab lists saved searches available to the user, if any.
Clicking on the name of a search will display a ticket list,
where each ticket links to the Self-Service page for that ticket.
This is useful if you want to give an unprivileged user the ability
to see certain tickets in which they are not the requester.
You will still need to setup appropriate RT permissions for the user.
Of course, the Self-Service user won't be able to define any queries.
One way to handle this is to define a group for the saved search,
add yourself to the group and define a query to save to the group,
then add the Self-Service user to this same group. Now when that
user logs in, they should see the query you defined.
(Remember to give the group the ShowSavedSearches permission.)
---
html/SelfService/Elements/Tabs | 3 ++
html/SelfService/Query.html | 59 +++++++++++++++++++++++++++++++++++
html/SelfService/QueryList.html | 66 +++++++++++++++++++++++++++++++++++++++
3 files changed, 128 insertions(+), 0 deletions(-)
(Patch is attached)
-------------- next part --------------
diff --git a/html/SelfService/Elements/Tabs b/html/SelfService/Elements/Tabs
index 164fa28..59b20ed 100755
--- a/html/SelfService/Elements/Tabs
+++ b/html/SelfService/Elements/Tabs
@@ -81,6 +81,9 @@ my $tabs = { A => { title => loc('Open tickets'),
B => { title => loc('Closed tickets'),
path => 'SelfService/Closed.html',
},
+ Q => { title => loc('Queries'),
+ path => 'SelfService/QueryList.html',
+ },
};
if ($queue_count > 1) {
diff --git a/html/SelfService/Query.html b/html/SelfService/Query.html
new file mode 100644
index 0000000..1f81bca
--- /dev/null
+++ b/html/SelfService/Query.html
@@ -0,0 +1,59 @@
+<& /SelfService/Elements/Header, Title => $SearchName &>
+
+<&| /Widgets/TitleBox, title => $SearchName &>
+<& /Elements/TicketList,
+ Title => $SearchName,
+ Format => $Format,
+ Query => $Query,
+ AllowSorting => 0,
+ Order => $Order,
+ OrderBy => $OrderBy,
+ BaseURL => $BaseURL,
+ Page => $Page &>
+</&>
+<%init>
+
+my $format;
+
+my $grp;
+if (defined $GroupName) {
+ my $groups = RT::Groups->new($session{'CurrentUser'});
+ $groups->LimitToUserDefinedGroups;
+ $groups->WithMember(PrincipalId => $session{'CurrentUser'}->Id,
+ Recursively => 1);
+ my $ref = $groups->ItemsArrayRef();
+ $grp = (grep { $_->Name eq $GroupName } @$ref)[0];
+} else {
+ $grp = $session{'CurrentUser'}->UserObj;
+}
+
+my $srch;
+if ($grp && defined $SearchName) {
+ my @attrs = $grp->Attributes->Named('SavedSearch');
+ $srch = (grep { $_->Description eq $SearchName } @attrs)[0];
+}
+
+# FIXME: if $srch is undefined, we're gonna have problems from here on
+
+if (not defined $Format) {
+ $Format = $srch->SubValue('Format');
+ $Format =~ s/%23/#/g;
+ $Format =~ s/%26/&/g;
+ $Format =~ s!/Ticket/Display\.html!/SelfService/Display.html!g;
+}
+$Query ||= $srch->SubValue('Query');
+$Rows ||= $srch->SubValue('RowsPerPage');
+$Order ||= $srch->SubValue('Order');
+$OrderBy ||= $srch->SubValue('OrderBy');
+</%init>
+<%ARGS>
+$GroupName => undef
+$SearchName => undef
+$Query => undef
+$Format => undef
+$Rows => undef
+$Order => undef
+$OrderBy => undef
+$Page => 1
+$BaseURL => undef
+</%ARGS>
diff --git a/html/SelfService/QueryList.html b/html/SelfService/QueryList.html
new file mode 100644
index 0000000..da0e14b
--- /dev/null
+++ b/html/SelfService/QueryList.html
@@ -0,0 +1,66 @@
+<& /SelfService/Elements/Header, Title => loc('Queries') &>
+
+<& /Elements/TitleBoxStart, title => loc('Queries') &>
+<table border="0" cellspacing="0" cellpadding="1" width="100%">
+
+% my $i=0;
+% foreach my $srch (@user_attrs) {
+% $m->out( '<TR class="' . ( $i % 2 ? 'oddline' : 'evenline' ) . '" >' );
+<td>
+% if ($srch->Id == $user_attrs[0]->Id) {
+My saved searches:
+% } else {
+
+% }
+</td>
+<td>
+<a href="Query.html?<% $m->comp('/Elements/QueryString',
+ SearchName => $srch->Description,
+ ) %>"><% $srch->Description %></a><br>
+</td>
+</tr>
+% $i++
+% }
+% for my $grp (@grouparr) {
+% my @gattrs = $grp->Attributes->Named('SavedSearch');
+% foreach my $srch (@gattrs) {
+% $m->out( '<TR class="' . ( $i % 2 ? 'oddline' : 'evenline' ) . '" >' );
+<td>
+% if ($srch->Id == $gattrs[0]->Id) {
+Group <% $grp->Name %> saved searches:
+% } else {
+
+% }
+</td>
+<td>
+<a href="Query.html?<% $m->comp('/Elements/QueryString',
+ GroupName => $grp->Name,
+ SearchName => $srch->Description,
+ ) %>"><% $srch->Description %></a><br>
+</td>
+</tr>
+% $i++
+% }
+% }
+</table>
+% if ($i == 0) {
+<p>Sorry, this feature is not available.</p>
+% }
+<& /Elements/TitleBoxEnd &>
+<%init>
+
+my @user_attrs = $session{'CurrentUser'}->UserObj->Attributes->Named('SavedSearch');
+
+# Get any group saved searches:
+my @attrs;
+my $groups = RT::Groups->new($session{'CurrentUser'});
+$groups->LimitToUserDefinedGroups;
+$groups->WithMember(PrincipalId => $session{'CurrentUser'}->Id,
+ Recursively => 1);
+my $ref = $groups->ItemsArrayRef();
+my @grouparr = @$ref;
+
+</%init>
+<%ARGS>
+$user_attrs => undef
+</%ARGS>
More information about the Rt-devel
mailing list