Revert some changes from #15525
This commit is contained in:
parent
f1bf9fcf5c
commit
43f679a554
7 changed files with 7 additions and 205 deletions
|
@ -1,28 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Events;
|
|
||||||
|
|
||||||
use App\Models\User;
|
|
||||||
use Illuminate\Foundation\Events\Dispatchable;
|
|
||||||
use Illuminate\Queue\SerializesModels;
|
|
||||||
|
|
||||||
class NoteAdded
|
|
||||||
{
|
|
||||||
use Dispatchable, SerializesModels;
|
|
||||||
public $itemNoteAddedOn;
|
|
||||||
public $note;
|
|
||||||
public $noteAddedBy;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new event instance.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function __construct($itemNoteAddedOn, User $noteAddedBy, $note)
|
|
||||||
{
|
|
||||||
$this->itemNoteAddedOn = $itemNoteAddedOn;
|
|
||||||
$this->note = $note;
|
|
||||||
$this->noteAddedBy = $noteAddedBy;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,43 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Http\Controllers\Api;
|
|
||||||
|
|
||||||
use App\Events\NoteAdded;
|
|
||||||
use App\Helpers\Helper;
|
|
||||||
use App\Http\Controllers\Controller;
|
|
||||||
use App\Models\Asset;
|
|
||||||
use Illuminate\Http\Request;
|
|
||||||
use Illuminate\Support\Facades\Auth;
|
|
||||||
use Illuminate\Validation\Rule;
|
|
||||||
|
|
||||||
class NotesController extends Controller
|
|
||||||
{
|
|
||||||
public function store(Request $request)
|
|
||||||
{
|
|
||||||
$validated = $request->validate([
|
|
||||||
'note' => 'required|string|max:500',
|
|
||||||
'type' => [
|
|
||||||
'required',
|
|
||||||
Rule::in(['asset']),
|
|
||||||
],
|
|
||||||
]);
|
|
||||||
|
|
||||||
// This can be made dynamic by using $request->input('type') to determine which model type to add the note to.
|
|
||||||
// For now, we are only placing this on Assets
|
|
||||||
$item = Asset::findOrFail($request->input("id"));
|
|
||||||
$this->authorize('update', $item);
|
|
||||||
|
|
||||||
event(new NoteAdded($item, Auth::user(), $validated['note']));
|
|
||||||
|
|
||||||
return response()->json(Helper::formatStandardApiResponse('success'));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function update(Request $request)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
public function destroy(Request $request)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -17,7 +17,6 @@ use App\Events\ItemAccepted;
|
||||||
use App\Events\ItemDeclined;
|
use App\Events\ItemDeclined;
|
||||||
use App\Events\LicenseCheckedIn;
|
use App\Events\LicenseCheckedIn;
|
||||||
use App\Events\LicenseCheckedOut;
|
use App\Events\LicenseCheckedOut;
|
||||||
use App\Events\NoteAdded;
|
|
||||||
use App\Models\Actionlog;
|
use App\Models\Actionlog;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use App\Models\LicenseSeat;
|
use App\Models\LicenseSeat;
|
||||||
|
@ -129,23 +128,6 @@ class LogListener
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Note is added to action log
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public function onNoteAdded(NoteAdded $event)
|
|
||||||
{
|
|
||||||
$logaction = new Actionlog();
|
|
||||||
$logaction->item_id = $event->itemNoteAddedOn->id;
|
|
||||||
$logaction->item_type = get_class($event->itemNoteAddedOn);
|
|
||||||
$logaction->note = $event->note; //this is the received alphanumeric text from the box
|
|
||||||
$logaction->created_by = $event->noteAddedBy->id;
|
|
||||||
$logaction->action_type = 'note_added';
|
|
||||||
$logaction->save();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Register the listeners for the subscriber.
|
* Register the listeners for the subscriber.
|
||||||
*
|
*
|
||||||
|
|
|
@ -28,7 +28,7 @@ $(function () {
|
||||||
|
|
||||||
var baseUrl = $('meta[name="baseUrl"]').attr('content');
|
var baseUrl = $('meta[name="baseUrl"]').attr('content');
|
||||||
//handle modal-add-interstitial calls
|
//handle modal-add-interstitial calls
|
||||||
var model, select, refreshSelector, hasnopayload;
|
var model, select, refreshSelector;
|
||||||
|
|
||||||
if($('#createModal').length == 0) {
|
if($('#createModal').length == 0) {
|
||||||
$('body').append('<div class="modal fade" id="createModal"></div><!-- /.modal -->');
|
$('body').append('<div class="modal fade" id="createModal"></div><!-- /.modal -->');
|
||||||
|
@ -40,8 +40,6 @@ $(function () {
|
||||||
select = link.data("select");
|
select = link.data("select");
|
||||||
refreshSelector = link.data("refresh");
|
refreshSelector = link.data("refresh");
|
||||||
|
|
||||||
hasnopayload = link.data("hasnopayload");
|
|
||||||
|
|
||||||
$('#createModal').load(link.attr('href'),function () {
|
$('#createModal').load(link.attr('href'),function () {
|
||||||
|
|
||||||
// this sets the focus to be the name field
|
// this sets the focus to be the name field
|
||||||
|
@ -123,13 +121,12 @@ $(function () {
|
||||||
$('#modal_error_msg').html(error_message).show();
|
$('#modal_error_msg').html(error_message).show();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if(!hasnopayload) {
|
|
||||||
var id = result.payload.id;
|
var id = result.payload.id;
|
||||||
var name = result.payload.name || (result.payload.first_name + " " + result.payload.last_name);
|
var name = result.payload.name || (result.payload.first_name + " " + result.payload.last_name);
|
||||||
if (!id || !name) {
|
if (!id || !name) {
|
||||||
console.error("Could not find resulting name or ID from modal-create. Name: " + name + ", id: " + id);
|
console.error("Could not find resulting name or ID from modal-create. Name: " + name + ", id: " + id);
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
$('#createModal').modal('hide');
|
$('#createModal').modal('hide');
|
||||||
$('#createModal').html("");
|
$('#createModal').html("");
|
||||||
|
|
|
@ -1302,20 +1302,6 @@ Route::group(['prefix' => 'v1', 'middleware' => ['api', 'throttle:api']], functi
|
||||||
)->name('api.activity.index');
|
)->name('api.activity.index');
|
||||||
}); // end reports api routes
|
}); // end reports api routes
|
||||||
|
|
||||||
/**
|
|
||||||
* Notes API routes
|
|
||||||
*/
|
|
||||||
|
|
||||||
Route::group(['prefix' => 'notes'], function () {
|
|
||||||
|
|
||||||
Route::post(
|
|
||||||
'/',
|
|
||||||
[ Api\NotesController::class,
|
|
||||||
'store'
|
|
||||||
]
|
|
||||||
)->name('api.notes.store');
|
|
||||||
}); // end notes api routes
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1,76 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace Tests\Feature\Notes;
|
|
||||||
|
|
||||||
use App\Events\NoteAdded;
|
|
||||||
use App\Models\Asset;
|
|
||||||
use App\Models\User;
|
|
||||||
use Illuminate\Support\Facades\Event;
|
|
||||||
use Tests\TestCase;
|
|
||||||
|
|
||||||
class AssetNotesTest extends TestCase
|
|
||||||
{
|
|
||||||
public function testRequiresPermission()
|
|
||||||
{
|
|
||||||
$asset = Asset::factory()->create();
|
|
||||||
|
|
||||||
$this->actingAsForApi(User::factory()->create())
|
|
||||||
->postJson(route('api.notes.store'), [
|
|
||||||
'note' => 'New Note!',
|
|
||||||
'type' => 'asset',
|
|
||||||
'id' => $asset->id,
|
|
||||||
])
|
|
||||||
->assertForbidden();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testValidation()
|
|
||||||
{
|
|
||||||
$asset = Asset::factory()->create();
|
|
||||||
|
|
||||||
$this->actingAsForApi(User::factory()->editAssets()->create())
|
|
||||||
->postJson(route('api.notes.store'), [
|
|
||||||
// 'note' => '',
|
|
||||||
'type' => 'a_type_not_asset',
|
|
||||||
'id' => $asset->id,
|
|
||||||
])
|
|
||||||
->assertOk()
|
|
||||||
->assertStatusMessageIs('error')
|
|
||||||
->assertJsonValidationErrors(['note', 'type'], 'messages');
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testRequiresExistingAsset()
|
|
||||||
{
|
|
||||||
$this->actingAsForApi(User::factory()->editAssets()->create())
|
|
||||||
->postJson(route('api.notes.store'), [
|
|
||||||
'note' => 'New Note!',
|
|
||||||
'type' => 'asset',
|
|
||||||
'id' => 999_999,
|
|
||||||
])
|
|
||||||
->assertStatusMessageIs('error')
|
|
||||||
->assertMessagesAre('Asset not found');
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testCanAddNoteToAsset()
|
|
||||||
{
|
|
||||||
Event::fake([NoteAdded::class]);
|
|
||||||
|
|
||||||
$asset = Asset::factory()->create();
|
|
||||||
$user = User::factory()->editAssets()->create();
|
|
||||||
|
|
||||||
$this->actingAsForApi($user)
|
|
||||||
->postJson(route('api.notes.store'), [
|
|
||||||
'note' => 'New Note!',
|
|
||||||
'type' => 'asset',
|
|
||||||
'id' => $asset->id,
|
|
||||||
])
|
|
||||||
->assertOk()
|
|
||||||
->assertStatusMessageIs('success');
|
|
||||||
|
|
||||||
Event::assertDispatchedTimes(NoteAdded::class, 1);
|
|
||||||
Event::assertDispatched(NoteAdded::class, function (NoteAdded $event) use ($asset, $user) {
|
|
||||||
return $event->itemNoteAddedOn->is($asset)
|
|
||||||
&& $event->note === 'New Note!'
|
|
||||||
&& $event->noteAddedBy->is($user);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -3,7 +3,6 @@
|
||||||
namespace Tests\Unit\Listeners;
|
namespace Tests\Unit\Listeners;
|
||||||
|
|
||||||
use App\Events\CheckoutableCheckedOut;
|
use App\Events\CheckoutableCheckedOut;
|
||||||
use App\Events\NoteAdded;
|
|
||||||
use App\Listeners\LogListener;
|
use App\Listeners\LogListener;
|
||||||
use App\Models\Asset;
|
use App\Models\Asset;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
|
@ -38,19 +37,4 @@ class LogListenerTest extends TestCase
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testLogsEntryOnAssetNoteCreation()
|
|
||||||
{
|
|
||||||
$asset = Asset::factory()->create();
|
|
||||||
$noteAddedBy = User::factory()->create();
|
|
||||||
|
|
||||||
event(new NoteAdded($asset, $noteAddedBy, 'My Cool Note!'));
|
|
||||||
|
|
||||||
$this->assertDatabaseHas('action_logs', [
|
|
||||||
'action_type' => 'note_added',
|
|
||||||
'created_by' => $noteAddedBy->id,
|
|
||||||
'item_id' => $asset->id,
|
|
||||||
'item_type' => Asset::class,
|
|
||||||
'note' => 'My Cool Note!',
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue