Exemplo n.º 1
0
 /**
  * @param string $attribute
  * @param CompetencyInterface $competency
  * @param UserInterface $user
  * @return bool
  */
 protected function isGranted($attribute, $competency, $user = null)
 {
     if (!$user instanceof UserInterface) {
         return false;
     }
     switch ($attribute) {
         // grant VIEW privileges
         // if the user's primary school is the the competency's owning school
         // - or -
         // if the user has READ rights on the competency's owning school
         // via the permissions system.
         case self::VIEW:
             return $this->schoolsAreIdentical($competency->getSchool(), $user->getSchool()) || $this->permissionManager->userHasReadPermissionToSchool($user, $competency->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 the competency's owning school
             //   - or -
             //   if the user has WRITE rights on the competency's owning school
             // via the permissions system.
             return $this->userHasRole($user, ['Developer']) && ($this->schoolsAreIdentical($competency->getSchool(), $user->getSchool()) || $this->permissionManager->userHasWritePermissionToSchool($user, $competency->getSchool()));
             break;
     }
     return false;
 }
Exemplo n.º 2
0
 /**
  * @param string $attribute
  * @param CompetencyInterface $competency
  * @param TokenInterface $token
  * @return bool
  */
 protected function voteOnAttribute($attribute, $competency, TokenInterface $token)
 {
     $user = $token->getUser();
     if (!$user instanceof UserInterface) {
         return false;
     }
     switch ($attribute) {
         case self::VIEW:
             // do not enforce special view permissions.
             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 the competency's owning school
             //   - or -
             //   if the user has WRITE rights on the competency's owning school
             // via the permissions system.
             return $this->userHasRole($user, ['Developer']) && ($this->schoolsAreIdentical($competency->getSchool(), $user->getSchool()) || $this->permissionManager->userHasWritePermissionToSchool($user, $competency->getSchool()->getId()));
             break;
     }
     return false;
 }
Exemplo n.º 3
0
 /**
  * @param array $data
  * @param CompetencyInterface $entity
  */
 protected function assertDataEquals(array $data, $entity)
 {
     // `competency_id`,`title`,`parent_competency_id`,`school_id`
     $this->assertEquals($data[0], $entity->getId());
     $this->assertEquals($data[1], $entity->getTitle());
     if (empty($data[2])) {
         $this->assertNull($entity->getParent());
     } else {
         $this->assertEquals($data[2], $entity->getParent()->getId());
     }
     $this->assertEquals($data[3], $entity->getSchool()->getId());
 }