예제 #1
0
 /** {@inheritDoc} */
 public function getPermissions(AbstractCalendar $calendar, AbstractCriterion $criterion = null)
 {
     $query = new Collection([new Collection([new Field('items', [new Field('id'), new Field('scope'), new Field('role')])], 'fields')]);
     if (null !== $criterion) {
         $query = $query->merge($criterion);
     }
     $response = $this->guzzle->get(sprintf('calendars/%s/acl', $calendar->getId()), ['query' => $query->build()]);
     if (200 > $response->getStatusCode() || 300 <= $response->getStatusCode()) {
         throw new ApiErrorException($response);
     }
     $result = $response->json();
     $list = new ArrayCollection();
     foreach ($result['items'] as $item) {
         // only user scope are supported
         if ('user' !== $item['scope']['type']) {
             continue;
         }
         $user = in_array($item['scope']['value'], $this->adapter->getUser()->getEmail(true)) ? $this->adapter->getUser() : User::hydrate(['email' => $item['scope']['value']]);
         $list[$item['id']] = UserPermission::hydrate($calendar, $user, $item['role']);
     }
     $calendar->setPermissions($list);
     return $list;
 }
예제 #2
0
 /**
  * Build a User object based on given data
  *
  * @param array $data User data
  *
  * @return User
  */
 protected static function buildUser(array $data)
 {
     if (isset($data['id'])) {
         $id = $data['id'];
     } else {
         $parts = [];
         if (isset($data['email'])) {
             $parts[] = $data['email'];
         }
         if (isset($data['displayName'])) {
             $parts[] = $data['displayName'];
         }
         $id = sha1(implode('', $parts));
     }
     if (!isset(static::$users[$id])) {
         static::$users[$id] = User::hydrate($data);
     }
     return static::$users[$id];
 }