Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added #9594 : Feature api image uploads and remove #9767

Merged
merged 40 commits into from
Jul 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
491a788
testing image upload via api
PetriAsi Jun 23, 2021
0e2efb6
Merge branch 'develop' of github.com:snipe/snipe-it into feature/api-…
PetriAsi Jun 27, 2021
695bf1e
save images
PetriAsi Jun 28, 2021
e0c5205
save images
PetriAsi Jun 28, 2021
8d42197
Support images and multipart requests
PetriAsi Jun 29, 2021
aa402bf
Support images and multipart requests
PetriAsi Jun 29, 2021
e8a4059
Support images and multipart requests
PetriAsi Jun 29, 2021
4ed9788
Support images and multipart requests
PetriAsi Jun 29, 2021
604a0b6
Support images and multipart requests
PetriAsi Jun 29, 2021
a7b1e31
Support images and multipart requests
PetriAsi Jun 29, 2021
4ba7529
Support images and multipart requests
PetriAsi Jun 29, 2021
fc84989
Support images and multipart requests
PetriAsi Jun 29, 2021
f9da83b
Support images and multipart requests
PetriAsi Jun 29, 2021
a936744
Support images and multipart requests
PetriAsi Jun 29, 2021
8c0be3a
Support images and multipart requests
PetriAsi Jun 29, 2021
b497338
Support images and multipart requests
PetriAsi Jun 29, 2021
b0aa26e
Support images and multipart requests
PetriAsi Jun 29, 2021
6048acc
fixed capitalization
PetriAsi Jun 30, 2021
347e742
merged current upstream/develop
PetriAsi Jun 30, 2021
e15159b
trait base64 encoded files
PetriAsi Jul 2, 2021
e846e6a
trait base64 encoded files
PetriAsi Jul 2, 2021
f4fa683
trait base64 encoded files
PetriAsi Jul 2, 2021
f59f3db
case case again..
PetriAsi Jul 2, 2021
d48a9d5
Try without trait
PetriAsi Jul 4, 2021
02fb7ac
Try without trait
PetriAsi Jul 4, 2021
013df74
debug trait
PetriAsi Jul 5, 2021
d66ef23
handle files via standard field
PetriAsi Jul 6, 2021
7a5b5c2
merged from develop
PetriAsi Jul 6, 2021
e3166c2
fix debug placement
PetriAsi Jul 6, 2021
c1bc248
keep using request
PetriAsi Jul 6, 2021
c21b291
keep using request
PetriAsi Jul 6, 2021
2169c62
Merge branch 'feature/api-image-uploads-json' into feature/api-image-…
PetriAsi Jul 6, 2021
3d8acd1
removed unused Bag-functions
PetriAsi Jul 6, 2021
e275c9e
Fixed case again
PetriAsi Jul 6, 2021
f53cabe
Better debug comment
PetriAsi Jul 6, 2021
168d7f7
Handle image_source with ConvertBase64ToFiles
PetriAsi Jul 7, 2021
b2d3ba7
Revert "Handle image_source with ConvertBase64ToFiles"
PetriAsi Jul 7, 2021
7a42464
convert image_source field
PetriAsi Jul 7, 2021
41deabf
hand legacy image_source field
PetriAsi Jul 7, 2021
4379ea6
Just mention source of idea as code rewriten
PetriAsi Jul 8, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions app/Http/Controllers/Api/AccessoriesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Auth;
use DB;
use Illuminate\Http\Request;
use App\Http\Requests\ImageUploadRequest;

class AccessoriesController extends Controller
{
Expand Down Expand Up @@ -86,14 +87,15 @@ public function index(Request $request)
*
* @author [A. Gianotto] [<snipe@snipe.net>]
* @since [v4.0]
* @param \Illuminate\Http\Request $request
* @param \App\Http\Requests\ImageUploadRequest $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
public function store(ImageUploadRequest $request)
{
$this->authorize('create', Accessory::class);
$accessory = new Accessory;
$accessory->fill($request->all());
$accessory = $request->handleImages($accessory);

if ($accessory->save()) {
return response()->json(Helper::formatStandardApiResponse('success', $accessory, trans('admin/accessories/message.create.success')));
Expand Down Expand Up @@ -180,15 +182,16 @@ public function checkedout($id, Request $request)
*
* @author [A. Gianotto] [<snipe@snipe.net>]
* @since [v4.0]
* @param \Illuminate\Http\Request $request
* @param \App\Http\Requests\ImageUploadRequest $request
* @param int $id
* @return \Illuminate\Http\Response
*/
public function update(Request $request, $id)
public function update(ImageUploadRequest $request, $id)
{
$this->authorize('update', Accessory::class);
$accessory = Accessory::findOrFail($id);
$accessory->fill($request->all());
$accessory = $request->handleImages($accessory);

if ($accessory->save()) {
return response()->json(Helper::formatStandardApiResponse('success', $accessory, trans('admin/accessories/message.update.success')));
Expand Down
13 changes: 8 additions & 5 deletions app/Http/Controllers/Api/AssetModelsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use App\Models\Asset;
use App\Models\AssetModel;
use Illuminate\Http\Request;
use App\Http\Requests\ImageUploadRequest;
use Illuminate\Support\Facades\Storage;

/**
Expand Down Expand Up @@ -107,14 +108,15 @@ public function index(Request $request)
*
* @author [A. Gianotto] [<snipe@snipe.net>]
* @since [v4.0]
* @param \Illuminate\Http\Request $request
* @param \App\Http\Requests\ImageUploadRequest $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
public function store(ImageUploadRequest $request)
{
$this->authorize('create', AssetModel::class);
$assetmodel = new AssetModel;
$assetmodel->fill($request->all());
$assetmodel = $request->handleImages($assetmodel);

if ($assetmodel->save()) {
return response()->json(Helper::formatStandardApiResponse('success', $assetmodel, trans('admin/models/message.create.success')));
Expand Down Expand Up @@ -159,16 +161,17 @@ public function assets($id)
*
* @author [A. Gianotto] [<snipe@snipe.net>]
* @since [v4.0]
* @param \Illuminate\Http\Request $request
* @param \App\Http\Requests\ImageUploadRequest $request
* @param int $id
* @return \Illuminate\Http\Response
*/
public function update(Request $request, $id)
public function update(ImageUploadRequest $request, $id)
{
$this->authorize('update', AssetModel::class);
$assetmodel = AssetModel::findOrFail($id);
$assetmodel->fill($request->all());

$assetmodel = $request->handleImages($assetmodel);

/**
* Allow custom_fieldset_id to override and populate fieldset_id.
* This is stupid, but required for legacy API support.
Expand Down
56 changes: 15 additions & 41 deletions app/Http/Controllers/Api/AssetsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use Carbon\Carbon;
use DB;
use Illuminate\Http\Request;
use App\Http\Requests\ImageUploadRequest;
use Input;
use Paginator;
use Slack;
Expand Down Expand Up @@ -425,11 +426,11 @@ public function selectlist(Request $request)
* Accepts a POST request to create a new asset
*
* @author [A. Gianotto] [<snipe@snipe.net>]
* @param Request $request
* @param \App\Http\Requests\ImageUploadRequest $request
* @since [v4.0]
* @return JsonResponse
*/
public function store(Request $request)
public function store(ImageUploadRequest $request)
{

$this->authorize('create', Asset::class);
Expand Down Expand Up @@ -458,21 +459,7 @@ public function store(Request $request)
$asset->rtd_location_id = $request->get('rtd_location_id', null);
$asset->location_id = $request->get('rtd_location_id', null);

if ($request->has('image_source') && $request->input('image_source') != "") {
$saved_image_path = Helper::processUploadedImage(
$request->input('image_source'), 'uploads/assets/'
);

if (!$saved_image_path) {
return response()->json(Helper::formatStandardApiResponse(
'error',
null,
trans('admin/hardware/message.create.error')
), 200);
}

$asset->image = $saved_image_path;
}
$asset = $request->handleImages($asset);

// Update custom fields in the database.
// Validation for these fields is handled through the AssetRequest form request
Expand Down Expand Up @@ -540,11 +527,11 @@ public function store(Request $request)
* Accepts a POST request to update an asset
*
* @author [A. Gianotto] [<snipe@snipe.net>]
* @param Request $request
* @param \App\Http\Requests\ImageUploadRequest $request
* @since [v4.0]
* @return JsonResponse
*/
public function update(Request $request, $id)
public function update(ImageUploadRequest $request, $id)
{
$this->authorize('update', Asset::class);

Expand All @@ -558,32 +545,19 @@ public function update(Request $request, $id)
($request->filled('company_id')) ?
$asset->company_id = Company::getIdForCurrentUser($request->get('company_id')) : '';

($request->filled('rtd_location_id')) ?
$asset->location_id = $request->get('rtd_location_id') : null;


if ($request->filled('image_source')) {
if ($request->input('image_source') == "") {
($request->filled('rtd_location_id')) ?
$asset->location_id = $request->get('rtd_location_id') : null;
$asset->image = null;
} else {
$saved_image_path = Helper::processUploadedImage(
$request->input('image_source'), 'uploads/assets/'
);

if (!$saved_image_path) {
return response()->json(Helper::formatStandardApiResponse(
'error',
null,
trans('admin/hardware/message.update.error')
), 200);
}

$asset->image = $saved_image_path;
}
}
/**
* this is here just legacy reasons. Api\AssetController
* used image_source once to allow encoded image uploads.
*/
if ($request->has('image_source')) {
$request->offsetSet('image', $request->offsetGet('image_source'));
}

$asset = $request->handleImages($asset);

// Update custom fields
if (($model = AssetModel::find($asset->model_id)) && (isset($model->fieldset))) {
foreach ($model->fieldset->fields as $field) {
Expand Down
11 changes: 7 additions & 4 deletions app/Http/Controllers/Api/CategoriesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use App\Http\Transformers\SelectlistTransformer;
use App\Models\Category;
use Illuminate\Http\Request;
use App\Http\Requests\ImageUploadRequest;
use Illuminate\Support\Facades\Storage;

class CategoriesController extends Controller
Expand Down Expand Up @@ -54,14 +55,15 @@ public function index(Request $request)
*
* @author [A. Gianotto] [<snipe@snipe.net>]
* @since [v4.0]
* @param \Illuminate\Http\Request $request
* @param \App\Http\Requests\ImageUploadRequest $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
public function store(ImageUploadRequest $request)
{
$this->authorize('create', Category::class);
$category = new Category;
$category->fill($request->all());
$category = $request->handleImages($category);

if ($category->save()) {
return response()->json(Helper::formatStandardApiResponse('success', $category, trans('admin/categories/message.create.success')));
Expand Down Expand Up @@ -92,15 +94,16 @@ public function show($id)
*
* @author [A. Gianotto] [<snipe@snipe.net>]
* @since [v4.0]
* @param \Illuminate\Http\Request $request
* @param \App\Http\Requests\ImageUploadRequest $request
* @param int $id
* @return \Illuminate\Http\Response
*/
public function update(Request $request, $id)
public function update(ImageUploadRequest $request, $id)
{
$this->authorize('update', Category::class);
$category = Category::findOrFail($id);
$category->fill($request->all());
$category = $request->handleImages($category);

if ($category->save()) {
return response()->json(Helper::formatStandardApiResponse('success', $category, trans('admin/categories/message.update.success')));
Expand Down
13 changes: 8 additions & 5 deletions app/Http/Controllers/Api/CompaniesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use App\Http\Transformers\SelectlistTransformer;
use App\Models\Company;
use Illuminate\Http\Request;
use App\Http\Requests\ImageUploadRequest;
use Illuminate\Support\Facades\Storage;

class CompaniesController extends Controller
Expand Down Expand Up @@ -65,15 +66,16 @@ public function index(Request $request)
*
* @author [A. Gianotto] [<snipe@snipe.net>]
* @since [v4.0]
* @param \Illuminate\Http\Request $request
* @param \App\Http\Requests\ImageUploadRequest $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
public function store(ImageUploadRequest $request)
{
$this->authorize('create', Company::class);
$company = new Company;
$company->fill($request->all());

$company = $request->handleImages($company);

if ($company->save()) {
return response()->json(Helper::formatStandardApiResponse('success', (new CompaniesTransformer)->transformCompany($company), trans('admin/companies/message.create.success')));
}
Expand Down Expand Up @@ -104,15 +106,16 @@ public function show($id)
*
* @author [A. Gianotto] [<snipe@snipe.net>]
* @since [v4.0]
* @param \Illuminate\Http\Request $request
* @param \App\Http\Requests\ImageUploadRequest $request
* @param int $id
* @return \Illuminate\Http\Response
*/
public function update(Request $request, $id)
public function update(ImageUploadRequest $request, $id)
{
$this->authorize('update', Company::class);
$company = Company::findOrFail($id);
$company->fill($request->all());
$company = $request->handleImages($company);

if ($company->save()) {
return response()
Expand Down
12 changes: 8 additions & 4 deletions app/Http/Controllers/Api/ComponentsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use App\Models\Company;
use App\Models\Component;
use Illuminate\Http\Request;
use App\Http\Requests\ImageUploadRequest;
use App\Events\CheckoutableCheckedIn;
use App\Events\ComponentCheckedIn;
use App\Models\Asset;
Expand Down Expand Up @@ -81,14 +82,15 @@ public function index(Request $request)
*
* @author [A. Gianotto] [<snipe@snipe.net>]
* @since [v4.0]
* @param \Illuminate\Http\Request $request
* @param \App\Http\Requests\ImageUploadRequest $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
public function store(ImageUploadRequest $request)
{
$this->authorize('create', Component::class);
$component = new Component;
$component->fill($request->all());
$component = $request->handleImages($component);

if ($component->save()) {
return response()->json(Helper::formatStandardApiResponse('success', $component, trans('admin/components/message.create.success')));
Expand Down Expand Up @@ -119,15 +121,17 @@ public function show($id)
*
* @author [A. Gianotto] [<snipe@snipe.net>]
* @since [v4.0]
* @param \Illuminate\Http\Request $request
* @param \App\Http\Requests\ImageUploadRequest $request
* @param int $id
* @return \Illuminate\Http\Response
*/
public function update(Request $request, $id)
public function update(ImageUploadRequest $request, $id)
{
$this->authorize('update', Component::class);
$component = Component::findOrFail($id);
$component->fill($request->all());
$component = $request->handleImages($component);


if ($component->save()) {
return response()->json(Helper::formatStandardApiResponse('success', $component, trans('admin/components/message.update.success')));
Expand Down
13 changes: 8 additions & 5 deletions app/Http/Controllers/Api/ConsumablesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use App\Models\Consumable;
use App\Models\User;
use Illuminate\Http\Request;
use App\Http\Requests\ImageUploadRequest;

class ConsumablesController extends Controller
{
Expand Down Expand Up @@ -90,14 +91,15 @@ public function index(Request $request)
*
* @author [A. Gianotto] [<snipe@snipe.net>]
* @since [v4.0]
* @param \Illuminate\Http\Request $request
* @param \App\Http\Requests\ImageUploadRequest $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
public function store(ImageUploadRequest $request)
{
$this->authorize('create', Consumable::class);
$consumable = new Consumable;
$consumable->fill($request->all());
$consumable = $request->handleImages($consumable);

if ($consumable->save()) {
return response()->json(Helper::formatStandardApiResponse('success', $consumable, trans('admin/consumables/message.create.success')));
Expand Down Expand Up @@ -125,16 +127,17 @@ public function show($id)
*
* @author [A. Gianotto] [<snipe@snipe.net>]
* @since [v4.0]
* @param \Illuminate\Http\Request $request
* @param \App\Http\Requests\ImageUploadRequest $request
* @param int $id
* @return \Illuminate\Http\Response
*/
public function update(Request $request, $id)
public function update(ImageUploadRequest $request, $id)
{
$this->authorize('update', Consumable::class);
$consumable = Consumable::findOrFail($id);
$consumable->fill($request->all());

$consumable = $request->handleImages($consumable);

if ($consumable->save()) {
return response()->json(Helper::formatStandardApiResponse('success', $consumable, trans('admin/consumables/message.update.success')));
}
Expand Down
Loading