Skip to content

Commit

Permalink
Add second button for BB token loading
Browse files Browse the repository at this point in the history
  • Loading branch information
melmothx committed Oct 10, 2024
1 parent 33e685b commit 8506ea9
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 19 deletions.
42 changes: 25 additions & 17 deletions lib/AmuseWikiFarm/Controller/BookBuilder.pm
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,38 @@ 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};
$c->flash->{status_msg} = $c->loc('Started new bookbuilder session');
$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 ) = @_;

Expand Down Expand Up @@ -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) = @_;
Expand Down
5 changes: 5 additions & 0 deletions root/src/bookbuilder/index.tt
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,11 @@
placeholder="[% loc('Load another session by token') %]" />
<span class="input-group-btn">
<button class="btn btn-default" type="submit" name="load" value="1">
[% loc('Load adding texts') %]
<span class="fa fa-folder-open-o"></span>
</button>
<button class="btn btn-default" type="submit" name="replace" value="1">
[% loc('Load replacing texts') %]
<span class="fa fa-folder-open-o"></span>
</button>
</span>
Expand Down
5 changes: 3 additions & 2 deletions t/authentication.t
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 8506ea9

Please sign in to comment.