EPrints Technical Mailing List Archive

See the EPrints wiki for instructions on how to join this mailing list and related information.

Message: #03293


< Previous (by date) | Next (by date) > | < Previous (in thread) | Next (in thread) > | Messages - Most Recent First | Threads - Most Recent First

[EP-tech] Re: EP_TRIGGER_URL_REWRITE and redirecting to a screen


Thanks Seb!

Took me a while, I think I’m there now…

There was an important

$r->handler('perl-script');

that needs to go before the

$r->set_handlers…

line.

 

I’ll get all this Wikified when I get back from my London/Paris bike ride :o)

Cheers,

John

 

 

From: eprints-tech-bounces@ecs.soton.ac.uk [mailto:eprints-tech-bounces@ecs.soton.ac.uk] On Behalf Of Sebastien Francois
Sent: 17 July 2014 14:14
To: eprints-tech@ecs.soton.ac.uk
Subject: [EP-tech] Re: EP_TRIGGER_URL_REWRITE and redirecting to a screen

 

Hola,

I think you can pass on the ScreenProcessor / a Screen from your trigger.

Something like:

$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 ){
 
                       $r->set_handlers( PerlResponseHandler => sub {
 
                               my( $r ) = @_;                                        # if needed
                               my $repository = $EPrints::HANDLE->current_repository;       # if needed
                               EPrints::ScreenProcessor->process(
                                      repository => $repository,
                                       screenid => "YourScreenID",
        
                                      # ... whatever other params your Screen needs ....
                               );
 
                               return HTTP_OK;
 
                       } );
 
                       $$return_code = EPrints::Const::OK;
                       return EP_TRIGGER_DONE;
 
                }
        }
        return EP_TRIGGER_OK;
 
}, priority => 100 ); 


Alternatively, you can have an actual Perl Response Handler, you can use as templates:

- http://bazaar.eprints.org/325/1/epm/meprints/cfg/cfg.d/z_meprints.pl (search for EP_TRIGGER_URL_REWRITE)
- http://bazaar.eprints.org/325/1/plugins/EPrints/Plugin/MePrints/MePrintsHandler.pm (the handler can do whatever you want, you can print the page to STDOUT, or let the ScreenProcessor do that for you).

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:

my $rc = $dataobj->permit_action( "view", $current_user );        # current_user may be undef too

Hope this helps,
Seb.



On 17/07/14 13:45, Enio Carboni wrote:

Hi John,
 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"):

my $url="">EPrints::Apache::AnApache::send_status_line( $args{request}, 307, "Temporary Redirect" );
EPrints::Apache::AnApache::header_out( $args{request}, "Location", $url );
EPrints::Apache::AnApache::send_http_header( $args{request} );
${$args{return_code}} = EPrints::Apache::AnApache::DONE;
return EP_TRIGGER_DONE;


  Enio


Il 17/07/2014 13:43, John Salter ha scritto:

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@ecs.soton.ac.uk [mailto:eprints-tech-bounces@ecs.soton.ac.uk] On Behalf Of Sebastien Francois
Sent: 11 July 2014 11:37
To: eprints-tech@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/
 
*** 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/