hi!

There is a missing $uid property that causes incorrect access

Scenario:

1 - Create a simple quiz with any number of questions, for example 1 multichoice.
2 - Do the quiz
3 - Go to my results: node/1/myresults/1

Notice: Undefined property: stdClass::$uid in QuizQuestion->viewCanRevealCorrect() (line 628 of

  public function viewCanRevealCorrect() {
    global $user;
    // permission overrides the hook
    if (user_access('view any quiz question correct response')
     || $user->uid == $this->node->uid) {
      return TRUE;
    }
    $results = module_invoke_all('answers_access', $this->node);
    $may_view_answers = in_array(TRUE, $results);
    return $may_view_answers;
  }

The problem is that the node is not loaded completely (because of performance reasons) and the uid is not beeing pulled from database so the if statement fails.

Attaching patch to solve it, please review!

Comments

GeduR created an issue. See original summary.

gedur’s picture

Status: Active » Needs review
ultimike’s picture

This could also be caused by a permissions issue - see https://www.drupal.org/node/2454273.

thanks,
-mike

  • djdevin committed 6a0be8c on 7.x-4.x authored by GeduR
    Issue #2592699 by GeduR: Undefined property: stdClass::$uid in...
djdevin’s picture

Status: Needs review » Fixed

Thanks, this fixes the notice. I changed r.nid to n.nid, so that the current question owner is pulled instead of the revision's owner.

This isn't necessary in 7.x-5.x since we use Drupal 7 entity caching.

  • djdevin committed b475834 on 7.x-4.x
    Issue #2592699: use n.nid for checking ownership
    

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.