From 4dd989192d5070d1c22c6d7bea1d5370715cce07 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Mon, 8 Apr 2019 12:13:27 +0100 Subject: [PATCH] Bug 15326: (follow-up) Add CMS feature This patch builds on Martin Persson's patch. I made a few changes that improve the patch and make this feature functional. The only thing I am not completely satisfied with (and doesn't reliably work) is the navigation for the CMS pages on both the staff side and the OPAC side. This needs work. Otherwise the CMS feature works. - Make sure you update database after applying patch - After adding a few pages, confirm that filtering results works (play with different combinations of display location, library and language) - Confirm that pages with specific locations ONLY show up in those locations, i.e. OPAC pages can only be accessed in OPAC and staff interface pages can only be accessed on staff client - Confirm that table is showing correct data, particularly language, location and library - Confirm that if page has not been published and user does not have permission to edit pages, page content will not display on OPAC side. On staff side, a message will show saying that page has not been published - Confirm pagination for table shows and works - Confirm deleting pages works as expected (confirm message before delete) - Confirm link title must be unique when adding new pages - Confirm that editing the details of an existing page works - Confirm that adding a child page will only work if the location of child page matches location of parent page, i.e., if parent page is an OPAC page then child page must also be OPAC page. if parent page is in all locations then child page can be in all or either interface(s) - Confirm Select All/Clear All toggle works - Confirm viewing of CMS pages in OPAC and in staff client works and looks nice Sponsored-by: Region Halland Bug 15326: [FOLLOW-UP] Many fixes This patch: - moves action buttons into a dropdown, adds a delete button to dropdown - fixes the tests (they should now all pass) - fixes qa tool problems - removes the Koha::CmsPages->remove() method (unnecessary) - makes changes to the Koha::CmsPages->add() method (now simpler, easier to test) This is now ready to test. Sponsored-by: Catalyst IT Bug 15326: [FOLLOW-UP] More fixes This patch removes the t/Pages.t file because it isn't required, and other unused methods. This patch is ready to test. The appropriate tests are in t/db_dependent/Pages.t Bug 15326: [FOLLOW-UP] adding and editing fixes Sorry, did not see the second half of your comment. This patch should fix the adding and editing issues in Comment 16. Bug 15326: [FOLLOW-UP] Fixing library field in form, opac publishing Fixes issues from Comment 19, please test Signed-off-by: Josef Moravec Signed-off-by: Michal Denar Signed-off-by: Michal Denar Rebased-by: Martin Renvoize --- Koha/CmsPage.pm | 2 +- Koha/CmsPages.pm | 124 ++++----- .../bug15326-add_cms_pages_permission.sql | 1 + .../intranet-tmpl/prog/en/includes/tools-menu.inc | 68 +++-- .../prog/en/modules/tools/cmspages.tt | 276 ++++++++++++++------- .../bootstrap/en/includes/html_helpers.inc | 18 +- .../bootstrap/en/modules/opac-cmspages.tt | 56 ++--- koha-tmpl/opac-tmpl/bootstrap/less/opac.less | 40 +-- opac/opac-cmspages.pl | 14 +- opac/opac-main.pl | 14 +- t/Pages.t | 31 --- t/db_dependent/Pages.t | 123 +++++---- tools/cmspages.pl | 59 ++++- 13 files changed, 453 insertions(+), 373 deletions(-) create mode 100644 installer/data/mysql/atomicupdate/bug15326-add_cms_pages_permission.sql delete mode 100644 t/Pages.t diff --git a/Koha/CmsPage.pm b/Koha/CmsPage.pm index fd5b52ab31..cb333d0e74 100644 --- a/Koha/CmsPage.pm +++ b/Koha/CmsPage.pm @@ -39,7 +39,7 @@ Koha::CmsPage - Koha Page Object class =cut -sub type { +sub _type { return 'CmsPage'; } diff --git a/Koha/CmsPages.pm b/Koha/CmsPages.pm index b49881e09b..6af9203941 100644 --- a/Koha/CmsPages.pm +++ b/Koha/CmsPages.pm @@ -40,7 +40,7 @@ Koha::CmsPage - Koha CMS Page Object Class =cut -sub type { +sub _type { return 'CmsPage'; } @@ -49,27 +49,46 @@ sub object_class { } =head3 add + Adds a new page to the CMS database based on the input data. + =cut sub add { my ( $self, $input ) = @_; -warn "input: ", scalar $input->param('location'); carp( 'Koha::CmsPages::add() undefined parameter: input' ) unless defined $input; + my $data = { - parent => scalar $input->param( 'parent' ) eq '' ? undef : scalar $input->param( 'parent' ), - location => scalar $input->param( 'location' ) eq '' ? undef : scalar $input->param( 'location'), - branchcode => scalar $input->param( 'branchcode' ) eq '' ? undef : scalar $input->param( 'branchcode' ), - lang => scalar $input->param( 'lang' ), - sortorder => scalar $input->param( 'sortorder' ), - title => scalar $input->param( 'title' ), - title_link => scalar $input->param( 'title_link' ), - publish => defined (scalar $input->param( 'publish' )), - content => scalar $input->param( 'content' ) + parent => $input->{parent} eq '' ? undef : $input->{parent}, + location => $input->{location} eq '' ? undef : $input->{location}, + branchcode => $input->{branchcode} eq '' ? undef : $input->{branchcode}, + lang => $input->{lang}, + sortorder => $input->{sortorder}, + title => $input->{title}, + title_link => $input->{title_link}, + publish => $input->{publish} eq 'on' ? 1 : 0, + content => $input->{content} }; - if (defined $input->param( 'id' )) { - $data->{'id'} = scalar $input->param( 'id' ); + if (defined $input->{id}){ + $data->{id} = $input->{id}; + } + + # Ensuring link titles are unique + my $title_link = $input->{title_link}; + if ( Koha::CmsPages->find({ title_link => $title_link }) ){ + my $link = Koha::CmsPages->find({ title_link => $title_link }); + unless ( $link->id eq $input->{id} ){ + return; + } + } + + # Ensuring that, if page has parent, provided location suits parent location + my $parent = Koha::CmsPages->find($input->{parent}); + if ( $parent && $parent->location ne "" ){ + if ( $parent->location ne $input->{location} ){ + return; + } } my $new_page = $self->_resultset()->update_or_create( $data, { key => 'primary' }); @@ -79,22 +98,31 @@ warn "input: ", scalar $input->param('location'); =head3 list -Lists pages based input filtering paramters for location, branch and language. +Lists pages based input filtering parameters for location, branch and language. =cut sub list { my ( $self, $id, $disp, $branch, $lang ) = @_; - my $filter = { }; - $filter->{'location'} = $disp unless not defined $disp; - $filter->{'branch'} = $branch unless not defined $branch; - $filter->{'lang'} = $lang unless not defined $lang; + my %filter; + if ($branch) { + my $branch_push = [ $branch, undef ]; + push @{$filter{'branchcode'}}, $branch_push; + } + if ($lang) { + my $lang_push = [ $lang, undef ]; + push @{$filter{'lang'}}, $lang_push; + } + if ($disp) { + my $disp_push = [ $disp, undef ]; + push @{$filter{'location'}}, $disp_push; + } - my $pages = $self->_resultset()->search( undef, { + my $pages = $self->_resultset()->search( {}, { order_by => { - -asc => [qw/parent location branchcode lang sortorder/] - }, where => $filter + -asc => [qw/parent location branchcode lang sortorder/] + }, where => { %filter } } ); my $page_list = []; @@ -136,60 +164,6 @@ sub list { return ( $page_list, $parent_list, $data ); } -=head3 page - -Retrieves all data to show a single CMS page. - -=cut - -sub page { - my ( $self, $id ) = @_; - - carp( 'Missing CMS page id parameter in Koha::Pages::page' ) unless defined $id; - - # Probably want to merge these to a single query: - my $top_links = $self->_resultset()->search( - { parent => undef }, { qw/id title_link/ }); - - my $page_links = $self->_resultset()->search( - { parent => $id }, { qw/id title_link/ }); - - my $page_data = $self->_resultset()->find( $id ); - - return ( $top_links, $page_links, $page_data ); -} - -=head3 child_links - -Lists pages which are children of a specific id (or undef for root). - -=cut - -sub child_links { - my ( $self, $id ) = @_; - - # 'id' can be undefined if listing top-level links. - my $rs = $self->_resultset()->search({ parent => $id }, - { columns => [qw/id title_link/] } ); - - return $rs; -} - -=head3 remove - -Removes a page identified by id from the CMS database. - -=cut - -sub remove { - my ( $self, @ids ) = @_; - - carp( 'Koha::CmsPages::remove() undefined parameter ids' ) unless @ids; - - my $pages = $self->_resultset()->search({ id => \@ids }); - $pages->delete; -} - =head1 AUTHOR Martin Persson diff --git a/installer/data/mysql/atomicupdate/bug15326-add_cms_pages_permission.sql b/installer/data/mysql/atomicupdate/bug15326-add_cms_pages_permission.sql new file mode 100644 index 0000000000..72ce00f9a2 --- /dev/null +++ b/installer/data/mysql/atomicupdate/bug15326-add_cms_pages_permission.sql @@ -0,0 +1 @@ +INSERT IGNORE INTO permissions (`module_bit`, `code`, `description`) VALUES ('13', 'edit_pages', 'Create, edit and delete CMS pages for OPAC and staff interfaces'); diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/tools-menu.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/tools-menu.inc index 0b5f33110f..6610121fd0 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/tools-menu.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/tools-menu.inc @@ -1,4 +1,23 @@ [% USE Koha %] +