mirror of
https://github.com/snipe/snipe-it.git
synced 2024-11-11 16:14:18 -08:00
Merge remote-tracking branch 'origin/develop'
This commit is contained in:
commit
0d2f43c04f
|
@ -63,7 +63,7 @@ class GroupsController extends Controller
|
||||||
$group = new Group;
|
$group = new Group;
|
||||||
|
|
||||||
$group->name = $request->input('name');
|
$group->name = $request->input('name');
|
||||||
$group->permissions = $request->input('permissions'); // Todo - some JSON validation stuff here
|
$group->permissions = json_encode($request->input('permissions')); // Todo - some JSON validation stuff here
|
||||||
|
|
||||||
if ($group->save()) {
|
if ($group->save()) {
|
||||||
return response()->json(Helper::formatStandardApiResponse('success', $group, trans('admin/groups/message.create.success')));
|
return response()->json(Helper::formatStandardApiResponse('success', $group, trans('admin/groups/message.create.success')));
|
||||||
|
|
|
@ -18,6 +18,7 @@ use App\Notifications\CheckoutAccessoryNotification;
|
||||||
use App\Notifications\CheckoutAssetNotification;
|
use App\Notifications\CheckoutAssetNotification;
|
||||||
use App\Notifications\CheckoutConsumableNotification;
|
use App\Notifications\CheckoutConsumableNotification;
|
||||||
use App\Notifications\CheckoutLicenseSeatNotification;
|
use App\Notifications\CheckoutLicenseSeatNotification;
|
||||||
|
use GuzzleHttp\Exception\ClientException;
|
||||||
use Illuminate\Support\Facades\Notification;
|
use Illuminate\Support\Facades\Notification;
|
||||||
use Exception;
|
use Exception;
|
||||||
use Log;
|
use Log;
|
||||||
|
@ -44,11 +45,6 @@ class CheckoutableListener
|
||||||
$acceptance = $this->getCheckoutAcceptance($event);
|
$acceptance = $this->getCheckoutAcceptance($event);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if ($this->shouldSendWebhookNotification()) {
|
|
||||||
Notification::route('slack', Setting::getSettings()->webhook_endpoint)
|
|
||||||
->notify($this->getCheckoutNotification($event));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (! $event->checkedOutTo->locale) {
|
if (! $event->checkedOutTo->locale) {
|
||||||
Notification::locale(Setting::getSettings()->locale)->send(
|
Notification::locale(Setting::getSettings()->locale)->send(
|
||||||
$this->getNotifiables($event),
|
$this->getNotifiables($event),
|
||||||
|
@ -60,6 +56,13 @@ class CheckoutableListener
|
||||||
$this->getCheckoutNotification($event, $acceptance)
|
$this->getCheckoutNotification($event, $acceptance)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($this->shouldSendWebhookNotification()) {
|
||||||
|
Notification::route('slack', Setting::getSettings()->webhook_endpoint)
|
||||||
|
->notify($this->getCheckoutNotification($event));
|
||||||
|
}
|
||||||
|
} catch (ClientException $e) {
|
||||||
|
Log::debug("Exception caught during checkout notification: " . $e->getMessage());
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
Log::error("Exception caught during checkout notification: " . $e->getMessage());
|
Log::error("Exception caught during checkout notification: " . $e->getMessage());
|
||||||
}
|
}
|
||||||
|
@ -92,11 +95,6 @@ class CheckoutableListener
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if ($this->shouldSendWebhookNotification()) {
|
|
||||||
Notification::route('slack', Setting::getSettings()->webhook_endpoint)
|
|
||||||
->notify($this->getCheckinNotification($event));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Use default locale
|
// Use default locale
|
||||||
if (! $event->checkedOutTo->locale) {
|
if (! $event->checkedOutTo->locale) {
|
||||||
Notification::locale(Setting::getSettings()->locale)->send(
|
Notification::locale(Setting::getSettings()->locale)->send(
|
||||||
|
@ -109,6 +107,13 @@ class CheckoutableListener
|
||||||
$this->getCheckinNotification($event)
|
$this->getCheckinNotification($event)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($this->shouldSendWebhookNotification()) {
|
||||||
|
Notification::route('slack', Setting::getSettings()->webhook_endpoint)
|
||||||
|
->notify($this->getCheckinNotification($event));
|
||||||
|
}
|
||||||
|
} catch (ClientException $e) {
|
||||||
|
Log::debug("Exception caught during checkout notification: " . $e->getMessage());
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
Log::error("Exception caught during checkin notification: " . $e->getMessage());
|
Log::error("Exception caught during checkin notification: " . $e->getMessage());
|
||||||
}
|
}
|
||||||
|
|
41
tests/Feature/Api/Groups/GroupStoreTest.php
Normal file
41
tests/Feature/Api/Groups/GroupStoreTest.php
Normal file
|
@ -0,0 +1,41 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Tests\Feature\Api\Groups;
|
||||||
|
|
||||||
|
use App\Models\Group;
|
||||||
|
use App\Models\User;
|
||||||
|
use Tests\Support\InteractsWithSettings;
|
||||||
|
use Tests\TestCase;
|
||||||
|
|
||||||
|
class GroupStoreTest extends TestCase
|
||||||
|
{
|
||||||
|
use InteractsWithSettings;
|
||||||
|
|
||||||
|
public function testStoringGroupRequiresSuperAdminPermission()
|
||||||
|
{
|
||||||
|
$this->actingAsForApi(User::factory()->create())
|
||||||
|
->postJson(route('api.groups.store'))
|
||||||
|
->assertForbidden();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testCanStoreGroup()
|
||||||
|
{
|
||||||
|
$this->actingAsForApi(User::factory()->superuser()->create())
|
||||||
|
->postJson(route('api.groups.store'), [
|
||||||
|
'name' => 'My Awesome Group',
|
||||||
|
'permissions' => [
|
||||||
|
'admin' => '1',
|
||||||
|
'import' => '1',
|
||||||
|
'reports.view' => '0',
|
||||||
|
],
|
||||||
|
])
|
||||||
|
->assertOk();
|
||||||
|
|
||||||
|
$group = Group::where('name', 'My Awesome Group')->first();
|
||||||
|
|
||||||
|
$this->assertNotNull($group);
|
||||||
|
$this->assertEquals('1', $group->decodePermissions()['admin']);
|
||||||
|
$this->assertEquals('1', $group->decodePermissions()['import']);
|
||||||
|
$this->assertEquals('0', $group->decodePermissions()['reports.view']);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue