Пример #1
0
 public function isAllowed(Entity $entity, $privilege)
 {
     // These checks are run within the user context.
     $user = $this->getUser();
     // Then we check if a user has the 'admin' role. If they do they're
     // allowed access to everything (all entities and all privileges)
     if ($this->isUserAdmin($user)) {
         return true;
     }
     // Non-admin users are not allowed to make sets featured
     if (in_array($privilege, ['create', 'update']) and $entity->hasChanged('featured')) {
         return false;
     }
     // If the user is the owner of this set, they can do anything
     if ($this->isUserOwner($entity, $user)) {
         return true;
     }
     // Check if the Set is only visible to specific roles.
     if ($this->isVisibleToUser($entity, $user) and $privilege === 'read') {
         return true;
     }
     // All *logged in* users can create sets
     if ($user->getId() and $privilege === 'create') {
         return true;
     }
     // Finally, all users can search sets
     if ($privilege === 'search') {
         return true;
     }
     // If no other access checks succeed, we default to denying access
     return false;
 }
Пример #2
0
 public function update(Entity $entity)
 {
     $state = ['updated' => time()];
     if ($entity->hasChanged('password')) {
         $state['password'] = $this->hasher->hash($entity->password);
     }
     return parent::update($entity->setState($state));
 }
Пример #3
0
 public function update(Entity $entity)
 {
     // Get changed values
     $record = $entity->getChanged();
     // Set the updated time
     $record['updated'] = time();
     // Finally, update the record in the DB
     return $this->executeUpdate(['id' => $entity->id, 'search' => (int) $this->savedSearch], $record);
 }
Пример #4
0
 protected function verifyValid(Entity $entity)
 {
     $changed = $entity->getChanged();
     if (isset($entity->id)) {
         $changed['id'] = $entity->id;
     }
     if (!$this->validator->check($changed)) {
         $this->validatorError($entity);
     }
 }
Пример #5
0
 protected function verifyValid(Entity $entity)
 {
     $changed = $entity->getChanged();
     // Always pass values to validation
     if (isset($entity->values)) {
         $changed['values'] = $entity->values;
     }
     if (!$this->validator->check($changed, $entity->asArray())) {
         $this->validatorError($entity);
     }
 }
Пример #6
0
 public function create(Entity $entity)
 {
     $record = $entity->asArray();
     unset($record['form_id']);
     try {
         $uuid = Uuid::uuid4();
         $record['key'] = $uuid->toString();
     } catch (UnsatisfiedDependencyException $e) {
         Kohana::$log->add(Log::ERROR, $e->getMessage());
     }
     return $this->executeInsertAttribute($this->removeNullValues($record));
 }
Пример #7
0
 public function update(Entity $entity)
 {
     $group = $entity->getId();
     $this->verifyGroup($group);
     $config = \Kohana::$config->load($group);
     $immutable = $entity->getImmutable();
     foreach ($entity->getChanged() as $key => $val) {
         if (!in_array($key, $immutable)) {
             $config->set($key, $val);
         }
     }
 }
Пример #8
0
 function it_does_interact_with_the_repository_and_authenticator($repo, $authenticator, $format, Entity $user)
 {
     $email = '*****@*****.**';
     $password = '******';
     $this->setIdentifiers(compact('email', 'password'));
     $user->getId()->willReturn(1);
     $user->password = '******';
     $repo->getByEmail($email)->willReturn($user);
     $authenticator->checkPassword($password, $user->password)->willReturn(true);
     $formatted = ['email' => '*****@*****.**', 'password' => 'hash'];
     $format->__invoke($user)->willReturn($formatted);
     $this->interact()->shouldReturn($formatted);
 }
Пример #9
0
 public function update(Entity $entity)
 {
     $role = $entity->getChanged();
     // Remove permissions
     unset($role['permissions']);
     // ... Update the post
     $count = $this->executeUpdate(['id' => $entity->id], $role);
     // ... Update permissions
     if ($entity->hasChanged('permissions')) {
         $this->updatePermissions($entity->name, $entity->permissions);
     }
     return $count;
 }
Пример #10
0
 /**
  * Verifies that a given entity has been loaded, by checking that the "id"
  * property is not empty.
  * @param  Entity  $entity
  * @param  Mixed   $lookup
  * @return Entity
  * @throws NotFoundException
  */
 protected function verifyEntityLoaded(Entity $entity, $lookup)
 {
     if (!$entity->getId()) {
         if (is_array($lookup)) {
             $arr = [];
             foreach ($lookup as $key => $val) {
                 $arr[] = "{$key}: {$val}";
             }
             $lookup_string = implode(', ', $arr);
         } else {
             $lookup_string = $lookup;
         }
         throw new NotFoundException(sprintf('Could not locate any %s matching [%s]', $entity->getResource(), $lookup_string));
     }
     return $entity;
 }
Пример #11
0
 protected function verifyValid(Entity $entity)
 {
     $changed = $entity->getChanged();
     if (isset($entity->id)) {
         $changed['id'] = $entity->id;
     }
     // Always pass form_id to validation
     if (isset($entity->form_id)) {
         $changed['form_id'] = $entity->form_id;
     }
     // Always pass values to validation
     if (isset($entity->values)) {
         $changed['values'] = $entity->values;
     }
     if (!$this->validator->check($changed)) {
         $this->validatorError($entity);
     }
 }
Пример #12
0
 public function update(Entity $entity)
 {
     $record = $entity->getChanged();
     $record['updated'] = time();
     return $this->executeUpdate(['id' => $entity->id, 'search' => (int) $this->savedSearch], $entity->getChanged());
 }
Пример #13
0
 public function update(Entity $entity)
 {
     $post = $entity->getChanged();
     $post['updated'] = time();
     // Remove attribute values and tags
     unset($post['values'], $post['tags'], $post['completed_stages'], $post['sets'], $post['source'], $post['color']);
     // Convert post_date to mysql format
     if (!empty($post['post_date'])) {
         $post['post_date'] = $post['post_date']->format("Y-m-d H:i:s");
     }
     $count = $this->executeUpdate(['id' => $entity->id], $post);
     if ($entity->hasChanged('tags')) {
         // Update post-tags
         $this->updatePostTags($entity->id, $entity->tags);
     }
     if ($entity->hasChanged('values')) {
         // Update post-values
         $this->updatePostValues($entity->id, $entity->values);
     }
     if ($entity->hasChanged('completed_stages')) {
         // Update post-stages
         $this->updatePostStages($entity->id, $entity->form_id, $entity->completed_stages);
     }
     return $count;
 }
Пример #14
0
 public function update(Entity $entity)
 {
     $update = $entity->getChanged();
     $update['updated'] = time();
     return $this->executeUpdate(['id' => $entity->id], $update);
 }
Пример #15
0
 public function update(Entity $entity)
 {
     $post = $entity->getChanged();
     $post['updated'] = time();
     // Remove attribute values and tags
     unset($post['values'], $post['tags'], $post['completed_stages']);
     // Update the post
     $count = $this->executeUpdate(['id' => $entity->id], $post);
     if ($entity->hasChanged('tags')) {
         // Update post-tags
         $this->updatePostTags($entity->id, $entity->tags);
     }
     if ($entity->hasChanged('values')) {
         // Update post-values
         $this->updatePostValues($entity->id, $entity->values);
     }
     if ($entity->hasChanged('completed_stages')) {
         // Update post-stages
         $this->updatePostStages($entity->id, $entity->form_id, $entity->completed_stages);
     }
     return $count;
 }
Пример #16
0
 public function update(Entity $entity)
 {
     $update = $this->json_transcoder->encode($entity->getChanged(), $this->json_properties);
     $update['updated'] = time();
     return $this->executeUpdate(['id' => $entity->id], $update);
 }
Пример #17
0
 public function update(Entity $entity)
 {
     return $this->executeUpdate(['id' => $entity->id], $entity->getChanged());
 }
Пример #18
0
 public function update(Entity $entity)
 {
     $record = $this->json_transcoder->encode($entity->getChanged(), $this->json_properties);
     return $this->executeUpdate(['id' => $entity->getId()], $record);
 }
Пример #19
0
 public function create(Entity $entity)
 {
     $record = $entity->asArray();
     $record['created'] = time();
     return $this->executeInsert($this->removeNullValues($record));
 }
Пример #20
0
 public function create(Entity $entity)
 {
     $record = $entity->asArray();
     unset($record['form_id']);
     return $this->executeInsert($this->removeNullValues($record));
 }
Пример #21
0
 public function create(Entity $entity)
 {
     $state = ['created' => time()];
     return parent::create($entity->setState($state));
 }
Пример #22
0
 /**
  * Throw a ValidatorException
  *
  * @param  Entity $entity
  * @return null
  * @throws ValidatorException
  */
 protected function contactValidatorError(Entity $entity)
 {
     throw new ValidatorException(sprintf('Failed to validate %s entity', $entity->getResource()), $this->contactValidator->errors());
 }
Пример #23
0
 protected function verifyValid(Entity $entity)
 {
     if (!$this->validator->check($entity->getChanged())) {
         $this->validatorError($entity);
     }
 }
Пример #24
0
 public function update(Entity $entity)
 {
     return parent::update($entity->setState(['updated' => time()]));
 }