mirror of
https://github.com/snipe/snipe-it.git
synced 2025-01-11 13:57:41 -08:00
Added a api endpoint for sending email notifications to users with their assigned assets
This commit is contained in:
parent
6dc0846f38
commit
d9a9bd1c0d
|
@ -15,6 +15,7 @@ use App\Models\Asset;
|
||||||
use App\Models\Company;
|
use App\Models\Company;
|
||||||
use App\Models\License;
|
use App\Models\License;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
|
use App\Notifications\CurrentInventory;
|
||||||
use Auth;
|
use Auth;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use App\Http\Requests\ImageUploadRequest;
|
use App\Http\Requests\ImageUploadRequest;
|
||||||
|
@ -490,6 +491,37 @@ class UsersController extends Controller
|
||||||
return (new AssetsTransformer)->transformAssets($assets, $assets->count(), $request);
|
return (new AssetsTransformer)->transformAssets($assets, $assets->count(), $request);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Notify a specific user via email with all of his assigned assets.
|
||||||
|
*
|
||||||
|
* @author [Lukas Fehling] [<lukas.fehling@adabay.rocks>]
|
||||||
|
* @since [v6.0.13]
|
||||||
|
* @param Request $request
|
||||||
|
* @param $id
|
||||||
|
* @return string JSON
|
||||||
|
*/
|
||||||
|
public function emailAssetList(Request $request, $id)
|
||||||
|
{
|
||||||
|
$user = User::findOrFail($id);
|
||||||
|
|
||||||
|
if (empty($user->email)) {
|
||||||
|
return response()->json(
|
||||||
|
[
|
||||||
|
'status' => 'error',
|
||||||
|
'message' => 'This user has no email set.',
|
||||||
|
'payload' => null,
|
||||||
|
], 404);
|
||||||
|
}
|
||||||
|
|
||||||
|
$user->notify((new CurrentInventory($user)));
|
||||||
|
|
||||||
|
return response()->json(
|
||||||
|
[
|
||||||
|
'status' => 'success',
|
||||||
|
'message' => 'The user was notified about his current inventory.',
|
||||||
|
'payload' => null,
|
||||||
|
], 200);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return JSON containing a list of consumables assigned to a user.
|
* Return JSON containing a list of consumables assigned to a user.
|
||||||
|
|
|
@ -976,6 +976,13 @@ Route::group(['prefix' => 'v1', 'middleware' => ['api', 'throttle:api']], functi
|
||||||
]
|
]
|
||||||
)->name('api.users.assetlist');
|
)->name('api.users.assetlist');
|
||||||
|
|
||||||
|
Route::post('{user}/email',
|
||||||
|
[
|
||||||
|
Api\UsersController::class,
|
||||||
|
'emailAssetList'
|
||||||
|
]
|
||||||
|
)->name('api.users.email_assets');
|
||||||
|
|
||||||
Route::get('{user}/accessories',
|
Route::get('{user}/accessories',
|
||||||
[
|
[
|
||||||
Api\UsersController::class,
|
Api\UsersController::class,
|
||||||
|
|
Loading…
Reference in a new issue