Node and user API routes implemented.

More attempts at the logic for API permissions, most likely will need
continued tweaking in the future, but base is there.
This commit is contained in:
Dane Everitt 2017-04-09 15:31:10 -04:00
parent f24b238e30
commit 820d2bf172
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
15 changed files with 447 additions and 26 deletions

View file

@ -30,6 +30,16 @@ use League\Fractal\TransformerAbstract;
class UserTransformer extends TransformerAbstract
{
/**
* List of resources that can be included.
*
* @var array
*/
protected $availableIncludes = [
'access',
'servers',
];
/**
* The Illuminate Request object if provided.
*
@ -61,4 +71,32 @@ class UserTransformer extends TransformerAbstract
{
return $user->toArray();
}
/**
* Return the servers associated with this user.
*
* @return \Leauge\Fractal\Resource\Collection
*/
public function includeServers(User $user)
{
if ($this->request && ! $this->request->apiKeyHasPermission('user-view')) {
return;
}
return $this->collection($user->servers, new ServerTransformer($this->request), 'server');
}
/**
* Return the servers that this user can access.
*
* @return \Leauge\Fractal\Resource\Collection
*/
public function includeAccess(User $user)
{
if ($this->request && ! $this->request->apiKeyHasPermission('user-view')) {
return;
}
return $this->collection($user->access()->get(), new ServerTransformer($this->request), 'server');
}
}