[EP-tech] Re: EP_TRIGGER_URL_REWRITE and redirecting to a screen
John Salter
J.Salter at leeds.ac.uk
Thu Jul 17 12:43:56 BST 2014
Hi Seb,
Thanks for the reply, sorry for the delay in getting back to you.
I'm still not sure I understand how to get where I need to be - here's what I'm trying to do:
- intercept a request for an EPrint - the rewrite trigger matches a URL e.g. http://repo/123/ with '^/(\d+)/$'. *
- check (with the new Access Control stuff we're working on :o) whether the request can view the item**
- if the request is permitted to view, render a variant of the EPrint::Summary screen, EPrint::SecureSummary
- if it can't, let EPrints do it's normal thing - which in this case will direct to a summary page with minimal metadata.
* I don’t want to redirect from http://repo/123/ to http://repo/cgi/[something],
**There may not be a 'user' at this point in time - there could be an IP-based 'allow'.
Below is what I've got so far for my trigger - I've tried various things - either resulting in a login page, a 404 error or a smoking server...
$c->add_trigger( EP_TRIGGER_URL_REWRITE, sub
{
my( %args ) = @_;
my( $repository, $uri, $return_code, $request ) = @args{ qw( repository uri return_code request ) };
if( defined $uri && ($uri =~ m# ^/(\d+)/$ #x ) )
{
my $eprintid = $1;
my $eprint = $repository->dataset( "eprint" )->dataobj( $eprintid );
# this is an overridden 'permit' that does some new things, but still returns a '1' or '0'.
my $can_view = $eprint->permit( "eprint/view", $repository->current_user ); #NB current_user may be undef
if( $can_view ){
#render the EPrint::SecureSummary screen
#and set the return code?
# ${$return_code} = EPrints::Const::OK;
#return EP_TRIGGER_DONE;
}
}
return EP_TRIGGER_OK;
}, priority => 100 );
Any (further) thoughts welcomed!
Cheers,
John
-----Original Message-----
From: eprints-tech-bounces at ecs.soton.ac.uk [mailto:eprints-tech-bounces at ecs.soton.ac.uk] On Behalf Of Sebastien Francois
Sent: 11 July 2014 11:37
To: eprints-tech at ecs.soton.ac.uk
Subject: [EP-tech] Re: EP_TRIGGER_URL_REWRITE and redirecting to a screen
Hi John,
I don't think that case (1) redirects - see eprints3/cgi/users/home. It
just passes on the request to the ScreenProcessor. You could achieve the
same with a trigger in fact.
Since your screen already has a url
(http://repo/cgi/users/home?screen=MyScreen), I guess what you want to
do is a rewrite as in mod_rewrite.
Seb.
On 11/07/14 11:16, John Salter wrote:
> Hi,
> What's the *best/intended* way to go from an EP_TRIGGER_URL_REWRITE trigger to a screen?
>
> >From searching the Bazaar, is seems like most things like this either:
> (1) use a cgi/... script that does the screen selection/processing, or
> (2) register a handler that does the work (e.g. $request->set_handlers(PerlResponseHandler => [ 'EPrints::Plugin::MePrints::MePrintsHandler' ] ); )
>
> Both seem not-quite-right: (1) requires the trigger to do a redirect (another HTTP call), (2) would duplicate a lot of stuff that EPrints does 'normally' (the screen I want to use is a normal EPrints screen).
>
> Should the trigger should be able to do the work?
> Have I missed some magic way of doing this?
>
> Cheers,
> John
>
>
>
> *** Options: http://mailman.ecs.soton.ac.uk/mailman/listinfo/eprints-tech
> *** Archive: http://www.eprints.org/tech.php/
> *** EPrints community wiki: http://wiki.eprints.org/
> *** EPrints developers Forum: http://forum.eprints.org/
*** Options: http://mailman.ecs.soton.ac.uk/mailman/listinfo/eprints-tech
*** Archive: http://www.eprints.org/tech.php/
*** EPrints community wiki: http://wiki.eprints.org/
*** EPrints developers Forum: http://forum.eprints.org/
More information about the Eprints-tech
mailing list