/** * @param string $attribute * @param CGroupInfo $group * @param User $user * @return bool */ protected function isGranted($attribute, $group, $user = null) { // make sure there is a user object (i.e. that the user is logged in) if (!$user instanceof UserInterface) { return false; } if ($group == false) { return false; } $authChecker = $this->container->get('security.authorization_checker'); // Admins have access to everything if ($authChecker->isGranted('ROLE_ADMIN')) { return true; } $groupInfo = ['id' => $group->getId(), 'session_id' => 0, 'status' => $group->getStatus()]; // Legacy return \GroupManager::userHasAccessToBrowse($user->getId(), $groupInfo); switch ($attribute) { case self::VIEW: if (!$group->hasUserInCourse($user, $course)) { $user->addRole('ROLE_CURRENT_SESSION_COURSE_STUDENT'); return true; } break; case self::EDIT: case self::DELETE: if (!$session->hasCoachInCourseWithStatus($user, $course)) { $user->addRole('ROLE_CURRENT_SESSION_COURSE_TEACHER'); return true; } break; } dump("You don't have access to this group!!"); return false; }