From b423c5ad383edc39314bab2b0a2229461a36aa8c Mon Sep 17 00:00:00 2001 From: John Yao Date: Mon, 16 Dec 2019 11:28:04 +1100 Subject: [PATCH] MDL-67524 book: fixing view hidden chapter issue * Users who has permission should be able to view after turning editing off --- mod/book/tests/behat/show_hide_chapters.feature | 10 +++++----- mod/book/view.php | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/mod/book/tests/behat/show_hide_chapters.feature b/mod/book/tests/behat/show_hide_chapters.feature index 463a179bc07..651de447cec 100644 --- a/mod/book/tests/behat/show_hide_chapters.feature +++ b/mod/book/tests/behat/show_hide_chapters.feature @@ -58,11 +58,6 @@ Feature: Book activity chapter visibility management And I follow "Test book" Then the "class" attribute of "a[title='Second chapter']" "css_element" should contain "dimmed_text" And the "class" attribute of "a[title='Third chapter']" "css_element" should contain "dimmed_text" - And I follow "Next" - And I should see "Fourth chapter" in the ".book_content" "css_element" - And I follow "Exit book" - And I follow "Test book" - And I should see "First chapter" in the ".book_content" "css_element" And I turn editing mode on And I follow "Next" And I should see "Second chapter" in the ".book_content" "css_element" @@ -80,3 +75,8 @@ Feature: Book activity chapter visibility management And I follow "Test book" And I should not see "Second chapter" in the "Table of contents" "block" And I should not see "Third chapter" in the "Table of contents" "block" + And I follow "Next" + And I should see "Fourth chapter" in the ".book_content" "css_element" + And I follow "Exit book" + And I follow "Test book" + And I should see "First chapter" in the ".book_content" "css_element" diff --git a/mod/book/view.php b/mod/book/view.php index 2b2c2d19ea6..b214b239f1e 100644 --- a/mod/book/view.php +++ b/mod/book/view.php @@ -80,7 +80,7 @@ if ($chapterid == '0') { // Go to first chapter if no given. book_view($book, null, false, $course, $cm, $context); foreach ($chapters as $ch) { - if ($edit) { + if ($edit || ($ch->hidden && $viewhidden)) { $chapterid = $ch->id; break; } @@ -132,7 +132,7 @@ $nexttitle = null; $navnexttitle = null; $last = null; foreach ($chapters as $ch) { - if (!$edit and $ch->hidden) { + if (!$edit and ($ch->hidden && !$viewhidden)) { continue; } if ($last == $chapter->id) {