Skip to content

Commit

Permalink
Merge pull request #7579 from Automattic/revert-7577-revert-7558-fix/…
Browse files Browse the repository at this point in the history
…viewing-lesson-content

Revert "Revert "Don't display "Complete Lesson" button if student doesn't have access""
  • Loading branch information
donnapep committed Apr 4, 2024
2 parents fea167f + 29f1e96 commit 58d96dc
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 8 deletions.
4 changes: 4 additions & 0 deletions changelog/fix-viewing-lesson-content
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: fixed

Ensure student can view the lesson content when rendering the Complete Lesson button
9 changes: 6 additions & 3 deletions includes/blocks/class-sensei-complete-lesson-block.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,11 @@ public function __construct() {
*
* @return string The block HTML.
*/
public function render( array $attributes, string $content ) : string {
public function render( array $attributes, string $content ): string {
if ( ! sensei_can_user_view_lesson() ) {
return '';
}

$lesson = get_post();

if ( empty( $lesson ) ) {
Expand All @@ -51,7 +55,6 @@ public function render( array $attributes, string $content ) : string {
}

if ( false === Sensei()->lesson->lesson_has_quiz_with_questions_and_pass_required( $lesson->ID ) ) {

return $this->render_with_form( $attributes, $content );
}

Expand All @@ -66,7 +69,7 @@ public function render( array $attributes, string $content ) : string {
*
* @return string The HTML to render.
*/
private function render_with_form( array $attributes, string $content ) : string {
private function render_with_form( array $attributes, string $content ): string {
wp_enqueue_script( 'sensei-stop-double-submission' );
$nonce = wp_nonce_field( 'woothemes_sensei_complete_lesson_noonce', 'woothemes_sensei_complete_lesson_noonce', false, false );
$permalink = esc_url( get_permalink() );
Expand Down
4 changes: 4 additions & 0 deletions includes/blocks/course-theme/class-lesson-actions.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ public function __construct() {
* @return string The complete lesson button.
*/
private function render_complete_lesson( string $button_class, bool $is_outline_style, bool $is_disabled ): string {
if ( ! sensei_can_user_view_lesson() ) {
return '';
}

$button_style_class = $is_outline_style ? 'is-style-outline' : '';
$disabled_attribute = $is_disabled ? 'disabled' : '';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,9 @@ public function testAlreadyCompletedNoNextLesson() {
}

/**
* Test lesson actions block for a lesson with a pre-requisite lesson.
* Test lesson actions block for a lesson with an unmet prerequisite.
*/
public function testHasPreRequisite() {
public function testHasPrerequisite() {
list( $lesson1, $course ) = $this->create_enrolled_lesson_with_quiz();
$lesson2 = $this->factory->lesson->create_and_get(
[
Expand All @@ -212,9 +212,7 @@ public function testHasPreRequisite() {
$GLOBALS['post'] = $lesson2;
$block = new Lesson_Actions();

// Check for disabled button.
$this->assertStringContainsString( ' disabled', $block->render(), 'Should render disabled button if lesson has a pre-requisite.' );
$this->assertStringContainsString( 'aria-disabled="true"', $block->render(), 'Should render disabled button if lesson has a pre-requisite.' );
$this->assertStringNotContainsString( 'Complete Lesson', $block->render(), 'Should not render button if lesson has an unmet prerequisite.' );
}

/**
Expand Down

0 comments on commit 58d96dc

Please sign in to comment.