public function check_group_membership($otheruserid) {
        global $USER;

        if (groups_get_activity_groupmode($this->cm) != SEPARATEGROUPS) {
            // The workshop is not in a group mode, or it is in a visible group mode.
            return true;

        } else if (has_capability('moodle/site:accessallgroups', $this->context)) {
            // The current user can access all groups.
            return true;

        } else {
            $thisusersgroups = groups_get_all_groups($this->course->id, $USER->id, $this->cm->groupingid, 'g.id');
            $otherusersgroups = groups_get_all_groups($this->course->id, $otheruserid, $this->cm->groupingid, 'g.id');
            $commongroups = array_intersect_key($thisusersgroups, $otherusersgroups);

            if (empty($commongroups)) {
                // The current user has no group common with the other user.
                return false;

            } else {
                // The current user has a group common with the other user.
                return true;
            }
        }
    }