/** * @param string $attribute * @param SessionTypeInterface $sessionType * @param UserInterface $user * @return bool */ protected function isGranted($attribute, $sessionType, $user = null) { if (!$user instanceof UserInterface) { return false; } switch ($attribute) { // grant VIEW privileges // if the user's primary school is the session type's owning school // - or - // if the user has READ rights on the session type's owning school // via the permissions system. case self::VIEW: return $this->schoolsAreIdentical($sessionType->getSchool(), $user->getSchool()) || $this->permissionManager->userHasReadPermissionToSchool($user, $sessionType->getSchool()); break; case self::CREATE: case self::EDIT: case self::DELETE: // grant CREATE, EDIT and DELETE privileges // if the user has the 'Developer' role // - and - // if the user's primary school is the session type's owning school // - or - // if the user has WRITE rights on the session type's owning school // via the permissions system. return $this->userHasRole($user, ['Developer']) && ($this->schoolsAreIdentical($sessionType->getSchool(), $user->getSchool()) || $this->permissionManager->userHasWritePermissionToSchool($user, $sessionType->getSchool())); break; } return false; }
/** * @param string $attribute * @param SessionTypeInterface $sessionType * @param TokenInterface $token * @return bool */ protected function voteOnAttribute($attribute, $sessionType, TokenInterface $token) { $user = $token->getUser(); if (!$user instanceof UserInterface) { return false; } switch ($attribute) { // grant VIEW privileges // do not impose any restrictions. case self::VIEW: return true; break; case self::CREATE: case self::EDIT: case self::DELETE: // grant CREATE, EDIT and DELETE privileges // if the user has the 'Developer' role // - and - // if the user's primary school is the session type's owning school // - or - // if the user has WRITE rights on the session type's owning school // via the permissions system. return $this->userHasRole($user, ['Developer']) && ($this->schoolsAreIdentical($sessionType->getSchool(), $user->getSchool()) || $this->permissionManager->userHasWritePermissionToSchool($user, $sessionType->getSchool()->getId())); break; } return false; }
/** * @param array $data * @param SessionTypeInterface $entity */ protected function assertDataEquals(array $data, $entity) { // `session_type_id`,`title`,`school_id`,`session_type_css_class`,`assessment`,`assessment_option_id` $this->assertEquals($data[0], $entity->getId()); $this->assertEquals($data[1], $entity->getTitle()); $this->assertEquals($data[2], $entity->getSchool()->getId()); $this->assertEquals($data[3], $entity->getSessionTypeCssClass()); $this->assertEquals((bool) $data[4], $entity->isAssessment()); if (empty($data[5])) { $this->assertNull($entity->getAssessmentOption()); } else { $this->assertEquals($data[5], $entity->getAssessmentOption()); } }