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:
parent
f24b238e30
commit
820d2bf172
15 changed files with 447 additions and 26 deletions
|
@ -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');
|
||||
}
|
||||
}
|
||||
|
|
Reference in a new issue