2016-03-25 01:18:05 -07:00
|
|
|
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
2018-07-16 20:09:53 -07:00
|
|
|
use App\Http\Requests\AssetFileRequest;
|
2016-03-25 01:18:05 -07:00
|
|
|
use Assets;
|
2016-12-26 15:19:04 -08:00
|
|
|
use Illuminate\Support\Facades\Session;
|
2016-03-25 01:18:05 -07:00
|
|
|
use Input;
|
|
|
|
use Lang;
|
|
|
|
use App\Models\License;
|
|
|
|
use App\Models\Asset;
|
|
|
|
use App\Models\User;
|
|
|
|
use App\Models\Actionlog;
|
|
|
|
use DB;
|
|
|
|
use App\Models\LicenseSeat;
|
|
|
|
use App\Models\Company;
|
|
|
|
use Validator;
|
|
|
|
use View;
|
|
|
|
use Response;
|
|
|
|
use Slack;
|
|
|
|
use Config;
|
|
|
|
use App\Helpers\Helper;
|
|
|
|
use Auth;
|
2016-08-02 00:54:38 -07:00
|
|
|
use Gate;
|
2016-12-15 12:48:15 -08:00
|
|
|
use Illuminate\Http\Request;
|
2016-03-25 01:18:05 -07:00
|
|
|
|
2016-04-07 13:21:09 -07:00
|
|
|
/**
|
|
|
|
* This controller handles all actions related to Licenses for
|
|
|
|
* the Snipe-IT Asset Management application.
|
|
|
|
*
|
|
|
|
* @version v1.0
|
|
|
|
*/
|
2016-03-25 01:18:05 -07:00
|
|
|
class LicensesController extends Controller
|
|
|
|
{
|
|
|
|
|
2016-03-25 17:20:28 -07:00
|
|
|
/**
|
|
|
|
* Returns a view that invokes the ajax tables which actually contains
|
|
|
|
* the content for the licenses listing, which is generated in getDatatable.
|
|
|
|
*
|
|
|
|
* @author [A. Gianotto] [<snipe@snipe.net>]
|
|
|
|
* @see LicensesController::getDatatable() method that generates the JSON response
|
|
|
|
* @since [v1.0]
|
2016-12-19 22:00:50 -08:00
|
|
|
* @return \Illuminate\Contracts\View\View
|
|
|
|
*/
|
2016-12-15 04:09:40 -08:00
|
|
|
public function index()
|
2016-03-25 01:18:05 -07:00
|
|
|
{
|
2016-12-19 11:04:28 -08:00
|
|
|
$this->authorize('view', License::class);
|
2017-06-09 16:44:03 -07:00
|
|
|
return view('licenses/index');
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2016-03-25 17:20:28 -07:00
|
|
|
* Returns a form view that allows an admin to create a new licence.
|
|
|
|
*
|
|
|
|
* @author [A. Gianotto] [<snipe@snipe.net>]
|
|
|
|
* @see AccessoriesController::getDatatable() method that generates the JSON response
|
|
|
|
* @since [v1.0]
|
2016-12-19 22:00:50 -08:00
|
|
|
* @return \Illuminate\Contracts\View\View
|
|
|
|
*/
|
2016-12-15 04:09:40 -08:00
|
|
|
public function create()
|
2016-03-25 01:18:05 -07:00
|
|
|
{
|
2016-12-19 11:04:28 -08:00
|
|
|
$this->authorize('create', License::class);
|
2016-12-19 22:00:50 -08:00
|
|
|
$maintained_list = [
|
|
|
|
'' => 'Maintained',
|
|
|
|
'1' => 'Yes',
|
|
|
|
'0' => 'No'
|
|
|
|
];
|
2016-03-25 01:18:05 -07:00
|
|
|
|
2017-06-09 16:44:03 -07:00
|
|
|
return view('licenses/edit')
|
2016-03-25 01:18:05 -07:00
|
|
|
//->with('license_options',$license_options)
|
2016-08-16 18:49:54 -07:00
|
|
|
->with('depreciation_list', Helper::depreciationList())
|
2016-03-25 01:18:05 -07:00
|
|
|
->with('maintained_list', $maintained_list)
|
Partialize forms (#2884)
* Consolidate edit form elements into reusable partials.
This is a large code change that doesn't do much immediately. It
refactors all of the various edit.blade.php files to reference
standardized partials, so that they all reference the same base html
layout. This has the side effect of moving everything to the new fancy
"required" indicators, and making things look consistent.
In addition, I've gone ahead and renamed a few database fields. We had
Assetmodel::modelno and Consumable::model_no, I've renamed both to
model_number. We had items using ::note and ::notes, I've standardized
on ::notes. Component used total_qty where consumables and accessories
used qty, so I've moved everything to qty (And fixed a few bugs in the
helper file in the process.
TODO includes looking at how/where to place the modal javascripts to
allow for on the fly creation from all places, rather than just the
asset page.
Rename assetmodel::modelno to model_number for clarity and consistency
Rename consumable::model_no to model_number for clarity and consistency
Rename assetmodel::note to notes for clarity and consistency
Port asset and assetmodel to new partials layout. Adapt all code to the renamed model_number and notes database changes. Fix some stying.
* Share a settings variable with all views.
* Allow editing the per_page setting. We showed the value, but we never showed it on the edit page..
* use snipeSettings in all views instead of the long ugly path.
* War on partials. Centralize all bootstrap table javascript
* Use model_number instead of modelno in importer
* Codacy fix.
* More unification/deduplication. Create an edit form template layout that we use as the base for all edit forms. This gives the same interface for editing everything and makes the edit.blade.* files much easier to read.
* Use a ViewComposer instead of sharing the variable directly. Fixes artisan optimize trying to hit the db--which ruins new installs
* Fix DB seeder.
* Base sql dump and csv's to import data from for tests.
* Start some functional tests for creating items.
* Add functional tests for all create methods. Still need to do tests for edits, deletes, and lots of other things
* Improvements to functional tests.
Use the built in DB seeding mechanism instead of doing it ourselves.
Break the tests into multiple units, rather than testing everything in
each function.
* Some improvements to acceptance tests.
Make sure we're only looking at the "trs" within the bootstrap table.
Creation of assets is now tested at the functional level (and is faster)
so ignore it here.
I'm testing acceptance tests with the
IMPORT_{ASSETS,ACCESSORIES,CONSUMABLES}.csv in the tests/_data folder
imported.
* A few things to make acceptance tests work. Add a name to the companies table, and make the locations table have the correct name
* Use a .env.tests file for testing functional and unit to allow a separate database.
* Add functional tests for compoents, groups, and licenses.
* Now that the config is in the functional.yml, this just confuses things.
* Start some functional tests for creating items.
* Add functional tests for all create methods. Still need to do tests for edits, deletes, and lots of other things
* Improvements to functional tests.
Use the built in DB seeding mechanism instead of doing it ourselves.
Break the tests into multiple units, rather than testing everything in
each function.
* Some improvements to acceptance tests.
Make sure we're only looking at the "trs" within the bootstrap table.
Creation of assets is now tested at the functional level (and is faster)
so ignore it here.
I'm testing acceptance tests with the
IMPORT_{ASSETS,ACCESSORIES,CONSUMABLES}.csv in the tests/_data folder
imported.
* update db dump
* Update tests to new reality
* env for the test setup
* only load the database at beginning of tests, not between each Functional test.
* Fix a miss from renaming note to notes.
* Set Termination date when creating an asset. It was only set on edit.
* Rename serial_number to serial in components for consistency.
* Update validation rules to match limits in database. Currently we just accepted the values and they were truncated when adding to DB.
* Much more detailed functional testing of creating items. This checks to make sure all values on form have been successfully persisted to database.
2016-11-16 16:56:57 -08:00
|
|
|
->with('item', new License);
|
2016-08-16 18:49:54 -07:00
|
|
|
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2016-12-19 22:00:50 -08:00
|
|
|
* Validates and stores the license form data submitted from the new
|
|
|
|
* license form.
|
|
|
|
*
|
|
|
|
* @author [A. Gianotto] [<snipe@snipe.net>]
|
|
|
|
* @see LicensesController::getCreate() method that provides the form view
|
|
|
|
* @since [v1.0]
|
|
|
|
* @param Request $request
|
|
|
|
* @return \Illuminate\Http\RedirectResponse
|
|
|
|
*/
|
2016-12-15 15:15:11 -08:00
|
|
|
public function store(Request $request)
|
2016-03-25 01:18:05 -07:00
|
|
|
{
|
2016-12-19 11:04:28 -08:00
|
|
|
$this->authorize('create', License::class);
|
2016-03-25 01:18:05 -07:00
|
|
|
// create a new model instance
|
|
|
|
$license = new License();
|
|
|
|
// Save the license data
|
2016-12-26 15:17:46 -08:00
|
|
|
$license->company_id = Company::getIdForCurrentUser($request->input('company_id'));
|
|
|
|
$license->depreciation_id = $request->input('depreciation_id');
|
|
|
|
$license->expiration_date = $request->input('expiration_date');
|
2016-12-19 22:00:50 -08:00
|
|
|
$license->license_email = $request->input('license_email');
|
|
|
|
$license->license_name = $request->input('license_name');
|
2016-12-26 15:17:46 -08:00
|
|
|
$license->maintained = $request->input('maintained', 0);
|
|
|
|
$license->manufacturer_id = $request->input('manufacturer_id');
|
|
|
|
$license->name = $request->input('name');
|
2016-12-19 22:00:50 -08:00
|
|
|
$license->notes = $request->input('notes');
|
|
|
|
$license->order_number = $request->input('order_number');
|
2016-12-26 15:17:46 -08:00
|
|
|
$license->purchase_cost = $request->input('purchase_cost');
|
2016-12-19 22:00:50 -08:00
|
|
|
$license->purchase_date = $request->input('purchase_date');
|
|
|
|
$license->purchase_order = $request->input('purchase_order');
|
2016-12-26 15:17:46 -08:00
|
|
|
$license->purchase_order = $request->input('purchase_order');
|
|
|
|
$license->reassignable = $request->input('reassignable', 0);
|
|
|
|
$license->seats = $request->input('seats');
|
|
|
|
$license->serial = $request->input('serial');
|
|
|
|
$license->supplier_id = $request->input('supplier_id');
|
2018-05-04 21:01:38 -07:00
|
|
|
$license->category_id = $request->input('category_id');
|
2016-12-19 22:00:50 -08:00
|
|
|
$license->termination_date = $request->input('termination_date');
|
|
|
|
$license->user_id = Auth::id();
|
2016-03-25 01:18:05 -07:00
|
|
|
|
|
|
|
if ($license->save()) {
|
2016-12-15 11:57:19 -08:00
|
|
|
return redirect()->route("licenses.index")->with('success', trans('admin/licenses/message.create.success'));
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|
2016-04-28 21:06:41 -07:00
|
|
|
return redirect()->back()->withInput()->withErrors($license->getErrors());
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-03-25 17:20:28 -07:00
|
|
|
* Returns a form with existing license data to allow an admin to
|
|
|
|
* update license information.
|
|
|
|
*
|
|
|
|
* @author [A. Gianotto] [<snipe@snipe.net>]
|
|
|
|
* @since [v1.0]
|
|
|
|
* @param int $licenseId
|
2016-12-19 22:00:50 -08:00
|
|
|
* @return \Illuminate\Contracts\View\View
|
|
|
|
*/
|
2016-12-15 04:09:40 -08:00
|
|
|
public function edit($licenseId = null)
|
2016-03-25 01:18:05 -07:00
|
|
|
{
|
Partialize forms (#2884)
* Consolidate edit form elements into reusable partials.
This is a large code change that doesn't do much immediately. It
refactors all of the various edit.blade.php files to reference
standardized partials, so that they all reference the same base html
layout. This has the side effect of moving everything to the new fancy
"required" indicators, and making things look consistent.
In addition, I've gone ahead and renamed a few database fields. We had
Assetmodel::modelno and Consumable::model_no, I've renamed both to
model_number. We had items using ::note and ::notes, I've standardized
on ::notes. Component used total_qty where consumables and accessories
used qty, so I've moved everything to qty (And fixed a few bugs in the
helper file in the process.
TODO includes looking at how/where to place the modal javascripts to
allow for on the fly creation from all places, rather than just the
asset page.
Rename assetmodel::modelno to model_number for clarity and consistency
Rename consumable::model_no to model_number for clarity and consistency
Rename assetmodel::note to notes for clarity and consistency
Port asset and assetmodel to new partials layout. Adapt all code to the renamed model_number and notes database changes. Fix some stying.
* Share a settings variable with all views.
* Allow editing the per_page setting. We showed the value, but we never showed it on the edit page..
* use snipeSettings in all views instead of the long ugly path.
* War on partials. Centralize all bootstrap table javascript
* Use model_number instead of modelno in importer
* Codacy fix.
* More unification/deduplication. Create an edit form template layout that we use as the base for all edit forms. This gives the same interface for editing everything and makes the edit.blade.* files much easier to read.
* Use a ViewComposer instead of sharing the variable directly. Fixes artisan optimize trying to hit the db--which ruins new installs
* Fix DB seeder.
* Base sql dump and csv's to import data from for tests.
* Start some functional tests for creating items.
* Add functional tests for all create methods. Still need to do tests for edits, deletes, and lots of other things
* Improvements to functional tests.
Use the built in DB seeding mechanism instead of doing it ourselves.
Break the tests into multiple units, rather than testing everything in
each function.
* Some improvements to acceptance tests.
Make sure we're only looking at the "trs" within the bootstrap table.
Creation of assets is now tested at the functional level (and is faster)
so ignore it here.
I'm testing acceptance tests with the
IMPORT_{ASSETS,ACCESSORIES,CONSUMABLES}.csv in the tests/_data folder
imported.
* A few things to make acceptance tests work. Add a name to the companies table, and make the locations table have the correct name
* Use a .env.tests file for testing functional and unit to allow a separate database.
* Add functional tests for compoents, groups, and licenses.
* Now that the config is in the functional.yml, this just confuses things.
* Start some functional tests for creating items.
* Add functional tests for all create methods. Still need to do tests for edits, deletes, and lots of other things
* Improvements to functional tests.
Use the built in DB seeding mechanism instead of doing it ourselves.
Break the tests into multiple units, rather than testing everything in
each function.
* Some improvements to acceptance tests.
Make sure we're only looking at the "trs" within the bootstrap table.
Creation of assets is now tested at the functional level (and is faster)
so ignore it here.
I'm testing acceptance tests with the
IMPORT_{ASSETS,ACCESSORIES,CONSUMABLES}.csv in the tests/_data folder
imported.
* update db dump
* Update tests to new reality
* env for the test setup
* only load the database at beginning of tests, not between each Functional test.
* Fix a miss from renaming note to notes.
* Set Termination date when creating an asset. It was only set on edit.
* Rename serial_number to serial in components for consistency.
* Update validation rules to match limits in database. Currently we just accepted the values and they were truncated when adding to DB.
* Much more detailed functional testing of creating items. This checks to make sure all values on form have been successfully persisted to database.
2016-11-16 16:56:57 -08:00
|
|
|
if (is_null($item = License::find($licenseId))) {
|
2016-12-15 04:09:40 -08:00
|
|
|
return redirect()->route('licenses.index')->with('error', trans('admin/licenses/message.does_not_exist'));
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|
|
|
|
|
2016-12-19 11:04:28 -08:00
|
|
|
$this->authorize('update', $item);
|
2016-03-25 01:18:05 -07:00
|
|
|
|
2016-12-19 22:00:50 -08:00
|
|
|
$maintained_list = [
|
|
|
|
'' => 'Maintained',
|
|
|
|
'1' => 'Yes',
|
|
|
|
'0' => 'No'
|
|
|
|
];
|
2016-03-25 01:18:05 -07:00
|
|
|
|
2017-06-09 16:44:03 -07:00
|
|
|
return view('licenses/edit', compact('item'))
|
2016-08-16 18:49:54 -07:00
|
|
|
->with('depreciation_list', Helper::depreciationList())
|
2017-10-28 09:21:39 -07:00
|
|
|
->with('maintained_list', $maintained_list);
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2016-12-19 22:00:50 -08:00
|
|
|
* Validates and stores the license form data submitted from the edit
|
|
|
|
* license form.
|
|
|
|
*
|
|
|
|
* @author [A. Gianotto] [<snipe@snipe.net>]
|
|
|
|
* @see LicensesController::getEdit() method that provides the form view
|
|
|
|
* @since [v1.0]
|
|
|
|
* @param Request $request
|
|
|
|
* @param int $licenseId
|
|
|
|
* @return \Illuminate\Http\RedirectResponse
|
|
|
|
*/
|
2016-12-15 12:48:15 -08:00
|
|
|
public function update(Request $request, $licenseId = null)
|
2016-03-25 01:18:05 -07:00
|
|
|
{
|
|
|
|
if (is_null($license = License::find($licenseId))) {
|
2016-12-15 04:09:40 -08:00
|
|
|
return redirect()->route('licenses.index')->with('error', trans('admin/licenses/message.does_not_exist'));
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|
|
|
|
|
2016-12-19 11:04:28 -08:00
|
|
|
$this->authorize('update', $license);
|
|
|
|
|
2016-12-26 15:17:46 -08:00
|
|
|
$license->company_id = Company::getIdForCurrentUser($request->input('company_id'));
|
|
|
|
$license->depreciation_id = $request->input('depreciation_id');
|
|
|
|
$license->expiration_date = $request->input('expiration_date');
|
2016-12-19 22:00:50 -08:00
|
|
|
$license->license_email = $request->input('license_email');
|
|
|
|
$license->license_name = $request->input('license_name');
|
2017-01-24 18:57:03 -08:00
|
|
|
$license->maintained = $request->input('maintained',0);
|
2016-12-26 15:17:46 -08:00
|
|
|
$license->name = $request->input('name');
|
2016-12-19 22:00:50 -08:00
|
|
|
$license->notes = $request->input('notes');
|
|
|
|
$license->order_number = $request->input('order_number');
|
2016-12-26 15:17:46 -08:00
|
|
|
$license->purchase_cost = $request->input('purchase_cost');
|
|
|
|
$license->purchase_date = $request->input('purchase_date');
|
2016-12-19 22:00:50 -08:00
|
|
|
$license->purchase_order = $request->input('purchase_order');
|
2017-01-24 18:57:03 -08:00
|
|
|
$license->reassignable = $request->input('reassignable', 0);
|
2019-05-08 05:14:49 -07:00
|
|
|
if (Gate::allows('viewKeys', $license)) {
|
|
|
|
$license->serial = $request->input('serial');
|
|
|
|
}
|
2016-12-26 15:17:46 -08:00
|
|
|
$license->termination_date = $request->input('termination_date');
|
2017-01-10 16:19:18 -08:00
|
|
|
$license->seats = e($request->input('seats'));
|
2017-01-24 18:57:03 -08:00
|
|
|
$license->manufacturer_id = $request->input('manufacturer_id');
|
2017-10-18 05:43:15 -07:00
|
|
|
$license->supplier_id = $request->input('supplier_id');
|
2018-05-04 21:01:38 -07:00
|
|
|
$license->category_id = $request->input('category_id');
|
2016-08-16 18:49:54 -07:00
|
|
|
|
2016-03-25 01:18:05 -07:00
|
|
|
if ($license->save()) {
|
2016-12-15 12:48:15 -08:00
|
|
|
return redirect()->route('licenses.show', ['license' => $licenseId])->with('success', trans('admin/licenses/message.update.success'));
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|
2017-01-10 16:19:18 -08:00
|
|
|
// If we can't adjust the number of seats, the error is flashed to the session by the event handler in License.php
|
|
|
|
return redirect()->back()->withInput()->withErrors($license->getErrors());
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-03-25 17:20:28 -07:00
|
|
|
* Checks to see whether the selected license can be deleted, and
|
|
|
|
* if it can, marks it as deleted.
|
|
|
|
*
|
|
|
|
* @author [A. Gianotto] [<snipe@snipe.net>]
|
|
|
|
* @since [v1.0]
|
|
|
|
* @param int $licenseId
|
2016-12-19 22:00:50 -08:00
|
|
|
* @return \Illuminate\Http\RedirectResponse
|
|
|
|
*/
|
2016-12-15 04:09:40 -08:00
|
|
|
public function destroy($licenseId)
|
2016-03-25 01:18:05 -07:00
|
|
|
{
|
|
|
|
// Check if the license exists
|
|
|
|
if (is_null($license = License::find($licenseId))) {
|
|
|
|
// Redirect to the license management page
|
2016-12-15 04:09:40 -08:00
|
|
|
return redirect()->route('licenses.index')->with('error', trans('admin/licenses/message.not_found'));
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|
|
|
|
|
2016-12-19 11:04:28 -08:00
|
|
|
$this->authorize('delete', $license);
|
2016-03-25 01:18:05 -07:00
|
|
|
|
2016-12-19 22:00:50 -08:00
|
|
|
if ($license->assigned_seats_count == 0) {
|
2016-03-25 01:18:05 -07:00
|
|
|
// Delete the license and the associated license seats
|
|
|
|
DB::table('license_seats')
|
2016-12-19 22:00:50 -08:00
|
|
|
->where('id', $license->id)
|
|
|
|
->update(array('assigned_to' => null,'asset_id' => null));
|
2016-03-25 01:18:05 -07:00
|
|
|
|
2016-12-19 22:00:50 -08:00
|
|
|
$licenseSeats = $license->licenseseats();
|
|
|
|
$licenseSeats->delete();
|
2016-03-25 01:18:05 -07:00
|
|
|
$license->delete();
|
|
|
|
|
|
|
|
// Redirect to the licenses management page
|
2016-12-15 04:09:40 -08:00
|
|
|
return redirect()->route('licenses.index')->with('success', trans('admin/licenses/message.delete.success'));
|
2016-12-19 22:00:50 -08:00
|
|
|
// Redirect to the license management page
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|
2016-12-19 22:00:50 -08:00
|
|
|
// There are still licenses in use.
|
|
|
|
return redirect()->route('licenses.index')->with('error', trans('admin/licenses/message.assoc_users'));
|
2016-03-25 01:18:05 -07:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-03-25 17:20:28 -07:00
|
|
|
* Provides the form view for checking out a license to a user.
|
|
|
|
* Here we pass the license seat ID instead of the license ID,
|
|
|
|
* because licenses themselves are never checked out to anyone,
|
|
|
|
* only the seats associated with them.
|
|
|
|
*
|
|
|
|
* @author [A. Gianotto] [<snipe@snipe.net>]
|
|
|
|
* @since [v1.0]
|
|
|
|
* @param int $seatId
|
2016-12-19 22:00:50 -08:00
|
|
|
* @return \Illuminate\Contracts\View\View
|
|
|
|
*/
|
2017-11-02 19:16:09 -07:00
|
|
|
public function getCheckout($licenceId)
|
2016-03-25 01:18:05 -07:00
|
|
|
{
|
2017-11-02 19:16:09 -07:00
|
|
|
// Check that the license is valid
|
|
|
|
if ($license = License::where('id',$licenceId)->first()) {
|
|
|
|
|
|
|
|
// If the license is valid, check that there is an available seat
|
|
|
|
if ($license->getAvailSeatsCountAttribute() < 1) {
|
|
|
|
return redirect()->route('licenses.index')->with('error', 'There are no available seats for this license');
|
|
|
|
}
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|
|
|
|
|
2017-11-02 19:16:09 -07:00
|
|
|
$this->authorize('checkout', $license);
|
|
|
|
return view('licenses/checkout', compact('license'));
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2016-12-19 22:00:50 -08:00
|
|
|
* Validates and stores the license checkout action.
|
|
|
|
*
|
|
|
|
* @todo Switch to using a FormRequest for validation here.
|
|
|
|
* @author [A. Gianotto] [<snipe@snipe.net>]
|
|
|
|
* @since [v1.0]
|
|
|
|
* @param Request $request
|
2018-07-23 20:28:45 -07:00
|
|
|
* @param int $licenseId
|
2016-12-19 22:00:50 -08:00
|
|
|
* @param int $seatId
|
|
|
|
* @return \Illuminate\Http\RedirectResponse
|
|
|
|
*/
|
2018-07-23 20:28:45 -07:00
|
|
|
public function postCheckout(Request $request, $licenseId, $seatId = null)
|
2016-03-25 01:18:05 -07:00
|
|
|
{
|
|
|
|
|
2017-11-02 19:16:09 -07:00
|
|
|
// Check that the license is valid
|
2018-07-23 20:28:45 -07:00
|
|
|
if ($license = License::where('id', $licenseId)->first()) {
|
|
|
|
|
2017-11-02 19:16:09 -07:00
|
|
|
// If the license is valid, check that there is an available seat
|
|
|
|
if ($license->getAvailSeatsCountAttribute() < 1) {
|
|
|
|
return redirect()->route('licenses.index')->with('error', 'There are no available seats for this license');
|
|
|
|
}
|
2018-07-23 20:28:45 -07:00
|
|
|
if (!$seatId) {
|
|
|
|
// Get the next available seat for this license
|
|
|
|
$next = $license->freeSeat();
|
|
|
|
if (!$next) {
|
|
|
|
return redirect()->route('licenses.index')->with('error', 'There are no available seats for this license');
|
|
|
|
}
|
|
|
|
if (!$licenseSeat = LicenseSeat::where('id', '=', $next->id)->first()) {
|
|
|
|
return redirect()->route('licenses.index')->with('error', 'There are no available seats for this license');
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$licenseSeat = LicenseSeat::where('id', '=', $seatId)->first();
|
|
|
|
if (!$licenseSeat) {
|
|
|
|
return redirect()->route('licenses.index')->with('error', 'License seat is not available for checkout');
|
|
|
|
}
|
2017-11-20 19:21:05 -08:00
|
|
|
}
|
2018-07-23 20:28:45 -07:00
|
|
|
|
2017-11-20 19:21:05 -08:00
|
|
|
|
2018-07-23 20:28:45 -07:00
|
|
|
|
2017-11-20 19:21:05 -08:00
|
|
|
|
2018-07-23 20:28:45 -07:00
|
|
|
|
2016-03-25 01:18:05 -07:00
|
|
|
|
2017-12-05 15:04:10 -08:00
|
|
|
$this->authorize('checkout', $license);
|
2017-11-02 19:16:09 -07:00
|
|
|
|
|
|
|
// Declare the rules for the form validation
|
|
|
|
$rules = [
|
|
|
|
'note' => 'string|nullable',
|
|
|
|
'asset_id' => 'required_without:assigned_to',
|
|
|
|
];
|
|
|
|
|
|
|
|
// Create a new validator instance from our validation rules
|
|
|
|
$validator = Validator::make(Input::all(), $rules);
|
|
|
|
|
|
|
|
// If validation fails, we'll exit the operation now.
|
|
|
|
if ($validator->fails()) {
|
|
|
|
// Ooops.. something went wrong
|
|
|
|
return redirect()->back()->withInput()->withErrors($validator);
|
|
|
|
}
|
|
|
|
$target = null;
|
2017-11-20 19:21:05 -08:00
|
|
|
|
2016-07-07 01:13:31 -07:00
|
|
|
|
2017-11-22 07:31:38 -08:00
|
|
|
// This item is checked out to a an asset
|
|
|
|
if (request('checkout_to_type')=='asset') {
|
|
|
|
if (is_null($target = Asset::find(request('asset_id')))) {
|
2017-11-02 19:16:09 -07:00
|
|
|
return redirect()->route('licenses.index')->with('error', trans('admin/licenses/message.asset_does_not_exist'));
|
|
|
|
}
|
2017-11-22 07:31:38 -08:00
|
|
|
$licenseSeat->asset_id = $request->input('asset_id');
|
2017-11-02 19:16:09 -07:00
|
|
|
|
2017-11-22 07:31:38 -08:00
|
|
|
// Override asset's assigned user if available
|
2017-12-12 05:43:06 -08:00
|
|
|
if ($target->checkedOutToUser()) {
|
2017-11-22 07:31:38 -08:00
|
|
|
$licenseSeat->assigned_to = $target->assigned_to;
|
2017-11-02 19:16:09 -07:00
|
|
|
}
|
2016-03-25 01:18:05 -07:00
|
|
|
|
2017-11-02 19:16:09 -07:00
|
|
|
} else {
|
2016-03-25 01:18:05 -07:00
|
|
|
|
2017-11-22 07:31:38 -08:00
|
|
|
// Fetch the target and set the license user
|
|
|
|
if (is_null($target = User::find(request('assigned_to')))) {
|
|
|
|
return redirect()->route('licenses.index')->with('error', trans('admin/licenses/message.user_does_not_exist'));
|
|
|
|
}
|
|
|
|
$licenseSeat->assigned_to = request('assigned_to');
|
2017-11-02 19:16:09 -07:00
|
|
|
}
|
|
|
|
|
2017-11-20 19:21:05 -08:00
|
|
|
$licenseSeat->user_id = Auth::user()->id;
|
|
|
|
|
2017-11-22 07:31:38 -08:00
|
|
|
|
2017-11-02 19:16:09 -07:00
|
|
|
if ($licenseSeat->save()) {
|
|
|
|
$licenseSeat->logCheckout($request->input('note'), $target);
|
|
|
|
return redirect()->route("licenses.index")->with('success', trans('admin/licenses/message.checkout.success'));
|
|
|
|
}
|
2016-03-25 01:18:05 -07:00
|
|
|
|
|
|
|
}
|
2017-11-02 19:16:09 -07:00
|
|
|
return redirect()->route('licenses.index')->with('error', trans('admin/licenses/message.not_found'));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-09-29 04:37:33 -07:00
|
|
|
return redirect()->route("licenses.index")->with('error', trans('admin/licenses/message.checkout.error'));
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2016-03-25 17:20:28 -07:00
|
|
|
* Makes the form view to check a license seat back into inventory.
|
|
|
|
*
|
|
|
|
* @author [A. Gianotto] [<snipe@snipe.net>]
|
|
|
|
* @since [v1.0]
|
|
|
|
* @param int $seatId
|
2016-12-19 22:00:50 -08:00
|
|
|
* @param string $backTo
|
|
|
|
* @return \Illuminate\Contracts\View\View
|
|
|
|
*/
|
|
|
|
public function getCheckin($seatId = null, $backTo = null)
|
2016-03-25 01:18:05 -07:00
|
|
|
{
|
|
|
|
// Check if the asset exists
|
2017-10-01 15:08:32 -07:00
|
|
|
if (is_null($licenseSeat = LicenseSeat::find($seatId))) {
|
2016-03-25 01:18:05 -07:00
|
|
|
// Redirect to the asset management page with error
|
2016-12-15 04:09:40 -08:00
|
|
|
return redirect()->route('licenses.index')->with('error', trans('admin/licenses/message.not_found'));
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|
2017-12-08 14:33:12 -08:00
|
|
|
|
|
|
|
if (is_null($license = License::find($licenseSeat->license_id))) {
|
|
|
|
// Redirect to the asset management page with error
|
|
|
|
return redirect()->route('licenses.index')->with('error', trans('admin/licenses/message.not_found'));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$this->authorize('checkout', $license);
|
2017-10-01 15:08:32 -07:00
|
|
|
return view('licenses/checkin', compact('licenseSeat'))->with('backto', $backTo);
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2016-03-25 17:20:28 -07:00
|
|
|
* Validates and stores the license checkin action.
|
|
|
|
*
|
|
|
|
* @author [A. Gianotto] [<snipe@snipe.net>]
|
|
|
|
* @see LicensesController::getCheckin() method that provides the form view
|
|
|
|
* @since [v1.0]
|
|
|
|
* @param int $seatId
|
2016-12-19 22:00:50 -08:00
|
|
|
* @param string $backTo
|
|
|
|
* @return \Illuminate\Http\RedirectResponse
|
|
|
|
*/
|
|
|
|
public function postCheckin($seatId = null, $backTo = null)
|
2016-03-25 01:18:05 -07:00
|
|
|
{
|
|
|
|
// Check if the asset exists
|
2016-12-19 22:00:50 -08:00
|
|
|
if (is_null($licenseSeat = LicenseSeat::find($seatId))) {
|
2016-03-25 01:18:05 -07:00
|
|
|
// Redirect to the asset management page with error
|
2016-12-15 04:09:40 -08:00
|
|
|
return redirect()->route('licenses.index')->with('error', trans('admin/licenses/message.not_found'));
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|
|
|
|
|
2016-12-19 22:00:50 -08:00
|
|
|
$license = License::find($licenseSeat->license_id);
|
2017-12-08 14:33:12 -08:00
|
|
|
$this->authorize('checkout', $license);
|
2016-03-25 01:18:05 -07:00
|
|
|
|
|
|
|
if (!$license->reassignable) {
|
|
|
|
// Not allowed to checkin
|
|
|
|
Session::flash('error', 'License not reassignable.');
|
2016-04-28 21:06:41 -07:00
|
|
|
return redirect()->back()->withInput();
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|
|
|
|
|
2019-05-02 15:20:47 -07:00
|
|
|
|
2016-12-19 22:00:50 -08:00
|
|
|
$return_to = User::find($licenseSeat->assigned_to);
|
2016-11-17 15:54:29 -08:00
|
|
|
if (!$return_to) {
|
2016-12-19 22:00:50 -08:00
|
|
|
$return_to = Asset::find($licenseSeat->asset_id);
|
2016-11-17 15:54:29 -08:00
|
|
|
}
|
2018-03-25 13:46:57 -07:00
|
|
|
|
2016-03-25 01:18:05 -07:00
|
|
|
// Update the asset data
|
2016-12-19 22:00:50 -08:00
|
|
|
$licenseSeat->assigned_to = null;
|
|
|
|
$licenseSeat->asset_id = null;
|
2016-03-25 01:18:05 -07:00
|
|
|
|
|
|
|
// Was the asset updated?
|
2016-12-19 22:00:50 -08:00
|
|
|
if ($licenseSeat->save()) {
|
2019-05-02 15:20:47 -07:00
|
|
|
$licenseSeat->logCheckin($license, e(request('note')));
|
2016-12-19 22:00:50 -08:00
|
|
|
if ($backTo=='user') {
|
|
|
|
return redirect()->route("users.show", $return_to->id)->with('success', trans('admin/licenses/message.checkin.success'));
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|
2016-12-26 15:19:04 -08:00
|
|
|
return redirect()->route("licenses.show", $licenseSeat->license_id)->with('success', trans('admin/licenses/message.checkin.success'));
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Redirect to the license page with error
|
2016-12-15 11:57:19 -08:00
|
|
|
return redirect()->route("licenses.index")->with('error', trans('admin/licenses/message.checkin.error'));
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-03-25 17:20:28 -07:00
|
|
|
* Makes the license detail page.
|
2016-03-25 01:18:05 -07:00
|
|
|
*
|
2016-03-25 17:20:28 -07:00
|
|
|
* @author [A. Gianotto] [<snipe@snipe.net>]
|
|
|
|
* @since [v1.0]
|
|
|
|
* @param int $licenseId
|
2016-12-19 22:00:50 -08:00
|
|
|
* @return \Illuminate\Contracts\View\View
|
|
|
|
*/
|
2016-12-15 11:57:19 -08:00
|
|
|
public function show($licenseId = null)
|
2016-03-25 01:18:05 -07:00
|
|
|
{
|
|
|
|
|
2017-10-19 03:37:27 -07:00
|
|
|
$license = License::with('assignedusers', 'licenseSeats.user', 'licenseSeats.asset')->find($licenseId);
|
2016-03-25 01:18:05 -07:00
|
|
|
|
2017-10-19 03:37:27 -07:00
|
|
|
if ($license) {
|
2016-12-19 11:04:28 -08:00
|
|
|
$this->authorize('view', $license);
|
2017-06-09 16:44:03 -07:00
|
|
|
return view('licenses/view', compact('license'));
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|
2017-10-19 03:37:27 -07:00
|
|
|
return redirect()->route('licenses.index')->with('error', trans('admin/licenses/message.does_not_exist', compact('id')));
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|
2017-10-19 03:37:27 -07:00
|
|
|
|
2016-03-25 01:18:05 -07:00
|
|
|
|
|
|
|
public function getClone($licenseId = null)
|
|
|
|
{
|
|
|
|
if (is_null($license_to_clone = License::find($licenseId))) {
|
2016-12-15 04:09:40 -08:00
|
|
|
return redirect()->route('licenses.index')->with('error', trans('admin/licenses/message.does_not_exist'));
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|
|
|
|
|
2016-12-19 11:04:28 -08:00
|
|
|
$this->authorize('create', License::class);
|
|
|
|
|
2016-12-19 22:00:50 -08:00
|
|
|
$maintained_list = [
|
|
|
|
'' => 'Maintained',
|
|
|
|
'1' => 'Yes',
|
|
|
|
'0' => 'No'
|
|
|
|
];
|
2016-03-25 01:18:05 -07:00
|
|
|
//clone the orig
|
|
|
|
$license = clone $license_to_clone;
|
|
|
|
$license->id = null;
|
|
|
|
$license->serial = null;
|
|
|
|
|
|
|
|
// Show the page
|
2017-06-09 16:44:03 -07:00
|
|
|
return view('licenses/edit')
|
2016-12-19 22:00:50 -08:00
|
|
|
->with('depreciation_list', Helper::depreciationList())
|
Partialize forms (#2884)
* Consolidate edit form elements into reusable partials.
This is a large code change that doesn't do much immediately. It
refactors all of the various edit.blade.php files to reference
standardized partials, so that they all reference the same base html
layout. This has the side effect of moving everything to the new fancy
"required" indicators, and making things look consistent.
In addition, I've gone ahead and renamed a few database fields. We had
Assetmodel::modelno and Consumable::model_no, I've renamed both to
model_number. We had items using ::note and ::notes, I've standardized
on ::notes. Component used total_qty where consumables and accessories
used qty, so I've moved everything to qty (And fixed a few bugs in the
helper file in the process.
TODO includes looking at how/where to place the modal javascripts to
allow for on the fly creation from all places, rather than just the
asset page.
Rename assetmodel::modelno to model_number for clarity and consistency
Rename consumable::model_no to model_number for clarity and consistency
Rename assetmodel::note to notes for clarity and consistency
Port asset and assetmodel to new partials layout. Adapt all code to the renamed model_number and notes database changes. Fix some stying.
* Share a settings variable with all views.
* Allow editing the per_page setting. We showed the value, but we never showed it on the edit page..
* use snipeSettings in all views instead of the long ugly path.
* War on partials. Centralize all bootstrap table javascript
* Use model_number instead of modelno in importer
* Codacy fix.
* More unification/deduplication. Create an edit form template layout that we use as the base for all edit forms. This gives the same interface for editing everything and makes the edit.blade.* files much easier to read.
* Use a ViewComposer instead of sharing the variable directly. Fixes artisan optimize trying to hit the db--which ruins new installs
* Fix DB seeder.
* Base sql dump and csv's to import data from for tests.
* Start some functional tests for creating items.
* Add functional tests for all create methods. Still need to do tests for edits, deletes, and lots of other things
* Improvements to functional tests.
Use the built in DB seeding mechanism instead of doing it ourselves.
Break the tests into multiple units, rather than testing everything in
each function.
* Some improvements to acceptance tests.
Make sure we're only looking at the "trs" within the bootstrap table.
Creation of assets is now tested at the functional level (and is faster)
so ignore it here.
I'm testing acceptance tests with the
IMPORT_{ASSETS,ACCESSORIES,CONSUMABLES}.csv in the tests/_data folder
imported.
* A few things to make acceptance tests work. Add a name to the companies table, and make the locations table have the correct name
* Use a .env.tests file for testing functional and unit to allow a separate database.
* Add functional tests for compoents, groups, and licenses.
* Now that the config is in the functional.yml, this just confuses things.
* Start some functional tests for creating items.
* Add functional tests for all create methods. Still need to do tests for edits, deletes, and lots of other things
* Improvements to functional tests.
Use the built in DB seeding mechanism instead of doing it ourselves.
Break the tests into multiple units, rather than testing everything in
each function.
* Some improvements to acceptance tests.
Make sure we're only looking at the "trs" within the bootstrap table.
Creation of assets is now tested at the functional level (and is faster)
so ignore it here.
I'm testing acceptance tests with the
IMPORT_{ASSETS,ACCESSORIES,CONSUMABLES}.csv in the tests/_data folder
imported.
* update db dump
* Update tests to new reality
* env for the test setup
* only load the database at beginning of tests, not between each Functional test.
* Fix a miss from renaming note to notes.
* Set Termination date when creating an asset. It was only set on edit.
* Rename serial_number to serial in components for consistency.
* Update validation rules to match limits in database. Currently we just accepted the values and they were truncated when adding to DB.
* Much more detailed functional testing of creating items. This checks to make sure all values on form have been successfully persisted to database.
2016-11-16 16:56:57 -08:00
|
|
|
->with('item', $license)
|
2017-10-28 09:21:39 -07:00
|
|
|
->with('maintained_list', $maintained_list);
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2016-03-25 17:20:28 -07:00
|
|
|
* Validates and stores files associated with a license.
|
2016-03-25 01:18:05 -07:00
|
|
|
*
|
2016-03-25 17:20:28 -07:00
|
|
|
* @todo Switch to using the AssetFileRequest form request validator.
|
|
|
|
* @author [A. Gianotto] [<snipe@snipe.net>]
|
|
|
|
* @since [v1.0]
|
|
|
|
* @param int $licenseId
|
2016-12-19 22:00:50 -08:00
|
|
|
* @return \Illuminate\Http\RedirectResponse
|
|
|
|
*/
|
2018-07-16 20:09:53 -07:00
|
|
|
public function postUpload(AssetFileRequest $request, $licenseId = null)
|
2016-03-25 01:18:05 -07:00
|
|
|
{
|
|
|
|
$license = License::find($licenseId);
|
|
|
|
// the license is valid
|
2016-03-25 15:50:08 -07:00
|
|
|
$destinationPath = config('app.private_uploads').'/licenses';
|
2016-03-25 01:18:05 -07:00
|
|
|
|
|
|
|
if (isset($license->id)) {
|
2016-12-19 11:04:28 -08:00
|
|
|
$this->authorize('update', $license);
|
2016-03-25 01:18:05 -07:00
|
|
|
|
2018-07-16 20:09:53 -07:00
|
|
|
if (Input::hasFile('file')) {
|
2016-03-25 01:18:05 -07:00
|
|
|
|
2018-07-16 20:09:53 -07:00
|
|
|
foreach (Input::file('file') as $file) {
|
2016-12-19 11:04:28 -08:00
|
|
|
$extension = $file->getClientOriginalExtension();
|
2018-05-02 14:13:06 -07:00
|
|
|
$filename = 'license-'.$license->id.'-'.str_random(8).'-'.str_slug(basename($file->getClientOriginalName(), '.'.$extension)).'.'.$extension;
|
2016-12-19 11:04:28 -08:00
|
|
|
$upload_success = $file->move($destinationPath, $filename);
|
2016-03-25 01:18:05 -07:00
|
|
|
|
2016-12-19 11:04:28 -08:00
|
|
|
//Log the upload to the log
|
2016-12-29 14:02:18 -08:00
|
|
|
$license->logUpload($filename, e($request->input('notes')));
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|
2017-10-01 12:57:04 -07:00
|
|
|
// This being called from a modal seems to confuse redirect()->back()
|
|
|
|
// It thinks we should go to the dashboard. As this is only used
|
|
|
|
// from the modal at present, hardcode the redirect. Longterm
|
|
|
|
// maybe we evaluate something else.
|
2016-03-25 01:18:05 -07:00
|
|
|
if ($upload_success) {
|
2017-10-01 12:57:04 -07:00
|
|
|
return redirect()->route('licenses.show', $license->id)->with('success', trans('admin/licenses/message.upload.success'));
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|
2017-10-01 12:57:04 -07:00
|
|
|
return redirect()->route('licenses.show', $license->id)->with('error', trans('admin/licenses/message.upload.error'));
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|
2017-10-01 12:57:04 -07:00
|
|
|
return redirect()->route('licenses.show', $license->id)->with('error', trans('admin/licenses/message.upload.nofiles'));
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|
2016-12-19 11:04:28 -08:00
|
|
|
// Prepare the error message
|
|
|
|
$error = trans('admin/licenses/message.does_not_exist', compact('id'));
|
|
|
|
return redirect()->route('licenses.index')->with('error', $error);
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2016-03-25 17:20:28 -07:00
|
|
|
* Deletes the selected license file.
|
2016-03-25 01:18:05 -07:00
|
|
|
*
|
2016-03-25 17:20:28 -07:00
|
|
|
* @author [A. Gianotto] [<snipe@snipe.net>]
|
|
|
|
* @since [v1.0]
|
|
|
|
* @param int $licenseId
|
|
|
|
* @param int $fileId
|
2016-12-19 22:00:50 -08:00
|
|
|
* @return \Illuminate\Http\RedirectResponse
|
|
|
|
*/
|
2016-03-25 01:18:05 -07:00
|
|
|
public function getDeleteFile($licenseId = null, $fileId = null)
|
|
|
|
{
|
|
|
|
$license = License::find($licenseId);
|
2016-03-25 15:50:08 -07:00
|
|
|
$destinationPath = config('app.private_uploads').'/licenses';
|
2016-03-25 01:18:05 -07:00
|
|
|
|
|
|
|
// the license is valid
|
2019-05-24 05:26:52 -07:00
|
|
|
if ($license) {
|
2016-12-19 11:04:28 -08:00
|
|
|
$this->authorize('edit', $license);
|
2016-03-25 01:18:05 -07:00
|
|
|
$log = Actionlog::find($fileId);
|
2019-05-24 15:44:40 -07:00
|
|
|
if ($log) {
|
|
|
|
$full_filename = $destinationPath.'/'.$log->filename;
|
|
|
|
if (file_exists($full_filename)) {
|
|
|
|
unlink($destinationPath.'/'.$log->filename);
|
|
|
|
}
|
|
|
|
$log->delete();
|
|
|
|
return redirect()->back()->with('success', trans('admin/licenses/message.deletefile.success'));
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|
2019-05-24 15:44:40 -07:00
|
|
|
|
|
|
|
return redirect()->back()->with('error', 'Could not locate that file.');
|
|
|
|
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|
2016-12-19 11:04:28 -08:00
|
|
|
|
|
|
|
// Redirect to the licence management page
|
2019-05-24 15:44:40 -07:00
|
|
|
return redirect()->route('licenses.index')->with('error', trans('admin/licenses/message.does_not_exist', compact('id')));
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2016-03-25 17:20:28 -07:00
|
|
|
* Allows the selected file to be viewed.
|
2016-03-25 01:18:05 -07:00
|
|
|
*
|
2016-03-25 17:20:28 -07:00
|
|
|
* @author [A. Gianotto] [<snipe@snipe.net>]
|
|
|
|
* @since [v1.4]
|
|
|
|
* @param int $licenseId
|
|
|
|
* @param int $fileId
|
2016-12-19 22:00:50 -08:00
|
|
|
* @return \Symfony\Component\HttpFoundation\BinaryFileResponse
|
|
|
|
*/
|
2018-05-02 14:13:06 -07:00
|
|
|
public function displayFile($licenseId = null, $fileId = null, $download = true)
|
2016-03-25 01:18:05 -07:00
|
|
|
{
|
|
|
|
|
|
|
|
$license = License::find($licenseId);
|
|
|
|
|
|
|
|
// the license is valid
|
|
|
|
if (isset($license->id)) {
|
2016-12-19 11:04:28 -08:00
|
|
|
$this->authorize('view', $license);
|
|
|
|
$log = Actionlog::find($fileId);
|
2018-05-02 14:13:06 -07:00
|
|
|
|
2019-05-24 16:06:52 -07:00
|
|
|
if ($log) {
|
2018-05-02 14:13:06 -07:00
|
|
|
|
2019-05-24 16:06:52 -07:00
|
|
|
$file = $log->get_src('licenses');
|
|
|
|
if ($file =='') {
|
|
|
|
return response('File not found on server', 404)
|
|
|
|
->header('Content-Type', 'text/plain');
|
|
|
|
}
|
2018-05-02 14:13:06 -07:00
|
|
|
|
2019-05-24 16:06:52 -07:00
|
|
|
$mimetype = \File::mimeType($file);
|
2018-05-02 14:13:06 -07:00
|
|
|
|
2019-05-24 16:06:52 -07:00
|
|
|
if (!file_exists($file)) {
|
|
|
|
return response('File '.$file.' not found on server', 404)
|
|
|
|
->header('Content-Type', 'text/plain');
|
|
|
|
}
|
2018-05-02 14:13:06 -07:00
|
|
|
|
2019-05-24 16:06:52 -07:00
|
|
|
if ($download != 'true') {
|
|
|
|
if ($contents = file_get_contents($file)) {
|
|
|
|
return Response::make($contents)->header('Content-Type', $mimetype);
|
|
|
|
}
|
|
|
|
return JsonResponse::create(["error" => "Failed validation: "], 500);
|
2018-05-02 14:13:06 -07:00
|
|
|
}
|
2019-05-24 16:06:52 -07:00
|
|
|
return Response::download($file);
|
2018-05-02 14:13:06 -07:00
|
|
|
}
|
2019-05-24 16:06:52 -07:00
|
|
|
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|
2018-05-02 14:13:06 -07:00
|
|
|
|
|
|
|
|
2017-10-07 06:56:02 -07:00
|
|
|
return redirect()->route('licenses.index')->with('error', trans('admin/licenses/message.does_not_exist', compact('id')));
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|
|
|
|
|
2016-03-25 17:20:28 -07:00
|
|
|
|
2016-03-25 01:18:05 -07:00
|
|
|
|
2016-03-25 17:20:28 -07:00
|
|
|
/**
|
|
|
|
* Generates the next free seat ID for checkout.
|
|
|
|
*
|
|
|
|
* @todo This is a dumb way to solve this problem.
|
|
|
|
* Author should refactor. And go hide in a hole and
|
|
|
|
* think about what she's done. And perhaps find a new
|
|
|
|
* line of work. And get in the sea.
|
|
|
|
*
|
|
|
|
* @author [A. Gianotto] [<snipe@snipe.net>]
|
|
|
|
* @since [v1.0]
|
|
|
|
* @param int $licenseId
|
2016-12-19 22:00:50 -08:00
|
|
|
* @return \Illuminate\Http\RedirectResponse
|
|
|
|
*/
|
2016-03-25 01:18:05 -07:00
|
|
|
public function getFreeLicense($licenseId)
|
|
|
|
{
|
2016-12-19 11:04:28 -08:00
|
|
|
$this->authorize('checkout', License::class);
|
2016-03-25 01:18:05 -07:00
|
|
|
if (is_null($license = License::find($licenseId))) {
|
2016-12-15 04:09:40 -08:00
|
|
|
return redirect()->route('licenses.index')->with('error', trans('admin/licenses/message.not_found'));
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|
|
|
|
$seatId = $license->freeSeat($licenseId);
|
2016-12-15 13:07:34 -08:00
|
|
|
return redirect()->route('licenses.checkout', $seatId);
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|
|
|
|
}
|