From 4ecb8e32af8b152817108c51324ce0f576c90173 Mon Sep 17 00:00:00 2001 From: Alex Buckley Date: Mon, 2 Oct 2017 17:51:16 +1300 Subject: [PATCH] Bug 19384 - Ability to skip the onboarding tool and then redirect the next user to it To allow IT staff and support vendors to quickly install Koha for clients this patch allows these people to skip the onboarding tool and go straight from the web installer to authenticating to the intranet. As well as allowing these users to install Koha quickly, the other purpose of this patch is that these people are unlikely to know what the library wants set as the library, patron category, administrator patron credentials, item type and circulation rule and so it is better to leave that to a librarian to fill out. The next user to log in (they will have to use the Koha db administrator credentials) after Koha has been installed (and only if the onboarding tool was skipped) is then redirected to login to the web installer to go through the onboarding tool. Test plan: 1. Drop and recreate your Koha database 2. Restart memcached 3. Go through the web installer and notice that on the page which says congradulations that you have successfully installed Koha there is a link to click to load the onboarding tool otherwise if you wait 10 seconds you are redirected anyway. 4. Apply patch 5. Repeat steps 1 and 2 6. Go through the web installer without installing sample patrons and notice on the same page described in step 3 there are now 2 links: one to go to the onboarding tool and one to skip the onboarding process. Also notice that if you wait 10 seconds you are not redirected to the onboarding tool. 7. Click the skip link 8. Notice the intranet login page appears, login using the Koha db adminstrator credentials and notice that the mainpage appears. 9. Now logout and login again and notice that you are redirected to the Web installer login page, login and notice that the onboarding tool is displayed 10. Repeat steps 1 and 2 and this time install sample data including sample patrons 11. On the page described on step 3 click the skip link. 12. Notice that the intranet login page appears, login and then logout 13. Try logging in again and notice that you are redirected to the web installer login page and after authenticating the onboarding tool is displayed. 14. Repeat steps 1 and 2 go through the web installer and on the page described in step 3 click the onboarding link and notice that a page from the onboarding process is displayed. 15. Aftergoing through the onboarding tool login as db administrator and then logout and login again and notice that you are not redirected to the onboarding tool because you have already completed it Sponsored-By: Catalyst IT https://bugs.koha-community.org/show_bug.cgi?id=19394 --- C4/Auth.pm | 17 +++++++++++++++++ Koha/Patron.pm | 19 +++++++++++++++++++ installer/data/mysql/kohastructure.sql | 1 + installer/onboarding.pl | 2 +- .../intranet-tmpl/prog/en/modules/installer/step3.tt | 7 ++----- mainpage.pl | 15 ++++++++++++++- 6 files changed, 54 insertions(+), 7 deletions(-) diff --git a/C4/Auth.pm b/C4/Auth.pm index d22e935..a74a6f1 100644 --- a/C4/Auth.pm +++ b/C4/Auth.pm @@ -2029,6 +2029,23 @@ sub get_all_subpermissions { return $all_perms; } +=head2 check_onboarding_required + +my $onboardingrequired = C4::Auth->check_onboarding_required(); + +Returns 1 from the userflags table if the authenticating user is required to go through the onboarding process. The 'onboardingrequired' field is set in the mainpage.pl + +=cut + +sub check_onboarding_required { + my $dbh = C4::Context->dbh; + my $sth = $dbh->prepare(" + SELECT onboardingrequired FROM userflags WHERE bit = 0"); + $sth->execute(); + my $onboardingrequired = $sth->fetchrow(); + return $onboardingrequired; +} + =head2 haspermission $flags = ($userid, $flagsrequired); diff --git a/Koha/Patron.pm b/Koha/Patron.pm index daa972c..46fb1b7 100644 --- a/Koha/Patron.pm +++ b/Koha/Patron.pm @@ -638,6 +638,25 @@ sub get_enrollable_clubs { return wantarray ? $e->as_list : $e; } +=head3 check_if_patrons_have_flags + +my $patron_has_flag = Koha::Patron->check_if_patrons_have_flags (); + +All sample patrons that can optionally be installed whilst running the Koha web installer have the flag value of NULL, this subroutine checks if any borrower records in the borrowers table contain a number, and so this means that they must have been manually added. If there is a numberical flag returned then this subroutine will return a 1 to mainpage.pl script to ensure that users are appropriately redirected to the onboarding tool +=cut + +sub check_if_patrons_have_flags { + my $dbh = C4::Context->dbh; + my $sth = $dbh->prepare(" + select * from borrowers where flags != 'NULL'"); + $sth->execute(); + my $no_patrons_with_flags; + if ( $sth->rows ) { + $no_patrons_with_flags = 1; + } + return $no_patrons_with_flags; +} + =head3 account_locked my $is_locked = $patron->account_locked diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql index 2edd371..6b45dd1 100644 --- a/installer/data/mysql/kohastructure.sql +++ b/installer/data/mysql/kohastructure.sql @@ -2255,6 +2255,7 @@ CREATE TABLE `userflags` ( `flag` varchar(30) default NULL, `flagdesc` varchar(255) default NULL, `defaulton` int(11) default NULL, + `onboardingrequired` int(1) default NULL, PRIMARY KEY (`bit`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; diff --git a/installer/onboarding.pl b/installer/onboarding.pl index 8b032c9..abb195d 100755 --- a/installer/onboarding.pl +++ b/installer/onboarding.pl @@ -37,7 +37,7 @@ use Koha::IssuingRules; my $input = new CGI; unless ( C4::Context->preference('Version') ) { - print $input->redirect("/cgi-bin/koha/installer/install.pl"); + print $input->redirect("mainpage.pl"); exit; } diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/installer/step3.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/installer/step3.tt index 42f1295..02752c2 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/installer/step3.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/installer/step3.tt @@ -32,10 +32,6 @@ [% END %] -[% IF ( finish ) %] - [%- metacontent= '10; url=/cgi-bin/koha/installer/onboarding.pl' -%] - -[% END %] [% INCLUDE 'installer-doc-head-close.inc' %] @@ -47,7 +43,8 @@ [% IF ( finish ) %]

Web installer › Installation complete

Congratulations, installation complete

-

This page will redirect in 10 seconds. If not, click here to start onboarding process.

+

Click here to start onboarding process.

+

Skip the onboarding process (this is recommended for users not familiar with library business rules)

[% END %] [% IF ( choosemarc ) %] diff --git a/mainpage.pl b/mainpage.pl index c1df82b..00f979d 100755 --- a/mainpage.pl +++ b/mainpage.pl @@ -88,7 +88,20 @@ $template->param( # warn user if they are using mysql/admin login # unless ($loggedinuser) { - $template->param(adminWarning => 1); + my $patrons = Koha::Patrons->search( { flags => 1 } )->count; + my $patron_has_flag = Koha::Patron->check_if_patrons_have_flags(); + my $dbh = C4::Context->dbh; + if (!$patrons && !$patron_has_flag){ + my $onboardingrequired = C4::Auth->check_onboarding_required(); + if (!$onboardingrequired) { + $dbh->do(q{UPDATE userflags SET onboardingrequired = 1 WHERE bit = ?}, {}, 0 ); + } else { + print $query->redirect("/cgi-bin/koha/installer/onboarding.pl"); + exit; + } + } else { + $template->param(adminWarning => 1); + } } output_html_with_http_headers $query, $cookie, $template->output; -- 2.1.4