Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions classes/QuizBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -810,11 +810,22 @@ public function save_quiz( $topic_id, $payload ) {
$errors = array();

$validation = $this->validate_payload( $payload );
if ( $validation->success && tutor()->topics_post_type !== get_post_type( $topic_id ) ) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checking the validtion->success will not add the post type error with the validation error. Since the post type check is part of validation, the error should be included regardless of the validation->success status. Now, the user will not know the post type error until it passes the existing validations.

$validation->success = false;
$validation->errors['topic_id'][] = __( 'Invalid topic id provided', 'tutor' );
}

if ( ! tutor_utils()->can_user_manage( 'topic', $topic_id ) ) {
$validation->success = false;
$validation->errors['topic_id'][] = tutor_utils()->error_message();
}

$existing_quiz_id = (int) ( $payload['ID'] ?? 0 );
if ( $validation->success && $existing_quiz_id && (int) wp_get_post_parent_id( $existing_quiz_id ) !== (int) $topic_id ) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Same issue is here.

$validation->success = false;
$validation->errors['topic_id'][] = __( 'Quiz does not belong to the submitted topic', 'tutor' );
}

if ( ! $validation->success ) {
return (object) array(
'success' => false,
Expand Down Expand Up @@ -847,6 +858,7 @@ public function save_quiz( $topic_id, $payload ) {
// Add or update the quiz.
if ( $is_update ) {
$quiz_data['ID'] = $quiz_id;
unset( $quiz_data['post_author'] );
}

$quiz_id = wp_insert_post( $quiz_data );
Expand Down Expand Up @@ -908,6 +920,9 @@ public function ajax_quiz_builder_save() {
$course_cls = new Course( false );

$course_cls->check_access( $course_id );
if ( $topic_id && (int) wp_get_post_parent_id( $topic_id ) !== $course_id ) {
$this->json_response( tutor_utils()->error_message(), null, HttpHelper::STATUS_FORBIDDEN );
}

$result = $this->save_quiz( $topic_id, wp_slash( $payload ) );
if ( $result->success ) {
Expand Down
Loading