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,26 +159,31 @@ class APIRepository
]);
$key->save();
foreach($data['permissions'] as $permNode) {
if (!strpos($permNode, ':')) continue;
list($toss, $permission) = explode(':', $permNode);
if (in_array('api.user.' . $permission, $this->permissions['user'])) {
$model = new Models\APIPermission;
$model->fill([
'key_id' => $key->id,
'permission' => 'api.user.' . $permission
]);
$model->save();
}
}
if ($this->user->root_admin === 1) {
$totalPermissions = 0;
if (isset($data['permissions'])) {
foreach($data['permissions'] 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['user'])) {
$totalPermissions++;
$model = new Models\APIPermission;
$model->fill([
'key_id' => $key->id,
'permission' => 'api.user.' . $permission
]);
$model->save();
}
}
}
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($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) {