From 8506ea93e1d162d61735f05fa3e748df8235c0d6 Mon Sep 17 00:00:00 2001 From: Marco Pessotto Date: Thu, 10 Oct 2024 07:44:43 +0200 Subject: [PATCH] Add second button for BB token loading --- lib/AmuseWikiFarm/Controller/BookBuilder.pm | 42 ++++++++++++--------- root/src/bookbuilder/index.tt | 5 +++ t/authentication.t | 5 ++- 3 files changed, 33 insertions(+), 19 deletions(-) diff --git a/lib/AmuseWikiFarm/Controller/BookBuilder.pm b/lib/AmuseWikiFarm/Controller/BookBuilder.pm index 9ab38405..0fc0102a 100644 --- a/lib/AmuseWikiFarm/Controller/BookBuilder.pm +++ b/lib/AmuseWikiFarm/Controller/BookBuilder.pm @@ -29,7 +29,7 @@ Deny access to not-human =cut -sub start_new_session :Chained('/site_human_required') :PathPart('bookbuild-new-session') :Args(0) { +sub start_new_session :Chained('/site_human_required') :PathPart('bookbuilder-new-session') :Args(0) { my ($self, $c) = @_; delete $c->session->{bookbuilder}; delete $c->session->{bookbuilder_token}; @@ -37,6 +37,30 @@ sub start_new_session :Chained('/site_human_required') :PathPart('bookbuild-new- $c->response->redirect($c->uri_for_action('/bookbuilder/index')); } +sub load :Chained('/site_human_required') :PathPart('bookbuilder-load-token') :Args(0) { + my ( $self, $c ) = @_; + my $ok; + if (my $token = $c->request->body_parameters->{token}) { + if ($c->request->body_parameters->{replace}) { + # log_info { "Starting new BB session" }; + delete $c->session->{bookbuilder}; + delete $c->session->{bookbuilder_token}; + } + my $bb = $c->model('BookBuilder'); + if (my $newbb = $bb->load_from_token("$token")) { + $c->stash(bb => $newbb); + $self->save_session($c); + $ok = 1; + } + } + unless ($ok) { + $c->flash->{error_msg} = $c->loc('Unable to load the bookbuilder session'); + } + $c->response->redirect($c->uri_for_action('/bookbuilder/index')); +} + + + sub root :Chained('/site_human_required') :PathPart('bookbuilder') :CaptureArgs(0) { my ( $self, $c ) = @_; @@ -379,22 +403,6 @@ sub schemas :Chained('root') :PathPart('schemas') :Args(0) { $c->stash(page_title => $c->loc('Imposition schemas')); } -sub load :Chained('root') :Args(0) { - my ( $self, $c ) = @_; - my $ok; - if (my $token = $c->request->body_parameters->{token}) { - if (my $bb = $c->stash->{bb}->load_from_token($token . '')) { - $c->stash(bb => $bb); - $self->save_session($c); - $ok = 1; - } - } - unless ($ok) { - $c->flash->{error_msg} = $c->loc('Unable to load the bookbuilder session'); - } - $c->response->redirect($c->uri_for_action('/bookbuilder/index')); -} - # no tests here, seems pretty straightforward sub from_custom_format :Chained('root') :PathPart('from-custom-format') :Args(1) { my ($self, $c, $cf_code) = @_; diff --git a/root/src/bookbuilder/index.tt b/root/src/bookbuilder/index.tt index e994a41c..04c83196 100644 --- a/root/src/bookbuilder/index.tt +++ b/root/src/bookbuilder/index.tt @@ -436,6 +436,11 @@ placeholder="[% loc('Load another session by token') %]" /> + diff --git a/t/authentication.t b/t/authentication.t index 83312d73..9f17254d 100644 --- a/t/authentication.t +++ b/t/authentication.t @@ -13,7 +13,7 @@ use Text::Amuse::Compile::Utils qw/write_file/; use AmuseWiki::Tests qw/create_site/; use AmuseWikiFarm::Schema; use Test::WWW::Mechanize::Catalyst; -use Test::More tests => 2463; # test spamming +use Test::More tests => 2483; # test spamming my $schema = AmuseWikiFarm::Schema->connect('amuse'); my $site = create_site($schema, '0authen0'); @@ -118,7 +118,8 @@ my @human_only = ( '/bookbuilder/edit', '/bookbuilder/fonts', '/bookbuilder', - '/bookbuilder/load', + '/bookbuilder-load-token', + '/bookbuilder-new-session', '/bookbuilder/profile/1', '/bookbuilder/schemas', # job number