protected static function validate_submission($submission, workshop $workshop) {
        global $USER;

        $workshopclosed = $workshop->phase == workshop::PHASE_CLOSED;
        $canviewpublished = has_capability('mod/workshop:viewpublishedsubmissions', $workshop->context);

        $canview = $submission->authorid == $USER->id;  // I did it.
        $canview = $canview || !empty($workshop->get_assessment_of_submission_by_user($submission->id, $USER->id));  // I reviewed.
        $canview = $canview || has_capability('mod/workshop:viewallsubmissions', $workshop->context); // I can view all.
        $canview = $canview || ($submission->published && $workshopclosed && $canviewpublished);    // It has been published.

        if ($canview) {
            // Here we should check if the user share group.
            if ($submission->authorid != $USER->id &&
                    !groups_user_groups_visible($workshop->course, $submission->authorid, $workshop->cm)) {
                throw new moodle_exception('notingroup');
            }
        } else {
            throw new moodle_exception('nopermissions', 'error', '', 'view submission');
        }
    }