<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40"><head><meta http-equiv=Content-Type content="text/html; charset=utf-8"><meta name=Generator content="Microsoft Word 14 (filtered medium)"><style><!--
/* Font Definitions */
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Tahoma;
        panose-1:2 11 6 4 3 5 4 4 2 4;}
@font-face
        {font-family:Consolas;
        panose-1:2 11 6 9 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman","serif";
        color:black;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
pre
        {mso-style-priority:99;
        mso-style-link:"HTML Preformatted Char";
        margin:0cm;
        margin-bottom:.0001pt;
        font-size:10.0pt;
        font-family:"Courier New";
        color:black;}
p.MsoAcetate, li.MsoAcetate, div.MsoAcetate
        {mso-style-priority:99;
        mso-style-link:"Balloon Text Char";
        margin:0cm;
        margin-bottom:.0001pt;
        font-size:8.0pt;
        font-family:"Tahoma","sans-serif";
        color:black;}
span.HTMLPreformattedChar
        {mso-style-name:"HTML Preformatted Char";
        mso-style-priority:99;
        mso-style-link:"HTML Preformatted";
        font-family:Consolas;
        color:black;}
span.BalloonTextChar
        {mso-style-name:"Balloon Text Char";
        mso-style-priority:99;
        mso-style-link:"Balloon Text";
        font-family:"Tahoma","sans-serif";
        color:black;}
span.EmailStyle21
        {mso-style-type:personal-reply;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-size:10.0pt;}
@page WordSection1
        {size:612.0pt 792.0pt;
        margin:72.0pt 72.0pt 72.0pt 72.0pt;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]--></head><body bgcolor=white lang=EN-GB link=blue vlink=purple><div class=WordSection1><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>Thanks Seb!<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>Took me a while, I think I’m there now…<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>There was an important <o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>$r->handler('perl-script');<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>that needs to go before the<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>$r->set_handlers…<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>line.<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>I’ll get all this Wikified when I get back from my London/Paris bike ride :o)<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>Cheers,<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>John<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p><div><div style='border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0cm 0cm 0cm'><p class=MsoNormal><b><span lang=EN-US style='font-size:10.0pt;font-family:"Tahoma","sans-serif";color:windowtext'>From:</span></b><span lang=EN-US style='font-size:10.0pt;font-family:"Tahoma","sans-serif";color:windowtext'> eprints-tech-bounces@ecs.soton.ac.uk [mailto:eprints-tech-bounces@ecs.soton.ac.uk] <b>On Behalf Of </b>Sebastien Francois<br><b>Sent:</b> 17 July 2014 14:14<br><b>To:</b> eprints-tech@ecs.soton.ac.uk<br><b>Subject:</b> [EP-tech] Re: EP_TRIGGER_URL_REWRITE and redirecting to a screen<o:p></o:p></span></p></div></div><p class=MsoNormal><o:p> </o:p></p><div><p class=MsoNormal>Hola,<br><br>I think you can pass on the ScreenProcessor / a Screen from your trigger.<br><br>Something like:<br><br><o:p></o:p></p><pre>$c->add_trigger( EP_TRIGGER_URL_REWRITE, sub<o:p></o:p></pre><pre>{<o:p></o:p></pre><pre> my( %args ) = @_;<o:p></o:p></pre><pre><o:p> </o:p></pre><pre> my( $repository, $uri, $return_code, $request ) = @args{ qw( repository uri return_code request ) };<o:p></o:p></pre><pre> if( defined $uri && ($uri =~ m# ^/(\d+)/$ #x ) )<o:p></o:p></pre><pre> {<o:p></o:p></pre><pre> my $eprintid = $1;<o:p></o:p></pre><pre> my $eprint = $repository->dataset( "eprint" )->dataobj( $eprintid );<o:p></o:p></pre><pre> # this is an overridden 'permit' that does some new things, but still returns a '1' or '0'.<o:p></o:p></pre><pre> my $can_view = $eprint->permit( "eprint/view", $repository->current_user ); #NB current_user may be undef<o:p></o:p></pre><pre> if( $can_view ){<o:p></o:p></pre><pre><o:p> </o:p></pre><pre> $r->set_handlers( PerlResponseHandler => sub {<o:p></o:p></pre><pre><o:p> </o:p></pre><pre> my( $r ) = @_; # if needed<o:p></o:p></pre><pre> my $repository = $EPrints::HANDLE->current_repository; # if needed<o:p></o:p></pre><pre> EPrints::ScreenProcessor->process(<o:p></o:p></pre><pre> repository => $repository,<o:p></o:p></pre><pre> screenid => "YourScreenID",<o:p></o:p></pre><pre> <o:p></o:p></pre><pre> # ... whatever other params your Screen needs ....<o:p></o:p></pre><pre> );<o:p></o:p></pre><pre><o:p> </o:p></pre><pre> return HTTP_OK;<o:p></o:p></pre><pre><o:p> </o:p></pre><pre> } );<o:p></o:p></pre><pre><o:p> </o:p></pre><pre> $$return_code = EPrints::Const::OK;<o:p></o:p></pre><pre> return EP_TRIGGER_DONE;<o:p></o:p></pre><pre><o:p> </o:p></pre><pre> }<o:p></o:p></pre><pre> }<o:p></o:p></pre><pre> return EP_TRIGGER_OK;<o:p></o:p></pre><pre><o:p> </o:p></pre><pre>}, priority => 100 ); <o:p></o:p></pre><p class=MsoNormal><br>Alternatively, you can have an actual Perl Response Handler, you can use as templates:<br><br>- <a href="http://bazaar.eprints.org/325/1/epm/meprints/cfg/cfg.d/z_meprints.pl">http://bazaar.eprints.org/325/1/epm/meprints/cfg/cfg.d/z_meprints.pl</a> (search for EP_TRIGGER_URL_REWRITE)<br>- <a href="http://bazaar.eprints.org/325/1/plugins/EPrints/Plugin/MePrints/MePrintsHandler.pm">http://bazaar.eprints.org/325/1/plugins/EPrints/Plugin/MePrints/MePrintsHandler.pm</a> (the handler can do whatever you want, you can print the page to STDOUT, or let the ScreenProcessor do that for you).<br><br>And just, as a small add-on, on some ACL work I was looking at, my main method was called permit_action (on DataObj) and you pass the action as a param so that it looks like:<br><br>my $rc = $dataobj->permit_action( "view", $current_user ); # current_user may be undef too<br><br>Hope this helps,<br>Seb.<br><br><br><br>On 17/07/14 13:45, Enio Carboni wrote:<o:p></o:p></p></div><blockquote style='margin-top:5.0pt;margin-bottom:5.0pt'><div><p class=MsoNormal style='margin-bottom:12.0pt'>Hi John,<br> I think you must use something like this in your EP_TRIGGER_URL_REWRITE (this trigger, i think, can't control direct "render a screen"):<o:p></o:p></p><p class=MsoNormal>my $url="your_url_to_redirect_this_call_i_think_to_screen_EPrint::SecureSummary_plus_args";<br>EPrints::Apache::AnApache::send_status_line( $args{request}, 307, "Temporary Redirect" );<br>EPrints::Apache::AnApache::header_out( $args{request}, "Location", $url );<br>EPrints::Apache::AnApache::send_http_header( $args{request} );<br>${$args{return_code}} = EPrints::Apache::AnApache::DONE;<br>return EP_TRIGGER_DONE;<o:p></o:p></p><p class=MsoNormal><br> Enio<br><br><br>Il 17/07/2014 13:43, John Salter ha scritto:<o:p></o:p></p></div><blockquote style='margin-top:5.0pt;margin-bottom:5.0pt'><pre>Hi Seb,<o:p></o:p></pre><pre>Thanks for the reply, sorry for the delay in getting back to you.<o:p></o:p></pre><pre><o:p> </o:p></pre><pre>I'm still not sure I understand how to get where I need to be - here's what I'm trying to do:<o:p></o:p></pre><pre> - intercept a request for an EPrint - the rewrite trigger matches a URL e.g. <a href="http://repo/123/">http://repo/123/</a> with '^/(\d+)/$'. *<o:p></o:p></pre><pre> - check (with the new Access Control stuff we're working on :o) whether the request can view the item**<o:p></o:p></pre><pre> - if the request is permitted to view, render a variant of the EPrint::Summary screen, EPrint::SecureSummary<o:p></o:p></pre><pre> - if it can't, let EPrints do it's normal thing - which in this case will direct to a summary page with minimal metadata.<o:p></o:p></pre><pre><o:p> </o:p></pre><pre>* I don’t want to redirect from <a href="http://repo/123/">http://repo/123/</a> to <a href="http://repo/cgi/">http://repo/cgi/</a>[something],<o:p></o:p></pre><pre>**There may not be a 'user' at this point in time - there could be an IP-based 'allow'.<o:p></o:p></pre><pre><o:p> </o:p></pre><pre>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...<o:p></o:p></pre><pre><o:p> </o:p></pre><pre>$c->add_trigger( EP_TRIGGER_URL_REWRITE, sub<o:p></o:p></pre><pre>{<o:p></o:p></pre><pre> my( %args ) = @_;<o:p></o:p></pre><pre><o:p> </o:p></pre><pre> my( $repository, $uri, $return_code, $request ) = @args{ qw( repository uri return_code request ) };<o:p></o:p></pre><pre> if( defined $uri && ($uri =~ m# ^/(\d+)/$ #x ) )<o:p></o:p></pre><pre> {<o:p></o:p></pre><pre> my $eprintid = $1;<o:p></o:p></pre><pre> my $eprint = $repository->dataset( "eprint" )->dataobj( $eprintid );<o:p></o:p></pre><pre> # this is an overridden 'permit' that does some new things, but still returns a '1' or '0'.<o:p></o:p></pre><pre> my $can_view = $eprint->permit( "eprint/view", $repository->current_user ); #NB current_user may be undef<o:p></o:p></pre><pre> if( $can_view ){<o:p></o:p></pre><pre> #render the EPrint::SecureSummary screen<o:p></o:p></pre><pre> #and set the return code?<o:p></o:p></pre><pre> # ${$return_code} = EPrints::Const::OK;<o:p></o:p></pre><pre> #return EP_TRIGGER_DONE;<o:p></o:p></pre><pre> }<o:p></o:p></pre><pre> }<o:p></o:p></pre><pre> return EP_TRIGGER_OK;<o:p></o:p></pre><pre><o:p> </o:p></pre><pre>}, priority => 100 ); <o:p></o:p></pre><pre><o:p> </o:p></pre><pre>Any (further) thoughts welcomed!<o:p></o:p></pre><pre>Cheers,<o:p></o:p></pre><pre>John<o:p></o:p></pre><pre><o:p> </o:p></pre><pre><o:p> </o:p></pre><pre>-----Original Message-----<o:p></o:p></pre><pre>From: <a href="mailto:eprints-tech-bounces@ecs.soton.ac.uk">eprints-tech-bounces@ecs.soton.ac.uk</a> [<a href="mailto:eprints-tech-bounces@ecs.soton.ac.uk">mailto:eprints-tech-bounces@ecs.soton.ac.uk</a>] On Behalf Of Sebastien Francois<o:p></o:p></pre><pre>Sent: 11 July 2014 11:37<o:p></o:p></pre><pre>To: <a href="mailto:eprints-tech@ecs.soton.ac.uk">eprints-tech@ecs.soton.ac.uk</a><o:p></o:p></pre><pre>Subject: [EP-tech] Re: EP_TRIGGER_URL_REWRITE and redirecting to a screen<o:p></o:p></pre><pre><o:p> </o:p></pre><pre>Hi John,<o:p></o:p></pre><pre><o:p> </o:p></pre><pre>I don't think that case (1) redirects - see eprints3/cgi/users/home. It <o:p></o:p></pre><pre>just passes on the request to the ScreenProcessor. You could achieve the <o:p></o:p></pre><pre>same with a trigger in fact.<o:p></o:p></pre><pre><o:p> </o:p></pre><pre>Since your screen already has a url <o:p></o:p></pre><pre>(<a href="http://repo/cgi/users/home?screen=MyScreen">http://repo/cgi/users/home?screen=MyScreen</a>), I guess what you want to <o:p></o:p></pre><pre>do is a rewrite as in mod_rewrite.<o:p></o:p></pre><pre><o:p> </o:p></pre><pre>Seb.<o:p></o:p></pre><pre><o:p> </o:p></pre><pre>On 11/07/14 11:16, John Salter wrote:<o:p></o:p></pre><blockquote style='margin-top:5.0pt;margin-bottom:5.0pt'><pre>Hi,<o:p></o:p></pre><pre>What's the *best/intended* way to go from an EP_TRIGGER_URL_REWRITE trigger to a screen?<o:p></o:p></pre><pre><o:p> </o:p></pre><pre>>From searching the Bazaar, is seems like most things like this either:<o:p></o:p></pre><pre>(1) use a cgi/... script that does the screen selection/processing, or<o:p></o:p></pre><pre>(2) register a handler that does the work (e.g. $request->set_handlers(PerlResponseHandler => [ 'EPrints::Plugin::MePrints::MePrintsHandler' ] ); )<o:p></o:p></pre><pre><o:p> </o:p></pre><pre>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).<o:p></o:p></pre><pre><o:p> </o:p></pre><pre>Should the trigger should be able to do the work?<o:p></o:p></pre><pre>Have I missed some magic way of doing this?<o:p></o:p></pre><pre><o:p> </o:p></pre><pre>Cheers,<o:p></o:p></pre><pre>John<o:p></o:p></pre><pre><o:p> </o:p></pre><pre><o:p> </o:p></pre><pre><o:p> </o:p></pre><pre>*** Options: <a href="http://mailman.ecs.soton.ac.uk/mailman/listinfo/eprints-tech">http://mailman.ecs.soton.ac.uk/mailman/listinfo/eprints-tech</a><o:p></o:p></pre><pre>*** Archive: <a href="http://www.eprints.org/tech.php/">http://www.eprints.org/tech.php/</a><o:p></o:p></pre><pre>*** EPrints community wiki: <a href="http://wiki.eprints.org/">http://wiki.eprints.org/</a><o:p></o:p></pre><pre>*** EPrints developers Forum: <a href="http://forum.eprints.org/">http://forum.eprints.org/</a><o:p></o:p></pre></blockquote><pre>*** Options: <a href="http://mailman.ecs.soton.ac.uk/mailman/listinfo/eprints-tech">http://mailman.ecs.soton.ac.uk/mailman/listinfo/eprints-tech</a><o:p></o:p></pre><pre>*** Archive: <a href="http://www.eprints.org/tech.php/">http://www.eprints.org/tech.php/</a><o:p></o:p></pre><pre>*** EPrints community wiki: <a href="http://wiki.eprints.org/">http://wiki.eprints.org/</a><o:p></o:p></pre><pre>*** EPrints developers Forum: <a href="http://forum.eprints.org/">http://forum.eprints.org/</a><o:p></o:p></pre><pre><o:p> </o:p></pre><pre>*** Options: <a href="http://mailman.ecs.soton.ac.uk/mailman/listinfo/eprints-tech">http://mailman.ecs.soton.ac.uk/mailman/listinfo/eprints-tech</a><o:p></o:p></pre><pre>*** Archive: <a href="http://www.eprints.org/tech.php/">http://www.eprints.org/tech.php/</a><o:p></o:p></pre><pre>*** EPrints community wiki: <a href="http://wiki.eprints.org/">http://wiki.eprints.org/</a><o:p></o:p></pre><pre>*** EPrints developers Forum: <a href="http://forum.eprints.org/">http://forum.eprints.org/</a><o:p></o:p></pre></blockquote><p class=MsoNormal><br><br><br><br><o:p></o:p></p><pre>*** Options: <a href="http://mailman.ecs.soton.ac.uk/mailman/listinfo/eprints-tech">http://mailman.ecs.soton.ac.uk/mailman/listinfo/eprints-tech</a><o:p></o:p></pre><pre>*** Archive: <a href="http://www.eprints.org/tech.php/">http://www.eprints.org/tech.php/</a><o:p></o:p></pre><pre>*** EPrints community wiki: <a href="http://wiki.eprints.org/">http://wiki.eprints.org/</a><o:p></o:p></pre><pre>*** EPrints developers Forum: <a href="http://forum.eprints.org/">http://forum.eprints.org/</a><o:p></o:p></pre></blockquote><p class=MsoNormal><o:p> </o:p></p></div></body></html>