Skip to content
This repository has been archived by the owner on Aug 16, 2023. It is now read-only.

Commit

Permalink
First working draft
Browse files Browse the repository at this point in the history
  • Loading branch information
a-j-wood committed Aug 26, 2021
1 parent af29734 commit bb95ef0
Show file tree
Hide file tree
Showing 6 changed files with 548 additions and 21 deletions.
2 changes: 1 addition & 1 deletion Changes
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Revision history for RT-Extension-ShareSearchLink

0.01 [Release Date]
0.01 Thu Aug 26 2021
- Initial version
2 changes: 2 additions & 0 deletions Makefile.PL
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use lib '.';
use inc::Module::Install;

perl_version 5.6;

RTx 'RT-Extension-ShareSearchLink';
license 'gpl_2';
repository 'https://github.com/a-j-wood/rt-extension-sharesearchlink';
Expand Down
115 changes: 108 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,112 @@
# RT::Extension::ShareSearchLink
# NAME

This extension adds a "*Share a link*" item to the *Tools* menu on the
search results page, and a similar button at the bottom of the search
results.
RT-Extension-ShareSearchLink - Shorter links for ticket searches

The "*Share a link*" menu item or button will show a pop-up box containing
a short link to this search, with all the search terms and formatting stored
in a database entry in RT.
# DESCRIPTION

This extension adds a "_Share_" item to the menu on the search results
page, and a "_Share a link_" button to the bottom of the results.

Both of these will show a pop-up box containing a short link to the current
search, with all the search terms and formatting stored in a database entry
in RT.

This is useful when your search URL is very long.

# RT VERSION

Known to work with RT 5.0.1 and 4.2.16.

# REQUIREMENTS

Requires `Data::GUID`.

# INSTALLATION

- `perl Makefile.PL`
- `make`
- `make install`

May need root permissions.

- Set up the database

After running `make install` for the first time, you will need to create
the database table for this extension, using the file `etc/dbsetup.sql`.

- Edit your `/opt/rt4/etc/RT_SiteConfig.pm`

Add this line:

Plugin('RT::Extension::ShareSearchLink');

- Clear your mason cache

rm -rf /opt/rt4/var/mason_data/obj

- Restart your web server
- Set up database pruning

Add a cron job similar to the ones you will already have for other RT
maintenance jobs like `rt-email-dashboards` to clear down expired shared
search links, like this:

4 4 * * * root /opt/rt4/bin/rt-crontool --search RT::Extension::ShareSearchLink --action RT::Extension::ShareSearchLink

This way, shared search links will expire 90 days after they have last been
viewed, and will expire within 7 days of creation if they aren't viewed at
least twice in that time.

# AUTHOR

Andrew Wood

<div>
<p>All bugs should be reported via email to <a
href="mailto:[email protected]">[email protected]</a>
or via the web at <a
href="http://rt.cpan.org/Public/Dist/Display.html?Name=RT-Extension-ShareSearchLink">rt.cpan.org</a>.</p>
</div>

# LICENSE AND COPYRIGHT

This software is Copyright (c) 2021 by Andrew Wood

This is free software, licensed under:

The GNU General Public License, Version 2, June 1991

# Internal package RT::ShareSearchLink::SharedSearchLink

This package provides the shared search link object.

## Create Parameters => { ... }, \[ UUID => 'xxx' \]

Creates a new shared search link for a search with the given parameters, and
returns (_$id_, _$message_). If a _UUID_ is not supplied, a new one is
generated.

## Load $id|$UUID

Load a shared search link by numeric ID or by string UUID, returning the
numeric ID or undef.

## Delete

Delete this shared search link from the database.

## Parameters

Return a hash of the parameters stored in this shared search link.

## AddView

Increment the view counter for this shared search link, and set its last viewed date.

## \_CoreAccessible

Private method which defines the columns in the database table.

# Internal package RT::ShareSearchLink::SharedSearchLinks

This package provides the group class for shared search links.
17 changes: 16 additions & 1 deletion html/Callbacks/ShareSearchLinks/Search/Results.html/AfterResults
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,26 @@ function ShareSearchLink () {
dataType: 'html',
data: jQuery('#ShareSearchLinkForm').serialize(),
success: function (html) {
\
%# We remove the loading message and append the new content, rather than
%# replacing all the HTML, because in RT 4.2.16 if we do that we lose the
%# modal dialog's close icon.
%#
modal.find('.transient-loading-message').remove();
modal.append(jQuery(html));
\
%# The button in the HTML we've just loaded has an href containing a
%# relative URL. We create a new "a" tag, set its "href", and clone it,
%# because reading the cloned tag's "href" attribute gives us the full
%# canonical URL.
var a = document.createElement('a');
a.href = jQuery('#NewShareSearchLink').attr('href');
jQuery('#NewShareSearchLinkInput').val(a.cloneNode(false).href);
var fullURL = a.cloneNode(false).href;
\
%# Now we can put the full URL of the shared search link into the text box
%# for the user to cut and paste.
%#
jQuery('#NewShareSearchLinkInput').val(fullURL);
},
});
return false;
Expand Down
4 changes: 2 additions & 2 deletions html/Helpers/ShareSearchLinks
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ if ( not $id ) {
<h5 class="modal-title"><&|/l&>Share a link</&></h5>
\
% # This just shows up as "x" on RT 4.2.16 and that version shows a close
% # button already anyway.
% # button already anyway, so only output this in versions above 4.x.
% #
% if ($RT::MAJOR_VERSION > 4) {
<a href="javascript:void(0)" class="close" data-dismiss="modal" aria-label="Close">
Expand All @@ -56,7 +56,7 @@ if ( not $id ) {
<&|/l&>Sharing this link with other RT users will allow them to load the same search parameters you have used here.</&>
</p>
<p style="text-align:center;">
<a class="button btn" id="NewShareSearchLink" href="<%RT->Config->Get('WebPath')%>/Search/ShareSearchLink.html?id=<%$SharedSearchLink->UUID|u%>" class="btn button"><&|/l&>Shared search link</&></a>
<a class="button btn" id="NewShareSearchLink" target="_blank" href="<%RT->Config->Get('WebPath')%>/Search/ShareSearchLink.html?id=<%$SharedSearchLink->UUID|u%>" class="btn button"><&|/l&>Shared search link</&></a>
</p>
<p style="text-align:center;">
<button type="button" title="<&|/l&>Copy</&>" onclick="CopyNewSharedSearchLink()">&#x1f4cb;</button>
Expand Down
Loading

0 comments on commit bb95ef0

Please sign in to comment.