Merge pull request #12119 from lukasfehling/feature/added-endpoint-for-user-notification

Added: API endpoint to trigger a user email notification with their assigned assets
This commit is contained in:
snipe 2022-11-15 17:51:15 +00:00 committed by GitHub
commit ffd252a00c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 39 additions and 0 deletions

View file

@ -15,6 +15,7 @@ use App\Models\Asset;
use App\Models\Company;
use App\Models\License;
use App\Models\User;
use App\Notifications\CurrentInventory;
use Auth;
use Illuminate\Http\Request;
use App\Http\Requests\ImageUploadRequest;
@ -490,6 +491,37 @@ class UsersController extends Controller
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.

View file

@ -976,6 +976,13 @@ Route::group(['prefix' => 'v1', 'middleware' => ['api', 'throttle:api']], functi
]
)->name('api.users.assetlist');
Route::post('{user}/email',
[
Api\UsersController::class,
'emailAssetList'
]
)->name('api.users.email_assets');
Route::get('{user}/accessories',
[
Api\UsersController::class,