Fixes adding api keys a little more

This commit is contained in:
Dane Everitt 2016-10-20 18:29:34 -04:00
parent 53ec2c55ec
commit 0f4648b13a
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53

View file

@ -159,11 +159,14 @@ class APIRepository
]); ]);
$key->save(); $key->save();
$totalPermissions = 0;
if (isset($data['permissions'])) {
foreach($data['permissions'] as $permNode) { foreach($data['permissions'] as $permNode) {
if (!strpos($permNode, ':')) continue; if (!strpos($permNode, ':')) continue;
list($toss, $permission) = explode(':', $permNode); 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 = new Models\APIPermission;
$model->fill([ $model->fill([
'key_id' => $key->id, 'key_id' => $key->id,
@ -172,13 +175,15 @@ class APIRepository
$model->save(); $model->save();
} }
} }
}
if ($this->user->root_admin === 1) { if ($this->user->root_admin === 1 && isset($data['adminPermissions'])) {
foreach($data['permissions'] as $permNode) { foreach($data['adminPermissions'] as $permNode) {
if (!strpos($permNode, ':')) continue; if (!strpos($permNode, ':')) continue;
list($toss, $permission) = explode(':', $permNode); 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 = new Models\APIPermission;
$model->fill([ $model->fill([
'key_id' => $key->id, 'key_id' => $key->id,
@ -189,6 +194,10 @@ class APIRepository
} }
} }
if ($totalPermissions < 1) {
throw new DisplayException('No valid permissions were passed.');
}
DB::commit(); DB::commit();
return $secretKey; return $secretKey;
} catch (\Exception $ex) { } catch (\Exception $ex) {