public function can_view_grades($groupid = null) {
        // Permissions check.
        if (!has_any_capability(array('mod/assign:viewgrades', 'mod/assign:grade'), $this->context)) {
            return false;
        }
        // Checks for the edge case when user belongs to no groups and groupmode is sep.
        if ($this->get_course_module()->effectivegroupmode == SEPARATEGROUPS) {
            if ($groupid === null) {
                $groupid = groups_get_activity_allowed_groups($this->get_course_module());
            }
            $groupflag = has_capability('moodle/site:accessallgroups', $this->get_context());
            $groupflag = $groupflag || !empty($groupid);
            return (bool)$groupflag;
        }
        return true;
    }