Fixes adding api keys a little more
This commit is contained in:
parent
53ec2c55ec
commit
0f4648b13a
1 changed files with 25 additions and 16 deletions
|
@ -159,11 +159,14 @@ class APIRepository
|
|||
]);
|
||||
$key->save();
|
||||
|
||||
$totalPermissions = 0;
|
||||
if (isset($data['permissions'])) {
|
||||
foreach($data['permissions'] as $permNode) {
|
||||
if (!strpos($permNode, ':')) continue;
|
||||
|
||||
list($toss, $permission) = explode(':', $permNode);
|
||||
if (in_array('api.user.' . $permission, $this->permissions['user'])) {
|
||||
if (in_array($permission, $this->permissions['user'])) {
|
||||
$totalPermissions++;
|
||||
$model = new Models\APIPermission;
|
||||
$model->fill([
|
||||
'key_id' => $key->id,
|
||||
|
@ -172,13 +175,15 @@ class APIRepository
|
|||
$model->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->user->root_admin === 1) {
|
||||
foreach($data['permissions'] as $permNode) {
|
||||
if ($this->user->root_admin === 1 && isset($data['adminPermissions'])) {
|
||||
foreach($data['adminPermissions'] as $permNode) {
|
||||
if (!strpos($permNode, ':')) continue;
|
||||
|
||||
list($toss, $permission) = explode(':', $permNode);
|
||||
if (in_array('api.admin.' . $permission, $this->permissions['admin'])) {
|
||||
if (in_array($permission, $this->permissions['admin'])) {
|
||||
$totalPermissions++;
|
||||
$model = new Models\APIPermission;
|
||||
$model->fill([
|
||||
'key_id' => $key->id,
|
||||
|
@ -189,6 +194,10 @@ class APIRepository
|
|||
}
|
||||
}
|
||||
|
||||
if ($totalPermissions < 1) {
|
||||
throw new DisplayException('No valid permissions were passed.');
|
||||
}
|
||||
|
||||
DB::commit();
|
||||
return $secretKey;
|
||||
} catch (\Exception $ex) {
|
||||
|
|
Loading…
Reference in a new issue