2016-03-25 01:18:05 -07:00
< ? php
namespace App\Models ;
2018-07-21 05:01:30 -07:00
use App\Events\AssetCheckedOut ;
2018-09-10 07:40:26 -07:00
use App\Events\CheckoutableCheckedOut ;
2018-07-05 19:30:36 -07:00
use App\Http\Traits\UniqueSerialTrait ;
2016-09-06 19:39:42 -07:00
use App\Http\Traits\UniqueUndeletedTrait ;
2018-07-28 04:09:21 -07:00
use App\Models\Traits\Acceptable ;
2018-07-16 14:13:07 -07:00
use App\Models\Traits\Searchable ;
2016-12-23 17:52:00 -08:00
use App\Presenters\Presentable ;
use AssetPresenter ;
2016-09-06 19:39:42 -07:00
use Auth ;
2016-12-23 17:52:00 -08:00
use Carbon\Carbon ;
2019-03-13 20:12:03 -07:00
use DB ;
2018-07-16 14:13:07 -07:00
use Illuminate\Database\Eloquent\Builder ;
2016-03-25 01:18:05 -07:00
use Illuminate\Database\Eloquent\SoftDeletes ;
2018-09-29 21:33:52 -07:00
use Illuminate\Support\Facades\Storage ;
2019-03-13 20:12:03 -07:00
use Watson\Validating\ValidatingTrait ;
2016-04-07 13:21:09 -07:00
/**
* Model for Assets .
*
* @ version v1 . 0
*/
2016-03-25 01:18:05 -07:00
class Asset extends Depreciable
{
2016-12-23 17:52:00 -08:00
protected $presenter = 'App\Presenters\AssetPresenter' ;
2018-07-05 19:30:36 -07:00
use Loggable , Requestable , Presentable , SoftDeletes , ValidatingTrait , UniqueUndeletedTrait , UniqueSerialTrait ;
2016-03-25 01:18:05 -07:00
2016-12-27 16:24:41 -08:00
const LOCATION = 'location' ;
const ASSET = 'asset' ;
const USER = 'user' ;
2018-03-25 13:46:57 -07:00
2018-07-28 04:09:21 -07:00
use Acceptable ;
2018-03-25 13:46:57 -07:00
/**
2018-07-28 04:09:21 -07:00
* Run after the checkout acceptance was declined by the user
2018-07-27 16:16:42 -07:00
*
2018-07-28 04:09:21 -07:00
* @ param User $acceptedBy
* @ param string $signature
*/
public function declinedCheckout ( User $declinedBy , $signature ) {
2018-07-27 16:16:42 -07:00
$this -> assigned_to = null ;
$this -> assigned_type = null ;
$this -> accepted = null ;
2018-07-28 04:09:21 -07:00
$this -> save ();
2018-07-27 16:16:42 -07:00
}
2018-03-25 13:46:57 -07:00
/**
* The database table used by the model .
*
* @ var string
*/
2016-03-25 01:18:05 -07:00
protected $table = 'assets' ;
2018-03-25 13:46:57 -07:00
/**
* Whether the model should inject it ' s identifier to the unique
* validation rules before attempting validation . If this property
* is not set in the model it will default to true .
*
* @ var boolean
*/
2016-03-25 01:18:05 -07:00
protected $injectUniqueIdentifier = true ;
2017-03-03 17:30:19 -08:00
2017-11-08 18:03:27 -08:00
// We set these as protected dates so that they will be easily accessible via Carbon
2017-03-03 17:30:19 -08:00
protected $dates = [
'created_at' ,
'updated_at' ,
'deleted_at' ,
'purchase_date' ,
'last_checkout' ,
2017-12-12 03:03:43 -08:00
'expected_checkin' ,
'last_audit_date' ,
'next_audit_date'
2017-03-03 17:30:19 -08:00
];
2016-03-25 01:18:05 -07:00
protected $rules = [
2017-03-31 13:48:11 -07:00
'name' => 'max:255|nullable' ,
'model_id' => 'required|integer|exists:models,id' ,
'status_id' => 'required|integer|exists:status_labels,id' ,
'company_id' => 'integer|nullable' ,
Integrations/develop into master (#7352)
* Fixes #6204 - added email alerts and web/API access to assets due for audits (#6992)
* Added upcoming audit report
TODO: Fid diff/threshold math
* Added route to list overdue / upcoming assets via API
* Controller/API methods for due/overdue audits
We could probably skip this and just handle it via view in the routes…
* Added query scopes for due and overdue audits
* Added audit due console command to kernel
* Added ability to pass audit specs to main API asset search method
* Added audit presenter
* Added bootstrap-tables presenter formatter to display an audit button
* Added gated sidenav items to left nav
* Added audit due/overdue blades
* Cleanup on audit due/overdue console command
* Added language strings for audit views
* Fixed :threshold placeholder
* Removed unused setting variable
* Fixed next audit date math
* Added scope for both overdue and upcoming
* Derp. Wrong version
* Bumped version
(I will release this version officially tomorrow)
* Leave the activated state for users alone in normal LDAP synchronisation. (#6988)
* Fixed #7003 - crash when warranty months or purchase date is null
* Fixed #6956 - viewKeys policy inconsistent (#7009)
* Fixed #6956 - Added additional gates show showing/hiding license keys
* Modified gate to allow user to see licenses if they can create or edit the license as well
* Added API middleware to API routes to enable throttling
TODO: Figure out how to make this costumizable without touching the code
* Import locations from CSV via command line (#7021)
* Added import locations command
* Small fixes to location importer
* Added country, LDAP OU
* Cleaned up comments, added more clarification to what the script does
* Added ability to update groups via API
Fixes [ch9139]
* Bumped version
* Fixed #6883 - remove escaping of fields on LDAP import
* Fixed #6880 - correctly encrypt encrypted fields via the API
* Fixes #5054: LDAP users deactivated for none-ad (#7032)
When using none-AD ldap, users are automatically deactivated every LDAP
sync. This commit changes the behaviour so that if the active flag isn't set,
the users are enabled.
Fixed #5054, at least for 4.X
* Updated packages
- Updating erusev/parsedown (v1.7.2 => 1.7.3): Downloading (100%)
- Updating squizlabs/php_codesniffer (3.4.1 => 3.4.2): Downloading (100%)
- Updating symfony/polyfill-mbstring (v1.10.0 => v1.11.0): Downloading (100%)
- Updating symfony/var-dumper (v3.4.23 => v3.4.27): Downloading (100%)
- Updating league/flysystem (1.0.50 => 1.0.51): Downloading (100%)
- Updating symfony/translation (v3.4.23 => v3.4.27): Downloading (100%)
- Updating nesbot/carbon (1.36.2 => 1.37.1): Downloading (100%)
- Updating symfony/debug (v3.4.23 => v3.4.27): Downloading (100%)
- Updating symfony/console (v3.4.23 => v3.4.27): Downloading (100%)
- Updating symfony/finder (v3.4.23 => v3.4.27): Downloading (100%)
- Updating symfony/polyfill-ctype (v1.10.0 => v1.11.0): Downloading (100%)
- Updating symfony/polyfill-php70 (v1.10.0 => v1.11.0): Downloading (100%)
- Updating symfony/http-foundation (v3.4.23 => v3.4.27): Downloading (100%)
- Updating symfony/event-dispatcher (v3.4.23 => v3.4.27): Downloading (100%)
- Updating symfony/http-kernel (v3.4.23 => v3.4.27): Downloading (100%)
- Updating symfony/process (v3.4.23 => v3.4.27): Downloading (100%)
- Updating symfony/routing (v3.4.23 => v3.4.27): Downloading (100%)
- Updating symfony/polyfill-util (v1.10.0 => v1.11.0): Downloading (100%)
- Updating symfony/polyfill-php56 (v1.10.0 => v1.11.0): Downloading (100%)
- Updating symfony/psr-http-message-bridge (v1.1.1 => v1.1.2): Downloading (failed)
Downloading (100%)
- Updating rollbar/rollbar (v1.7.5 => v1.8.1): Downloading (100%)
- Updating symfony/yaml (v3.4.23 => v3.4.27): Downloading (100%)
- Updating symfony/browser-kit (v3.4.23 => v3.4.27): Downloading (100%)
* Fixed #7044 - API update deleted custom fields if they are not re-presented
* Fixed XSS vulnerability when creating a new categories, etc via modal on create
Same fix as before, because of the weird select2 post-parsing ajax behavior
* Updated email strings
* Fixed #7046 - added user website url back into UI
* Updated language strings
* Bumped version
* Updated packages
* New backups config for spatie
* Removed debugbar service provider (autodiscovery)
* Use laravel v5.5 withCount manual aliases
* Added spatie language files
* Removed old laravel backups config
This config file was renamed in a newer version of spatie laravel-backup
* Set the serialization
* Added the command loader to console kernel
* Renamed fire() to handle()
* Updated withCount to use manual naming
* Updated backup path in backup admin
* Updated travis with new php versions
* Bumped laravel version in readme
* Fixed custom field edit screen
* Fixed baseUrl is undefined error
I literally cannot figure out how this ever worked before.
* Fix for included files in backup
* Bumped version
* Switch has() to filled()
* Change ->has() to ->filled()
* Removed cosole log
* Bumped packages
* Use getReader instead of fetchAssoc for CSV parser
https://csv.thephpleague.com/9.0/upgrading/
* Handle JSON validation errors like 5.4
* Handle JSON validation errors like 5.4
* Handle JSON validation errors like 5.4
* Trying to fix ajax asset validation
This I think gets us closer, but still not handling the validation on the asset properly.
When I do a print_r of the validation in the other items, its looking for an error bag that looks something like this:
```
Illuminate\Support\MessageBag Object
(
[messages:protected] => Array
(
[name] => Array
(
[0] => The name field is required.
)
[seats] => Array
(
[0] => The seats field is required.
)
[category_id] => Array
(
[0] => The category id field is required.
)
)
[format:protected] => :message
)
```
Currently the Assets ajax returns:
```
[2019-05-24 06:52:06] develop.ERROR: array (
'messages' =>
array (
'model_id' =>
array (
0 => 'The model id field is required.',
),
'status_id' =>
array (
0 => 'The status id field is required.',
),
'asset_tag' =>
array (
0 => 'The asset tag field is required.',
),
),
)
```
So not sure why it’s not working.
* Fixed missing asset validation
* Check that a model exists before trying to fiddle with fieldsets
* Tidied up license check
* Removed extra escaping on checkin
* Updated importer to work with newer CSV Reader::getRecords() method
* Fixed field mapping
* Small fix for reordering fields
Fixes Illuminate\Database\QueryException: SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'order' cannot be null (SQL: insert into `custom_field_custom_fieldset` (`custom_field_id`, `custom_fieldset_id`, `order`, `required`) values (12, 7, , 0)) [ch1151]
This needs revisiting for a more solid fix, especially for data that was already entered bad.
* Fixed bug where sorting by company name in Users API did not work
Fixes [ch9200]
* Removed custom fields from AssignedSearch to prevent confusing data in selectlist
Fixes [ch9193]
* Removed alert-danger from tests
* Fixed missed consumables_count withCount() statement
* Fixed Undefined variable user in $backto if checked out to a non-user
Fixes [ch9194]
* Check for valid model before attempting to access fieldsets
Fixes [ch1249]
* Only build the log upload destination path if there is a matching record
Fixes [ch1232]
* Fixed free_seats_count variable name
(I forgot that Laravel switched camel case to snake case for their old 5.4 withCount variables)
* Only gtry to delete the file if a record is found in the log
* Only try to get fieldset if model is valid
* Fixed more camel-casing -> snake-casing
* Only display the file if the log record can be found
* Fixed casing in sync command
* Updated README
* Derp - typo
* Added link to Atlassian plugin
* More Atlassian clarifications
* Show accessory image on view page
* Increased image size to 800px, added lightboxes
* Fixed #7083 - Removed user_exists constraint on department save
If the user has been deleted, this prevented the department from being successfully saved on edit
* Updated branch in version file
* Dockerfile update to bring us up to php v7.1 for Laravel 5.5 (#7084)
* bump up to php7.1
& change deprecated MAINTAINER to a LABEL so it is visible with `docker inspect`
* AND modapache ><
* 2 updates required to get software-properties+ppa
* Bumped version
* Bumped release again :(
* Missed one
* Fixed #7098 - updated backup config for deleteFile() method
* Fixed #7092 - handle weird port forwarding/port numbers for baseUrl
* Bumped version
* Fixed #7099 - set email to null by default for backup notifications
* Removed old comments
* Fixed #7100 - Check if $user isset on checkin
* Increased throttle to 120 requests per minute
* Added Filipino, corrected order for Spanish variations
* Update language strings
* Bumped hash
* Changed has to filled to fix bulk asset editing
* Bumped point version
* Small fixes for phpleague CSB reader v9
* Improved error checking in locations importer
* Fixed #7145 - rename groups table to permissions_group for mysql 8 reserved word compatibility
* Reduce minimum group name length to 2 (from 3)
eg: IT
* Back in time fix FOR #7145 for new installs on MySQL 8+
* Fixed permission insert
//TODO
Handle this via model
* Possible fix for reporting/admin migration back in time
* Fixed #7164 - change table name to permission_groups
* Fixed LDAP password blanking on save
* fixing previous commit's actual wiping of password (#7183)
replaced Input::fille('ldap_pword') with _filled_. Should be good to go.
https://github.com/snipe/snipe-it/issues/7179
https://github.com/snipe/snipe-it/issues/7169
* Bumped version
* Downgrading rollbar for Laravel 5.5
* Spelling Correction (#7206)
Fixed Spelling for the word reqrite, to be rewrite.
* Fix #6910: Add logic to manipulate the eloquent query. (#7006)
* Added company_id to consumables_users table
* Added logic to manage when a pivot table doesn't have the column company_id trough a join with users
* Remove a migration that tries to fix this problem, but is not longer necessary
* Addresses #7238 - add PWA code to layout
Needs additional UX testing
* Better log message for bad LDAP connection
* Fixed #7186 - has vs filled in User’s API blanking out groups if no group_ids are passed
* Comment clarification on #7186
* Check for valid seat on hardware view
* Added space between footer and custom message
* Cap warranty months to three characters
Filles rollbar 209
* Cap warranty months to 3 on the frontend blade
* Fixed countable() strings on user destroy
* Check that the user has assets and that the aset model is valid
* Bumped hash
* Caps asset warranty to 20 years
* Command to fix custom field unicode conversion differences between PHP versions (#7263)
* Fixes #7252 form request changes (#7272)
* Fixes for #7252 - custom fields not validating / no validaton messages in API w/form requests
* Removed debug info
* More fixes for #7252
This is mostly working as intended, if not yet the way Laravel wants us to do it.
Right now, the API returns correctly, and the form UI will return highlighted errors, with the input filled in ~sometimes~. I’m not sure why it’s only sometimes yet, but this is potentially progress.
* Removed experimental method
* Check for digits_between:0,240 for warranty
* Removed debug code
* Apply fix from PR #7273 to master
* Bumped hash
* Fixed #7250 - permission issue for API fieldsets and fields endpoints
This applies the change from #7294 to master
* Add @mskrip as a contributor
* Fixed #7270 - Checking-in Assets via API Removes the Item's Asset Name
* CORS for api (#7292)
* Added CORS support to API
* Changed order so CORS will still work if throttle hit
* Added APP_CORS_ALLOWED_ORIGINS env option
* Fixed typo
* Clarified header comments
* More clarification
* DIsable CORS allowed origins by default to replicate existing behavior
* Change variable name to be clearer
* Bumped version
* Added condition to deal with fieldname 'rtd_location' which can be tried to be queried in some places and doesn't exist in database (#7317)
* Added comments to the ByFilter query scope for clarity
* Added accessories checkout/checkin API endpoint
* Fixed CVE-2019-10742
https://nvd.nist.gov/vuln/detail/CVE-2019-10742
* Update README.md (#7334)
Add reference to CSV importer.
* Group related variables in .env
* History importer fixes
* Fixes to history importer
2019-08-14 21:48:14 -07:00
'warranty_months' => 'numeric|nullable|digits_between:0,240' ,
2018-07-05 19:30:36 -07:00
'physical' => 'numeric|max:1|nullable' ,
2017-03-31 13:48:11 -07:00
'checkout_date' => 'date|max:10|min:10|nullable' ,
'checkin_date' => 'date|max:10|min:10|nullable' ,
'supplier_id' => 'numeric|nullable' ,
'asset_tag' => 'required|min:1|max:255|unique_undeleted' ,
'status' => 'integer' ,
2018-07-05 19:30:36 -07:00
'serial' => 'unique_serial|nullable' ,
2017-03-31 13:48:11 -07:00
'purchase_cost' => 'numeric|nullable' ,
2017-08-25 18:40:20 -07:00
'next_audit_date' => 'date|nullable' ,
2017-12-12 03:03:43 -08:00
'last_audit_date' => 'date|nullable' ,
2016-03-25 01:18:05 -07:00
];
/**
* The attributes that are mass assignable .
*
* @ var array
*/
2017-01-10 16:19:18 -08:00
protected $fillable = [
'asset_tag' ,
'assigned_to' ,
2017-09-18 16:40:13 -07:00
'assigned_type' ,
2017-01-10 16:19:18 -08:00
'company_id' ,
'image' ,
2018-03-29 05:11:07 -07:00
'location_id' ,
2017-01-10 16:19:18 -08:00
'model_id' ,
'name' ,
'notes' ,
2017-10-26 16:13:35 -07:00
'order_number' ,
2017-01-10 16:19:18 -08:00
'purchase_cost' ,
'purchase_date' ,
'rtd_location_id' ,
'serial' ,
'status_id' ,
'supplier_id' ,
'warranty_months' ,
];
2016-03-25 01:18:05 -07:00
2018-07-16 14:13:07 -07:00
use Searchable ;
2017-10-31 05:21:55 -07:00
2018-07-16 14:13:07 -07:00
/**
* The attributes that should be included when searching the model .
*
* @ var array
*/
protected $searchableAttributes = [
'name' ,
'asset_tag' ,
'serial' ,
'order_number' ,
'purchase_cost' ,
'notes' ,
'created_at' ,
'updated_at' ,
'purchase_date' ,
'expected_checkin' ,
'next_audit_date' ,
'last_audit_date'
];
/**
* The relations and their attributes that should be included when searching the model .
*
* @ var array
*/
protected $searchableRelations = [
'assetstatus' => [ 'name' ],
'supplier' => [ 'name' ],
'company' => [ 'name' ],
'defaultLoc' => [ 'name' ],
'model' => [ 'name' , 'model_number' ],
'model.category' => [ 'name' ],
'model.manufacturer' => [ 'name' ],
2018-09-29 21:33:52 -07:00
];
/**
* This handles the custom field validation for assets
*
* @ var array
*/
2018-10-02 04:40:20 -07:00
public function save ( array $params = [])
2018-09-29 21:33:52 -07:00
{
$settings = \App\Models\Setting :: getSettings ();
// I don't remember why we have this here? Asset tag would always be required, even if auto increment is on...
$this -> rules [ 'asset_tag' ] = ( $settings -> auto_increment_assets == '1' ) ? 'max:255' : 'required' ;
if ( $this -> model_id != '' ) {
$model = AssetModel :: find ( $this -> model_id );
if (( $model ) && ( $model -> fieldset )) {
$this -> rules += $model -> fieldset -> validation_rules ();
}
}
return parent :: save ( $params );
}
2017-10-31 05:21:55 -07:00
2016-12-23 17:52:00 -08:00
public function getDisplayNameAttribute ()
{
return $this -> present () -> name ();
}
2016-03-25 01:18:05 -07:00
2017-03-14 08:37:39 -07:00
/**
* Returns the warranty expiration date as Carbon object
* @ return \Carbon | null
*/
public function getWarrantyExpiresAttribute ()
{
if ( isset ( $this -> attributes [ 'warranty_months' ]) && isset ( $this -> attributes [ 'purchase_date' ])) {
if ( is_string ( $this -> attributes [ 'purchase_date' ]) || is_string ( $this -> attributes [ 'purchase_date' ])) {
$purchase_date = \Carbon\Carbon :: parse ( $this -> attributes [ 'purchase_date' ]);
} else {
$purchase_date = \Carbon\Carbon :: instance ( $this -> attributes [ 'purchase_date' ]);
}
$purchase_date -> setTime ( 0 , 0 , 0 );
return $purchase_date -> addMonths (( int ) $this -> attributes [ 'warranty_months' ]);
}
return null ;
}
2018-08-01 00:06:41 -07:00
/**
* Establishes the asset -> company relationship
*
* @ author [ A . Gianotto ] [ < snipe @ snipe . net > ]
* @ since [ v3 . 0 ]
* @ return \Illuminate\Database\Eloquent\Relations\Relation
*/
2016-03-25 01:18:05 -07:00
public function company ()
{
return $this -> belongsTo ( '\App\Models\Company' , 'company_id' );
}
2018-08-01 00:06:41 -07:00
/**
* Determines if an asset is available for checkout
*
* @ author [ A . Gianotto ] [ < snipe @ snipe . net > ]
* @ since [ v3 . 0 ]
* @ return boolean
*/
2016-08-16 13:02:42 -07:00
public function availableForCheckout ()
{
2017-12-05 11:28:48 -08:00
if (
( empty ( $this -> assigned_to )) &&
( empty ( $this -> deleted_at )) &&
(( $this -> assetstatus ) && ( $this -> assetstatus -> deployable == 1 )))
{
2017-10-28 02:31:54 -07:00
return true ;
}
return false ;
2016-08-16 13:02:42 -07:00
}
2016-07-26 01:39:30 -07:00
2018-08-01 00:06:41 -07:00
2016-12-23 17:52:00 -08:00
/**
2018-08-01 00:06:41 -07:00
* Checks the asset out to the target
*
* @ todo The admin parameter is never used . Can probably be removed .
*
* @ author [ A . Gianotto ] [ < snipe @ snipe . net > ]
2016-12-23 17:52:00 -08:00
* @ param User $user
* @ param User $admin
* @ param Carbon $checkout_at
2017-11-08 18:03:27 -08:00
* @ param Carbon $expected_checkin
2016-12-23 17:52:00 -08:00
* @ param string $note
* @ param null $name
* @ return bool
2018-08-01 00:06:41 -07:00
* @ since [ v3 . 0 ]
* @ return boolean
2016-12-23 17:52:00 -08:00
*/
2017-11-03 19:39:48 -07:00
public function checkOut ( $target , $admin = null , $checkout_at = null , $expected_checkin = null , $note = null , $name = null , $location = null )
2016-03-25 01:18:05 -07:00
{
2016-12-27 16:24:41 -08:00
if ( ! $target ) {
2016-08-16 13:02:42 -07:00
return false ;
}
2016-03-25 01:18:05 -07:00
if ( $expected_checkin ) {
2016-08-16 13:02:42 -07:00
$this -> expected_checkin = $expected_checkin ;
2016-03-25 01:18:05 -07:00
}
$this -> last_checkout = $checkout_at ;
2016-12-27 16:24:41 -08:00
$this -> assignedTo () -> associate ( $target );
2016-08-16 18:23:20 -07:00
2016-12-29 14:02:18 -08:00
if ( $name != null ) {
2016-08-16 18:23:20 -07:00
$this -> name = $name ;
}
2016-03-25 01:18:05 -07:00
2017-11-03 19:39:48 -07:00
if ( $location != null ) {
$this -> location_id = $location ;
2017-12-28 20:08:45 -08:00
} else {
if ( $target -> location ) {
$this -> location_id = $target -> location -> id ;
}
2018-07-23 06:47:21 -07:00
if ( $target instanceof Location ) {
$this -> location_id = $target -> id ;
}
2017-11-03 19:39:48 -07:00
}
2016-03-25 01:18:05 -07:00
if ( $this -> save ()) {
2018-07-21 05:01:30 -07:00
2018-09-10 07:40:26 -07:00
event ( new CheckoutableCheckedOut ( $this , $target , Auth :: user (), $note ));
2018-07-21 05:01:30 -07:00
2018-05-16 19:20:43 -07:00
$this -> increment ( 'checkout_counter' , 1 );
2016-03-25 01:18:05 -07:00
return true ;
}
return false ;
}
2018-08-01 00:06:41 -07:00
/**
* Sets the detailedNameAttribute
*
* @ author [ A . Gianotto ] [ < snipe @ snipe . net > ]
* @ since [ v3 . 0 ]
* @ return string
*/
2016-06-22 12:27:41 -07:00
public function getDetailedNameAttribute ()
{
2017-09-29 17:14:38 -07:00
if ( $this -> assignedto ) {
$user_name = $this -> assignedto -> present () -> name ();
2016-06-22 12:27:41 -07:00
} else {
$user_name = " Unassigned " ;
}
2017-10-24 16:53:46 -07:00
return $this -> asset_tag . ' - ' . $this -> name . ' (' . $user_name . ') ' . ( $this -> model ) ? $this -> model -> name : '' ;
2016-05-24 18:05:48 -07:00
}
2017-09-29 17:14:38 -07:00
2018-08-01 00:06:41 -07:00
/**
* Pulls in the validation rules
*
* @ author [ A . Gianotto ] [ < snipe @ snipe . net > ]
* @ since [ v3 . 0 ]
* @ return array
*/
public function validationRules ()
2016-03-25 01:18:05 -07:00
{
return $this -> rules ;
}
2016-04-23 02:07:40 -07:00
2016-05-18 19:26:50 -07:00
/**
2018-08-01 00:06:41 -07:00
* Establishes the asset -> depreciation relationship
*
* @ author [ A . Gianotto ] [ < snipe @ snipe . net > ]
* @ since [ v3 . 0 ]
* @ return \Illuminate\Database\Eloquent\Relations\Relation
*/
2016-03-25 01:18:05 -07:00
public function depreciation ()
{
return $this -> model -> belongsTo ( '\App\Models\Depreciation' , 'depreciation_id' );
}
2018-08-01 00:06:41 -07:00
2016-05-18 19:26:50 -07:00
/**
* Get components assigned to this asset
2018-08-01 00:06:41 -07:00
*
* @ author [ A . Gianotto ] [ < snipe @ snipe . net > ]
* @ since [ v4 . 0 ]
* @ return \Illuminate\Database\Eloquent\Relations\Relation
2016-05-18 19:26:50 -07:00
*/
public function components ()
{
2018-01-24 05:25:01 -08:00
return $this -> belongsToMany ( '\App\Models\Component' , 'components_assets' , 'asset_id' , 'component_id' ) -> withPivot ( 'id' , 'assigned_qty' ) -> withTrashed ();
2016-05-18 19:26:50 -07:00
}
2018-08-01 00:06:41 -07:00
/**
* Get depreciation attribute from associated asset model
*
* @ todo Is this still needed ?
*
* @ author [ A . Gianotto ] [ < snipe @ snipe . net > ]
* @ since [ v4 . 0 ]
* @ return \Illuminate\Database\Eloquent\Relations\Relation
*/
2016-03-25 01:18:05 -07:00
public function get_depreciation ()
{
2018-01-25 11:06:37 -08:00
if (( $this -> model ) && ( $this -> model -> depreciation )) {
2018-01-25 03:34:52 -08:00
return $this -> model -> depreciation ;
}
2016-03-25 01:18:05 -07:00
}
2018-08-01 00:06:41 -07:00
/**
* Get uploads for this asset
*
* @ author [ A . Gianotto ] [ < snipe @ snipe . net > ]
* @ since [ v4 . 0 ]
* @ return \Illuminate\Database\Eloquent\Relations\Relation
*/
2016-03-25 01:18:05 -07:00
public function uploads ()
{
2016-09-06 19:39:42 -07:00
return $this -> hasMany ( '\App\Models\Actionlog' , 'item_id' )
-> where ( 'item_type' , '=' , Asset :: class )
2016-03-25 01:18:05 -07:00
-> where ( 'action_type' , '=' , 'uploaded' )
-> whereNotNull ( 'filename' )
-> orderBy ( 'created_at' , 'desc' );
}
2018-08-01 00:06:41 -07:00
2016-12-29 06:31:16 -08:00
/**
2018-08-01 00:06:41 -07:00
* Determines whether the asset is checked out to a user
*
2016-12-29 06:31:16 -08:00
* Even though we allow allow for checkout to things beyond users
* this method is an easy way of seeing if we are checked out to a user .
2018-08-01 00:06:41 -07:00
*
* @ author [ A . Gianotto ] [ < snipe @ snipe . net > ]
* @ since [ v4 . 0 ]
* @ return boolean
2016-12-29 06:31:16 -08:00
*/
2017-09-05 17:54:58 -07:00
public function checkedOutToUser ()
2016-03-25 01:18:05 -07:00
{
2017-09-05 17:54:58 -07:00
return $this -> assignedType () === self :: USER ;
2016-03-25 01:18:05 -07:00
}
2018-08-01 00:06:41 -07:00
/**
* Get the target this asset is checked out to
*
* @ author [ A . Gianotto ] [ < snipe @ snipe . net > ]
* @ since [ v4 . 0 ]
* @ return \Illuminate\Database\Eloquent\Relations\Relation
*/
2016-12-27 16:24:41 -08:00
public function assignedTo ()
{
2017-03-14 08:37:39 -07:00
return $this -> morphTo ( 'assigned' , 'assigned_type' , 'assigned_to' );
2016-12-27 16:24:41 -08:00
}
2018-08-01 00:06:41 -07:00
/**
* Gets assets assigned to this asset
*
* Sigh .
*
* @ author [ A . Gianotto ] [ < snipe @ snipe . net > ]
* @ since [ v4 . 0 ]
* @ return \Illuminate\Database\Eloquent\Relations\Relation
*/
2016-12-27 16:24:41 -08:00
public function assignedAssets ()
{
2017-03-14 08:37:39 -07:00
return $this -> morphMany ( 'App\Models\Asset' , 'assigned' , 'assigned_type' , 'assigned_to' ) -> withTrashed ();
2016-12-27 16:24:41 -08:00
}
2018-08-01 00:06:41 -07:00
/**
* Get the asset ' s location based on the assigned user
*
* @ todo Refactor this if possible . It ' s awful .
*
* @ author [ A . Gianotto ] [ < snipe @ snipe . net > ]
* @ since [ v4 . 0 ]
* @ return \ArrayObject
*/
2017-12-04 23:00:55 -08:00
public function assetLoc ( $iterations = 1 , $first_asset = null )
2016-03-25 01:18:05 -07:00
{
2017-03-14 08:37:39 -07:00
if ( ! empty ( $this -> assignedType ())) {
2016-12-27 16:24:41 -08:00
if ( $this -> assignedType () == self :: ASSET ) {
2017-10-28 01:48:27 -07:00
if ( ! $first_asset ) {
$first_asset = $this ;
}
if ( $iterations > 10 ) {
throw new \Exception ( " Asset assignment Loop for Asset ID: " . $first_asset -> id );
}
$assigned_to = Asset :: find ( $this -> assigned_to ); //have to do this this way because otherwise it errors
2017-10-31 08:47:40 -07:00
if ( $assigned_to ) {
2017-12-04 23:00:55 -08:00
return $assigned_to -> assetLoc ( $iterations + 1 , $first_asset );
2017-10-31 08:47:40 -07:00
} // Recurse until we have a final location
2017-05-22 17:49:03 -07:00
}
if ( $this -> assignedType () == self :: LOCATION ) {
2017-10-31 08:47:40 -07:00
if ( $this -> assignedTo ) {
return $this -> assignedTo ;
}
2016-12-27 16:24:41 -08:00
}
2017-05-22 17:49:03 -07:00
if ( $this -> assignedType () == self :: USER ) {
2017-10-31 08:47:40 -07:00
if (( $this -> assignedTo ) && $this -> assignedTo -> userLoc ) {
return $this -> assignedTo -> userLoc ;
2017-09-25 11:25:15 -07:00
}
2017-10-31 08:47:40 -07:00
//this makes no sense
return $this -> defaultLoc ;
2017-05-22 17:49:03 -07:00
}
2017-09-25 11:25:15 -07:00
2016-03-25 01:18:05 -07:00
}
2017-10-28 01:48:27 -07:00
return $this -> defaultLoc ;
2016-03-25 01:18:05 -07:00
}
2018-08-01 00:06:41 -07:00
/**
* Gets the lowercased name of the type of target the asset is assigned to
*
* @ author [ A . Gianotto ] [ < snipe @ snipe . net > ]
* @ since [ v4 . 0 ]
* @ return string
*/
2016-12-27 16:24:41 -08:00
public function assignedType ()
{
return strtolower ( class_basename ( $this -> assigned_type ));
}
2018-08-01 00:06:41 -07:00
/**
* Get the asset ' s location based on default RTD location
*
* @ author [ A . Gianotto ] [ < snipe @ snipe . net > ]
* @ since [ v2 . 0 ]
* @ return \Illuminate\Database\Eloquent\Relations\Relation
*/
2016-03-25 01:18:05 -07:00
public function defaultLoc ()
{
return $this -> belongsTo ( '\App\Models\Location' , 'rtd_location_id' );
}
2018-08-01 00:06:41 -07:00
/**
* Get the image URL of the asset .
*
* Check first to see if there is a specific image uploaded to the asset ,
* and if not , check for an image uploaded to the asset model .
*
* @ author [ A . Gianotto ] [ < snipe @ snipe . net > ]
* @ since [ v2 . 0 ]
* @ return string | false
*/
2017-03-14 08:37:39 -07:00
public function getImageUrl ()
{
2017-01-24 22:46:07 -08:00
if ( $this -> image && ! empty ( $this -> image )) {
2018-09-29 21:33:52 -07:00
return Storage :: disk ( 'public' ) -> url ( app ( 'assets_upload_path' ) . e ( $this -> image ));
2017-01-24 22:46:07 -08:00
} elseif ( $this -> model && ! empty ( $this -> model -> image )) {
2018-09-29 21:33:52 -07:00
return Storage :: disk ( 'public' ) -> url ( app ( 'models_upload_path' ) . e ( $this -> model -> image ));
2017-01-24 22:46:07 -08:00
}
return false ;
}
2018-08-01 00:06:41 -07:00
/**
* Get the asset ' s logs
*
* @ author [ A . Gianotto ] [ < snipe @ snipe . net > ]
* @ since [ v2 . 0 ]
* @ return \Illuminate\Database\Eloquent\Relations\Relation
*/
2016-03-25 01:18:05 -07:00
public function assetlog ()
{
2016-09-06 19:39:42 -07:00
return $this -> hasMany ( '\App\Models\Actionlog' , 'item_id' )
-> where ( 'item_type' , '=' , Asset :: class )
2016-03-25 01:18:05 -07:00
-> orderBy ( 'created_at' , 'desc' )
-> withTrashed ();
}
2018-04-06 16:23:39 -07:00
/**
2018-08-01 00:06:41 -07:00
* Get the list of checkouts for this asset
*
* @ author [ A . Gianotto ] [ < snipe @ snipe . net > ]
* @ since [ v2 . 0 ]
* @ return \Illuminate\Database\Eloquent\Relations\Relation
2018-04-06 16:23:39 -07:00
*/
public function checkouts ()
{
return $this -> assetlog () -> where ( 'action_type' , '=' , 'checkout' )
-> orderBy ( 'created_at' , 'desc' )
-> withTrashed ();
}
/**
2018-08-01 00:06:41 -07:00
* Get the list of checkins for this asset
*
* @ author [ A . Gianotto ] [ < snipe @ snipe . net > ]
* @ since [ v2 . 0 ]
* @ return \Illuminate\Database\Eloquent\Relations\Relation
2018-04-06 16:23:39 -07:00
*/
public function checkins ()
{
return $this -> assetlog ()
-> where ( 'action_type' , '=' , 'checkin from' )
-> orderBy ( 'created_at' , 'desc' )
-> withTrashed ();
}
/**
2018-08-01 00:06:41 -07:00
* Get the asset ' s user requests
*
* @ author [ A . Gianotto ] [ < snipe @ snipe . net > ]
* @ since [ v2 . 0 ]
* @ return \Illuminate\Database\Eloquent\Relations\Relation
2018-04-06 16:23:39 -07:00
*/
public function userRequests ()
{
return $this -> assetlog ()
-> where ( 'action_type' , '=' , 'requested' )
-> orderBy ( 'created_at' , 'desc' )
-> withTrashed ();
}
2016-03-25 01:18:05 -07:00
2018-08-01 00:06:41 -07:00
/**
* Get maintenances for this asset
*
* @ author Vincent Sposato < vincent . sposato @ gmail . com >
* @ since 1.0
* @ return \Illuminate\Database\Eloquent\Relations\Relation
*/
2016-03-25 01:18:05 -07:00
public function assetmaintenances ()
{
return $this -> hasMany ( '\App\Models\AssetMaintenance' , 'asset_id' )
2016-12-01 00:55:00 -08:00
-> orderBy ( 'created_at' , 'desc' );
2016-03-25 01:18:05 -07:00
}
2018-08-01 00:06:41 -07:00
/**
* Get action logs history for this asset
*
* @ author [ A . Gianotto ] [ < snipe @ snipe . net > ]
* @ since [ v1 . 0 ]
* @ return \Illuminate\Database\Eloquent\Relations\Relation
*/
2016-03-25 01:18:05 -07:00
public function adminuser ()
{
return $this -> belongsTo ( '\App\Models\User' , 'user_id' );
}
2018-08-01 00:06:41 -07:00
/**
* Establishes the asset -> status relationship
*
* @ author [ A . Gianotto ] [ < snipe @ snipe . net > ]
* @ since [ v1 . 0 ]
* @ return \Illuminate\Database\Eloquent\Relations\Relation
*/
2016-03-25 01:18:05 -07:00
public function assetstatus ()
{
return $this -> belongsTo ( '\App\Models\Statuslabel' , 'status_id' );
}
2018-08-01 00:06:41 -07:00
/**
* Establishes the asset -> model relationship
*
* @ author [ A . Gianotto ] [ < snipe @ snipe . net > ]
* @ since [ v1 . 0 ]
* @ return \Illuminate\Database\Eloquent\Relations\Relation
*/
2016-03-25 01:18:05 -07:00
public function model ()
{
return $this -> belongsTo ( '\App\Models\AssetModel' , 'model_id' ) -> withTrashed ();
}
2018-08-01 00:06:41 -07:00
/**
* Return the assets with a warranty expiring within x days
*
* @ param $days
* @ author [ A . Gianotto ] [ < snipe @ snipe . net > ]
* @ since [ v2 . 0 ]
* @ return mixed
*/
2016-03-25 01:18:05 -07:00
public static function getExpiringWarrantee ( $days = 30 )
{
return Asset :: where ( 'archived' , '=' , '0' )
-> whereNotNull ( 'warranty_months' )
-> whereNotNull ( 'purchase_date' )
-> whereNull ( 'deleted_at' )
-> whereRaw ( \DB :: raw ( 'DATE_ADD(`purchase_date`,INTERVAL `warranty_months` MONTH) <= DATE(NOW() + INTERVAL '
. $days
. ' DAY) AND DATE_ADD(`purchase_date`,INTERVAL `warranty_months` MONTH) > NOW()' ))
-> orderBy ( 'purchase_date' , 'ASC' )
-> get ();
}
2018-08-01 00:06:41 -07:00
/**
* Establishes the asset -> assigned licenses relationship
*
* @ author [ A . Gianotto ] [ < snipe @ snipe . net > ]
* @ since [ v4 . 0 ]
* @ return \Illuminate\Database\Eloquent\Relations\Relation
*/
2016-03-25 01:18:05 -07:00
public function licenses ()
{
return $this -> belongsToMany ( '\App\Models\License' , 'license_seats' , 'asset_id' , 'license_id' );
}
2018-08-01 00:06:41 -07:00
/**
* Establishes the asset -> status relationship
*
* @ author [ A . Gianotto ] [ < snipe @ snipe . net > ]
* @ since [ v4 . 0 ]
* @ return \Illuminate\Database\Eloquent\Relations\Relation
*/
2016-03-25 01:18:05 -07:00
public function licenseseats ()
{
return $this -> hasMany ( '\App\Models\LicenseSeat' , 'asset_id' );
}
2018-08-01 00:06:41 -07:00
/**
* Establishes the asset -> aupplier relationship
*
* @ author [ A . Gianotto ] [ < snipe @ snipe . net > ]
* @ since [ v2 . 0 ]
* @ return \Illuminate\Database\Eloquent\Relations\Relation
*/
2016-03-25 01:18:05 -07:00
public function supplier ()
{
return $this -> belongsTo ( '\App\Models\Supplier' , 'supplier_id' );
}
2018-08-01 00:06:41 -07:00
/**
* Establishes the asset -> location relationship
*
* @ author [ A . Gianotto ] [ < snipe @ snipe . net > ]
* @ since [ v2 . 0 ]
* @ return \Illuminate\Database\Eloquent\Relations\Relation
*/
2017-10-28 01:48:27 -07:00
public function location ()
{
return $this -> belongsTo ( '\App\Models\Location' , 'location_id' );
}
2016-03-25 01:18:05 -07:00
2018-08-01 00:06:41 -07:00
/**
* Get the next autoincremented asset tag
*
* @ author [ A . Gianotto ] [ < snipe @ snipe . net > ]
* @ since [ v4 . 0 ]
* @ return string | false
*/
2016-03-25 01:18:05 -07:00
public static function autoincrement_asset ()
{
$settings = \App\Models\Setting :: getSettings ();
2017-06-15 19:42:43 -07:00
2016-03-25 01:18:05 -07:00
if ( $settings -> auto_increment_assets == '1' ) {
2017-01-06 02:54:06 -08:00
$temp_asset_tag = \DB :: table ( 'assets' )
2016-03-25 01:18:05 -07:00
-> where ( 'physical' , '=' , '1' )
2017-01-06 02:54:06 -08:00
-> max ( 'asset_tag' );
2017-01-06 03:14:32 -08:00
$asset_tag_digits = preg_replace ( '/\D/' , '' , $temp_asset_tag );
$asset_tag = preg_replace ( '/^0*/' , '' , $asset_tag_digits );
2016-07-27 21:28:00 -07:00
if ( $settings -> zerofill_count > 0 ) {
2017-06-15 19:42:43 -07:00
return $settings -> auto_increment_prefix . Asset :: zerofill ( $settings -> next_auto_tag_base , $settings -> zerofill_count );
2016-07-27 21:28:00 -07:00
}
2017-06-20 12:13:36 -07:00
return $settings -> auto_increment_prefix . $settings -> next_auto_tag_base ;
2016-03-25 01:18:05 -07:00
} else {
return false ;
}
}
2018-08-01 00:06:41 -07:00
/**
* Get the next base number for the auto - incrementer .
*
* We ' ll add the zerofill and prefixes on the fly as we generate the number .
2017-06-15 19:42:43 -07:00
*
2018-08-01 00:06:41 -07:00
* @ author [ A . Gianotto ] [ < snipe @ snipe . net > ]
* @ since [ v4 . 0 ]
* @ return int
2017-06-15 19:42:43 -07:00
*/
public static function nextAutoIncrement ( $assets )
{
$max = 1 ;
foreach ( $assets as $asset ) {
$results = preg_match ( " / \ d+ $ / " , $asset [ 'asset_tag' ], $matches );
if ( $results )
{
$number = $matches [ 0 ];
if ( $number > $max )
{
$max = $number ;
}
}
}
return $max + 1 ;
}
2018-08-01 00:06:41 -07:00
/**
* Add zerofilling based on Settings
*
* We ' ll add the zerofill and prefixes on the fly as we generate the number .
*
* @ author [ A . Gianotto ] [ < snipe @ snipe . net > ]
* @ since [ v4 . 0 ]
* @ return string
*/
2016-12-29 14:02:18 -08:00
public static function zerofill ( $num , $zerofill = 3 )
2016-07-27 21:28:00 -07:00
{
return str_pad ( $num , $zerofill , '0' , STR_PAD_LEFT );
}
2018-08-01 00:06:41 -07:00
/**
* Determine whether to send a checkin / checkout email based on
* asset model category
*
* @ author [ A . Gianotto ] [ < snipe @ snipe . net > ]
* @ since [ v4 . 0 ]
* @ return boolean
*/
2016-12-23 17:52:00 -08:00
public function checkin_email ()
2016-03-25 01:18:05 -07:00
{
return $this -> model -> category -> checkin_email ;
}
2018-08-01 00:06:41 -07:00
/**
* Determine whether this asset requires acceptance by the assigned user
*
* @ author [ A . Gianotto ] [ < snipe @ snipe . net > ]
* @ since [ v4 . 0 ]
* @ return boolean
*/
2016-03-25 01:18:05 -07:00
public function requireAcceptance ()
{
return $this -> model -> category -> require_acceptance ;
}
2018-08-01 00:06:41 -07:00
/**
* Checks for a category - specific EULA , and if that doesn ' t exist ,
* checks for a settings level EULA
*
* @ author [ A . Gianotto ] [ < snipe @ snipe . net > ]
* @ since [ v4 . 0 ]
* @ return string | false
*/
2016-03-25 01:18:05 -07:00
public function getEula ()
{
$Parsedown = new \Parsedown ();
if ( $this -> model -> category -> eula_text ) {
return $Parsedown -> text ( e ( $this -> model -> category -> eula_text ));
} elseif ( $this -> model -> category -> use_default_eula == '1' ) {
return $Parsedown -> text ( e ( Setting :: getSettings () -> default_eula_text ));
} else {
2017-10-11 15:36:47 -07:00
return false ;
2016-03-25 01:18:05 -07:00
}
}
2018-08-01 00:06:41 -07:00
/**
* -----------------------------------------------
* BEGIN QUERY SCOPES
* -----------------------------------------------
**/
2018-07-16 14:13:07 -07:00
/**
* Run additional , advanced searches .
2018-08-01 00:06:41 -07:00
*
* @ param \Illuminate\Database\Eloquent\Builder $query
2018-07-16 17:44:31 -07:00
* @ param array $terms The search terms
2018-08-01 00:06:41 -07:00
* @ return \Illuminate\Database\Eloquent\Builder
2018-07-16 14:13:07 -07:00
*/
2018-07-16 17:44:31 -07:00
public function advancedTextSearch ( Builder $query , array $terms ) {
2018-08-01 00:06:41 -07:00
/**
* Assigned user
*/
$query = $query -> leftJoin ( 'users as assets_users' , function ( $leftJoin ) {
2018-07-16 14:13:07 -07:00
$leftJoin -> on ( " assets_users.id " , " = " , " assets.assigned_to " )
-> where ( " assets.assigned_type " , " = " , User :: class );
2018-08-01 00:06:41 -07:00
});
2018-07-16 17:44:31 -07:00
2018-08-01 00:06:41 -07:00
foreach ( $terms as $term ) {
2018-07-16 17:44:31 -07:00
2018-08-01 00:06:41 -07:00
$query = $query
-> orWhere ( 'assets_users.first_name' , 'LIKE' , '%' . $term . '%' )
-> orWhere ( 'assets_users.last_name' , 'LIKE' , '%' . $term . '%' )
-> orWhere ( 'assets_users.username' , 'LIKE' , '%' . $term . '%' )
-> orWhereRaw ( 'CONCAT(' . DB :: getTablePrefix () . 'assets_users.first_name," ",' . DB :: getTablePrefix () . 'assets_users.last_name) LIKE ?' , [ " % $term % " , " % $term % " ]);
2018-07-16 17:44:31 -07:00
2018-08-01 00:06:41 -07:00
}
2018-07-16 14:13:07 -07:00
2018-08-01 00:06:41 -07:00
/**
* Assigned location
*/
$query = $query -> leftJoin ( 'locations as assets_locations' , function ( $leftJoin ) {
$leftJoin -> on ( " assets_locations.id " , " = " , " assets.assigned_to " )
-> where ( " assets.assigned_type " , " = " , Location :: class );
});
foreach ( $terms as $term ) {
2018-07-16 14:13:07 -07:00
2018-08-01 00:06:41 -07:00
$query = $query -> orWhere ( 'assets_locations.name' , 'LIKE' , '%' . $term . '%' );
2018-07-16 17:44:31 -07:00
2018-08-01 00:06:41 -07:00
}
2018-07-16 17:44:31 -07:00
2018-08-01 00:06:41 -07:00
/**
* Assigned assets
*/
$query = $query -> leftJoin ( 'assets as assigned_assets' , function ( $leftJoin ) {
$leftJoin -> on ( 'assigned_assets.id' , '=' , 'assets.assigned_to' )
-> where ( 'assets.assigned_type' , '=' , Asset :: class );
});
2018-07-16 14:13:07 -07:00
2018-08-01 00:06:41 -07:00
foreach ( $terms as $term ) {
2018-07-16 14:13:07 -07:00
2018-08-01 00:06:41 -07:00
$query = $query -> orWhere ( 'assigned_assets.name' , 'LIKE' , '%' . $term . '%' );
2018-07-16 17:44:31 -07:00
2018-08-01 00:06:41 -07:00
}
2018-07-16 14:13:07 -07:00
2018-08-01 00:06:41 -07:00
return $query ;
2018-07-16 14:13:07 -07:00
}
2016-03-25 01:18:05 -07:00
2018-08-01 00:06:41 -07:00
/**
* Query builder scope for hardware
*
* @ param \Illuminate\Database\Query\Builder $query Query builder instance
*
* @ return \Illuminate\Database\Query\Builder Modified query builder
*/
2016-03-25 01:18:05 -07:00
public function scopeHardware ( $query )
{
return $query -> where ( 'physical' , '=' , '1' );
}
2018-08-01 00:06:41 -07:00
/**
* Query builder scope for pending assets
*
* @ param \Illuminate\Database\Query\Builder $query Query builder instance
*
* @ return \Illuminate\Database\Query\Builder Modified query builder
*/
2016-03-25 01:18:05 -07:00
public function scopePending ( $query )
{
return $query -> whereHas ( 'assetstatus' , function ( $query ) {
$query -> where ( 'deployable' , '=' , 0 )
-> where ( 'pending' , '=' , 1 )
-> where ( 'archived' , '=' , 0 );
});
}
2016-04-19 20:23:04 -07:00
/**
2017-09-05 17:54:58 -07:00
* Query builder scope for searching location
2016-04-19 20:23:04 -07:00
*
2017-02-03 19:34:24 -08:00
* @ param \Illuminate\Database\Query\Builder $query Query builder instance
2016-04-19 20:23:04 -07:00
*
2017-02-03 19:34:24 -08:00
* @ return \Illuminate\Database\Query\Builder Modified query builder
2016-04-19 20:23:04 -07:00
*/
public function scopeAssetsByLocation ( $query , $location )
{
2016-06-22 12:27:41 -07:00
return $query -> where ( function ( $query ) use ( $location ) {
2017-09-05 17:54:58 -07:00
$query -> whereHas ( 'assignedTo' , function ( $query ) use ( $location ) {
$query -> where ([
[ 'users.location_id' , '=' , $location -> id ],
[ 'assets.assigned_type' , '=' , User :: class ]
]) -> orWhere ([
[ 'locations.id' , '=' , $location -> id ],
[ 'assets.assigned_type' , '=' , Location :: class ]
]) -> orWhere ([
[ 'assets.rtd_location_id' , '=' , $location -> id ],
[ 'assets.assigned_type' , '=' , Asset :: class ]
]);
2016-06-22 12:27:41 -07:00
}) -> orWhere ( function ( $query ) use ( $location ) {
2016-04-19 20:23:04 -07:00
$query -> where ( 'assets.rtd_location_id' , '=' , $location -> id );
$query -> whereNull ( 'assets.assigned_to' );
});
});
}
/**
* Query builder scope for RTD assets
*
2017-02-03 19:34:24 -08:00
* @ param \Illuminate\Database\Query\Builder $query Query builder instance
2016-04-19 20:23:04 -07:00
*
2017-02-03 19:34:24 -08:00
* @ return \Illuminate\Database\Query\Builder Modified query builder
2016-04-19 20:23:04 -07:00
*/
2016-03-25 01:18:05 -07:00
public function scopeRTD ( $query )
{
2018-07-25 06:46:06 -07:00
return $query -> whereNull ( 'assets.assigned_to' )
2016-03-25 01:18:05 -07:00
-> whereHas ( 'assetstatus' , function ( $query ) {
$query -> where ( 'deployable' , '=' , 1 )
-> where ( 'pending' , '=' , 0 )
-> where ( 'archived' , '=' , 0 );
});
}
/**
* Query builder scope for Undeployable assets
*
2017-02-03 19:34:24 -08:00
* @ param \Illuminate\Database\Query\Builder $query Query builder instance
2016-03-25 01:18:05 -07:00
*
2017-02-03 19:34:24 -08:00
* @ return \Illuminate\Database\Query\Builder Modified query builder
2016-03-25 01:18:05 -07:00
*/
public function scopeUndeployable ( $query )
{
return $query -> whereHas ( 'assetstatus' , function ( $query ) {
$query -> where ( 'deployable' , '=' , 0 )
-> where ( 'pending' , '=' , 0 )
-> where ( 'archived' , '=' , 0 );
});
}
2016-09-01 13:28:15 -07:00
/**
* Query builder scope for non - Archived assets
*
2017-02-03 19:34:24 -08:00
* @ param \Illuminate\Database\Query\Builder $query Query builder instance
2016-09-01 13:28:15 -07:00
*
2017-02-03 19:34:24 -08:00
* @ return \Illuminate\Database\Query\Builder Modified query builder
2016-09-01 13:28:15 -07:00
*/
public function scopeNotArchived ( $query )
{
return $query -> whereHas ( 'assetstatus' , function ( $query ) {
$query -> where ( 'archived' , '=' , 0 );
});
}
2019-05-05 16:14:02 -07:00
/**
* Query builder scope for Assets that are due for auditing , based on the assets . next_audit_date
* and settings . audit_warning_days .
*
* This is / will be used in the artisan command snipeit : upcoming - audits and also
* for an upcoming API call for retrieving a report on assets that will need to be audited .
*
* Due for audit soon :
* next_audit_date greater than or equal to now ( must be in the future )
* and ( next_audit_date - threshold days ) <= now ()
*
* Example :
* next_audit_date = May 4 , 2025
* threshold for alerts = 30 days
* now = May 4 , 2019
*
* @ author A . Gianotto < snipe @ snipe . net >
2019-05-05 19:31:43 -07:00
* @ since v4 . 6.16
2019-05-05 16:14:02 -07:00
* @ param Setting $settings
*
* @ return \Illuminate\Database\Query\Builder Modified query builder
*/
public function scopeDueForAudit ( $query , $settings )
{
return $query -> whereNotNull ( 'assets.next_audit_date' )
-> where ( 'assets.next_audit_date' , '>=' , Carbon :: now ())
-> whereRaw ( " DATE_SUB(assets.next_audit_date, INTERVAL $settings->audit_warning_days DAY) <= ' " . Carbon :: now () . " ' " )
-> where ( 'assets.archived' , '=' , 0 )
-> NotArchived ();
}
/**
* Query builder scope for Assets that are OVERDUE for auditing , based on the assets . next_audit_date
* and settings . audit_warning_days . It checks to see if assets . next audit_date is before now
*
* This is / will be used in the artisan command snipeit : upcoming - audits and also
* for an upcoming API call for retrieving a report on overdue assets .
*
* @ author A . Gianotto < snipe @ snipe . net >
2019-05-05 19:31:43 -07:00
* @ since v4 . 6.16
2019-05-05 16:14:02 -07:00
* @ param Setting $settings
*
* @ return \Illuminate\Database\Query\Builder Modified query builder
*/
2019-05-05 16:58:08 -07:00
public function scopeOverdueForAudit ( $query )
2019-05-05 16:14:02 -07:00
{
return $query -> whereNotNull ( 'assets.next_audit_date' )
-> where ( 'assets.next_audit_date' , '<' , Carbon :: now ())
-> where ( 'assets.archived' , '=' , 0 )
-> NotArchived ();
}
2019-05-05 19:13:30 -07:00
/**
* Query builder scope for Assets that are due for auditing OR overdue , based on the assets . next_audit_date
* and settings . audit_warning_days .
*
* This is / will be used in the artisan command snipeit : upcoming - audits and also
* for an upcoming API call for retrieving a report on assets that will need to be audited .
*
* @ author A . Gianotto < snipe @ snipe . net >
2019-05-05 19:31:43 -07:00
* @ since v4 . 6.16
2019-05-05 19:13:30 -07:00
* @ param Setting $settings
*
* @ return \Illuminate\Database\Query\Builder Modified query builder
*/
public function scopeDueOrOverdueForAudit ( $query , $settings )
{
2019-07-18 14:08:55 -07:00
$interval = $settings -> audit_warning_days ? ? 0 ;
Integrations/develop into master (#7352)
* Fixes #6204 - added email alerts and web/API access to assets due for audits (#6992)
* Added upcoming audit report
TODO: Fid diff/threshold math
* Added route to list overdue / upcoming assets via API
* Controller/API methods for due/overdue audits
We could probably skip this and just handle it via view in the routes…
* Added query scopes for due and overdue audits
* Added audit due console command to kernel
* Added ability to pass audit specs to main API asset search method
* Added audit presenter
* Added bootstrap-tables presenter formatter to display an audit button
* Added gated sidenav items to left nav
* Added audit due/overdue blades
* Cleanup on audit due/overdue console command
* Added language strings for audit views
* Fixed :threshold placeholder
* Removed unused setting variable
* Fixed next audit date math
* Added scope for both overdue and upcoming
* Derp. Wrong version
* Bumped version
(I will release this version officially tomorrow)
* Leave the activated state for users alone in normal LDAP synchronisation. (#6988)
* Fixed #7003 - crash when warranty months or purchase date is null
* Fixed #6956 - viewKeys policy inconsistent (#7009)
* Fixed #6956 - Added additional gates show showing/hiding license keys
* Modified gate to allow user to see licenses if they can create or edit the license as well
* Added API middleware to API routes to enable throttling
TODO: Figure out how to make this costumizable without touching the code
* Import locations from CSV via command line (#7021)
* Added import locations command
* Small fixes to location importer
* Added country, LDAP OU
* Cleaned up comments, added more clarification to what the script does
* Added ability to update groups via API
Fixes [ch9139]
* Bumped version
* Fixed #6883 - remove escaping of fields on LDAP import
* Fixed #6880 - correctly encrypt encrypted fields via the API
* Fixes #5054: LDAP users deactivated for none-ad (#7032)
When using none-AD ldap, users are automatically deactivated every LDAP
sync. This commit changes the behaviour so that if the active flag isn't set,
the users are enabled.
Fixed #5054, at least for 4.X
* Updated packages
- Updating erusev/parsedown (v1.7.2 => 1.7.3): Downloading (100%)
- Updating squizlabs/php_codesniffer (3.4.1 => 3.4.2): Downloading (100%)
- Updating symfony/polyfill-mbstring (v1.10.0 => v1.11.0): Downloading (100%)
- Updating symfony/var-dumper (v3.4.23 => v3.4.27): Downloading (100%)
- Updating league/flysystem (1.0.50 => 1.0.51): Downloading (100%)
- Updating symfony/translation (v3.4.23 => v3.4.27): Downloading (100%)
- Updating nesbot/carbon (1.36.2 => 1.37.1): Downloading (100%)
- Updating symfony/debug (v3.4.23 => v3.4.27): Downloading (100%)
- Updating symfony/console (v3.4.23 => v3.4.27): Downloading (100%)
- Updating symfony/finder (v3.4.23 => v3.4.27): Downloading (100%)
- Updating symfony/polyfill-ctype (v1.10.0 => v1.11.0): Downloading (100%)
- Updating symfony/polyfill-php70 (v1.10.0 => v1.11.0): Downloading (100%)
- Updating symfony/http-foundation (v3.4.23 => v3.4.27): Downloading (100%)
- Updating symfony/event-dispatcher (v3.4.23 => v3.4.27): Downloading (100%)
- Updating symfony/http-kernel (v3.4.23 => v3.4.27): Downloading (100%)
- Updating symfony/process (v3.4.23 => v3.4.27): Downloading (100%)
- Updating symfony/routing (v3.4.23 => v3.4.27): Downloading (100%)
- Updating symfony/polyfill-util (v1.10.0 => v1.11.0): Downloading (100%)
- Updating symfony/polyfill-php56 (v1.10.0 => v1.11.0): Downloading (100%)
- Updating symfony/psr-http-message-bridge (v1.1.1 => v1.1.2): Downloading (failed)
Downloading (100%)
- Updating rollbar/rollbar (v1.7.5 => v1.8.1): Downloading (100%)
- Updating symfony/yaml (v3.4.23 => v3.4.27): Downloading (100%)
- Updating symfony/browser-kit (v3.4.23 => v3.4.27): Downloading (100%)
* Fixed #7044 - API update deleted custom fields if they are not re-presented
* Fixed XSS vulnerability when creating a new categories, etc via modal on create
Same fix as before, because of the weird select2 post-parsing ajax behavior
* Updated email strings
* Fixed #7046 - added user website url back into UI
* Updated language strings
* Bumped version
* Updated packages
* New backups config for spatie
* Removed debugbar service provider (autodiscovery)
* Use laravel v5.5 withCount manual aliases
* Added spatie language files
* Removed old laravel backups config
This config file was renamed in a newer version of spatie laravel-backup
* Set the serialization
* Added the command loader to console kernel
* Renamed fire() to handle()
* Updated withCount to use manual naming
* Updated backup path in backup admin
* Updated travis with new php versions
* Bumped laravel version in readme
* Fixed custom field edit screen
* Fixed baseUrl is undefined error
I literally cannot figure out how this ever worked before.
* Fix for included files in backup
* Bumped version
* Switch has() to filled()
* Change ->has() to ->filled()
* Removed cosole log
* Bumped packages
* Use getReader instead of fetchAssoc for CSV parser
https://csv.thephpleague.com/9.0/upgrading/
* Handle JSON validation errors like 5.4
* Handle JSON validation errors like 5.4
* Handle JSON validation errors like 5.4
* Trying to fix ajax asset validation
This I think gets us closer, but still not handling the validation on the asset properly.
When I do a print_r of the validation in the other items, its looking for an error bag that looks something like this:
```
Illuminate\Support\MessageBag Object
(
[messages:protected] => Array
(
[name] => Array
(
[0] => The name field is required.
)
[seats] => Array
(
[0] => The seats field is required.
)
[category_id] => Array
(
[0] => The category id field is required.
)
)
[format:protected] => :message
)
```
Currently the Assets ajax returns:
```
[2019-05-24 06:52:06] develop.ERROR: array (
'messages' =>
array (
'model_id' =>
array (
0 => 'The model id field is required.',
),
'status_id' =>
array (
0 => 'The status id field is required.',
),
'asset_tag' =>
array (
0 => 'The asset tag field is required.',
),
),
)
```
So not sure why it’s not working.
* Fixed missing asset validation
* Check that a model exists before trying to fiddle with fieldsets
* Tidied up license check
* Removed extra escaping on checkin
* Updated importer to work with newer CSV Reader::getRecords() method
* Fixed field mapping
* Small fix for reordering fields
Fixes Illuminate\Database\QueryException: SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'order' cannot be null (SQL: insert into `custom_field_custom_fieldset` (`custom_field_id`, `custom_fieldset_id`, `order`, `required`) values (12, 7, , 0)) [ch1151]
This needs revisiting for a more solid fix, especially for data that was already entered bad.
* Fixed bug where sorting by company name in Users API did not work
Fixes [ch9200]
* Removed custom fields from AssignedSearch to prevent confusing data in selectlist
Fixes [ch9193]
* Removed alert-danger from tests
* Fixed missed consumables_count withCount() statement
* Fixed Undefined variable user in $backto if checked out to a non-user
Fixes [ch9194]
* Check for valid model before attempting to access fieldsets
Fixes [ch1249]
* Only build the log upload destination path if there is a matching record
Fixes [ch1232]
* Fixed free_seats_count variable name
(I forgot that Laravel switched camel case to snake case for their old 5.4 withCount variables)
* Only gtry to delete the file if a record is found in the log
* Only try to get fieldset if model is valid
* Fixed more camel-casing -> snake-casing
* Only display the file if the log record can be found
* Fixed casing in sync command
* Updated README
* Derp - typo
* Added link to Atlassian plugin
* More Atlassian clarifications
* Show accessory image on view page
* Increased image size to 800px, added lightboxes
* Fixed #7083 - Removed user_exists constraint on department save
If the user has been deleted, this prevented the department from being successfully saved on edit
* Updated branch in version file
* Dockerfile update to bring us up to php v7.1 for Laravel 5.5 (#7084)
* bump up to php7.1
& change deprecated MAINTAINER to a LABEL so it is visible with `docker inspect`
* AND modapache ><
* 2 updates required to get software-properties+ppa
* Bumped version
* Bumped release again :(
* Missed one
* Fixed #7098 - updated backup config for deleteFile() method
* Fixed #7092 - handle weird port forwarding/port numbers for baseUrl
* Bumped version
* Fixed #7099 - set email to null by default for backup notifications
* Removed old comments
* Fixed #7100 - Check if $user isset on checkin
* Increased throttle to 120 requests per minute
* Added Filipino, corrected order for Spanish variations
* Update language strings
* Bumped hash
* Changed has to filled to fix bulk asset editing
* Bumped point version
* Small fixes for phpleague CSB reader v9
* Improved error checking in locations importer
* Fixed #7145 - rename groups table to permissions_group for mysql 8 reserved word compatibility
* Reduce minimum group name length to 2 (from 3)
eg: IT
* Back in time fix FOR #7145 for new installs on MySQL 8+
* Fixed permission insert
//TODO
Handle this via model
* Possible fix for reporting/admin migration back in time
* Fixed #7164 - change table name to permission_groups
* Fixed LDAP password blanking on save
* fixing previous commit's actual wiping of password (#7183)
replaced Input::fille('ldap_pword') with _filled_. Should be good to go.
https://github.com/snipe/snipe-it/issues/7179
https://github.com/snipe/snipe-it/issues/7169
* Bumped version
* Downgrading rollbar for Laravel 5.5
* Spelling Correction (#7206)
Fixed Spelling for the word reqrite, to be rewrite.
* Fix #6910: Add logic to manipulate the eloquent query. (#7006)
* Added company_id to consumables_users table
* Added logic to manage when a pivot table doesn't have the column company_id trough a join with users
* Remove a migration that tries to fix this problem, but is not longer necessary
* Addresses #7238 - add PWA code to layout
Needs additional UX testing
* Better log message for bad LDAP connection
* Fixed #7186 - has vs filled in User’s API blanking out groups if no group_ids are passed
* Comment clarification on #7186
* Check for valid seat on hardware view
* Added space between footer and custom message
* Cap warranty months to three characters
Filles rollbar 209
* Cap warranty months to 3 on the frontend blade
* Fixed countable() strings on user destroy
* Check that the user has assets and that the aset model is valid
* Bumped hash
* Caps asset warranty to 20 years
* Command to fix custom field unicode conversion differences between PHP versions (#7263)
* Fixes #7252 form request changes (#7272)
* Fixes for #7252 - custom fields not validating / no validaton messages in API w/form requests
* Removed debug info
* More fixes for #7252
This is mostly working as intended, if not yet the way Laravel wants us to do it.
Right now, the API returns correctly, and the form UI will return highlighted errors, with the input filled in ~sometimes~. I’m not sure why it’s only sometimes yet, but this is potentially progress.
* Removed experimental method
* Check for digits_between:0,240 for warranty
* Removed debug code
* Apply fix from PR #7273 to master
* Bumped hash
* Fixed #7250 - permission issue for API fieldsets and fields endpoints
This applies the change from #7294 to master
* Add @mskrip as a contributor
* Fixed #7270 - Checking-in Assets via API Removes the Item's Asset Name
* CORS for api (#7292)
* Added CORS support to API
* Changed order so CORS will still work if throttle hit
* Added APP_CORS_ALLOWED_ORIGINS env option
* Fixed typo
* Clarified header comments
* More clarification
* DIsable CORS allowed origins by default to replicate existing behavior
* Change variable name to be clearer
* Bumped version
* Added condition to deal with fieldname 'rtd_location' which can be tried to be queried in some places and doesn't exist in database (#7317)
* Added comments to the ByFilter query scope for clarity
* Added accessories checkout/checkin API endpoint
* Fixed CVE-2019-10742
https://nvd.nist.gov/vuln/detail/CVE-2019-10742
* Update README.md (#7334)
Add reference to CSV importer.
* Group related variables in .env
* History importer fixes
* Fixes to history importer
2019-08-14 21:48:14 -07:00
2019-05-05 19:13:30 -07:00
return $query -> whereNotNull ( 'assets.next_audit_date' )
2019-07-18 14:08:55 -07:00
-> whereRaw ( " DATE_SUB(assets.next_audit_date, INTERVAL $interval DAY) <= ' " . Carbon :: now () . " ' " )
2019-05-05 19:13:30 -07:00
-> where ( 'assets.archived' , '=' , 0 )
-> NotArchived ();
}
2016-03-25 01:18:05 -07:00
/**
* Query builder scope for Archived assets
*
2017-02-03 19:34:24 -08:00
* @ param \Illuminate\Database\Query\Builder $query Query builder instance
2016-03-25 01:18:05 -07:00
*
2017-02-03 19:34:24 -08:00
* @ return \Illuminate\Database\Query\Builder Modified query builder
2016-03-25 01:18:05 -07:00
*/
public function scopeArchived ( $query )
{
return $query -> whereHas ( 'assetstatus' , function ( $query ) {
$query -> where ( 'deployable' , '=' , 0 )
-> where ( 'pending' , '=' , 0 )
-> where ( 'archived' , '=' , 1 );
});
}
/**
* Query builder scope for Deployed assets
*
2017-02-03 19:34:24 -08:00
* @ param \Illuminate\Database\Query\Builder $query Query builder instance
2016-03-25 01:18:05 -07:00
*
2017-02-03 19:34:24 -08:00
* @ return \Illuminate\Database\Query\Builder Modified query builder
2016-03-25 01:18:05 -07:00
*/
public function scopeDeployed ( $query )
{
return $query -> where ( 'assigned_to' , '>' , '0' );
}
/**
* Query builder scope for Requestable assets
*
2017-02-03 19:34:24 -08:00
* @ param \Illuminate\Database\Query\Builder $query Query builder instance
2016-03-25 01:18:05 -07:00
*
2017-02-03 19:34:24 -08:00
* @ return \Illuminate\Database\Query\Builder Modified query builder
2016-03-25 01:18:05 -07:00
*/
public function scopeRequestableAssets ( $query )
{
2016-07-26 16:22:56 -07:00
return Company :: scopeCompanyables ( $query -> where ( 'requestable' , '=' , 1 ))
2016-04-19 20:23:04 -07:00
-> whereHas ( 'assetstatus' , function ( $query ) {
2016-06-22 12:27:41 -07:00
$query -> where ( 'deployable' , '=' , 1 )
2016-04-19 20:23:04 -07:00
-> where ( 'pending' , '=' , 0 )
-> where ( 'archived' , '=' , 0 );
});
2016-03-25 01:18:05 -07:00
}
/**
* scopeInModelList
* Get all assets in the provided listing of model ids
*
* @ param $query
* @ param array $modelIdListing
*
* @ return mixed
* @ author Vincent Sposato < vincent . sposato @ gmail . com >
* @ version v1 . 0
*/
public function scopeInModelList ( $query , array $modelIdListing )
{
2017-11-08 20:03:26 -08:00
return $query -> whereIn ( 'assets.model_id' , $modelIdListing );
2016-03-25 01:18:05 -07:00
}
/**
* Query builder scope to get not - yet - accepted assets
*
2017-02-03 19:34:24 -08:00
* @ param \Illuminate\Database\Query\Builder $query Query builder instance
2016-03-25 01:18:05 -07:00
*
2017-02-03 19:34:24 -08:00
* @ return \Illuminate\Database\Query\Builder Modified query builder
2016-03-25 01:18:05 -07:00
*/
public function scopeNotYetAccepted ( $query )
{
return $query -> where ( " accepted " , " = " , " pending " );
}
/**
* Query builder scope to get rejected assets
*
2017-02-03 19:34:24 -08:00
* @ param \Illuminate\Database\Query\Builder $query Query builder instance
2016-03-25 01:18:05 -07:00
*
2017-02-03 19:34:24 -08:00
* @ return \Illuminate\Database\Query\Builder Modified query builder
2016-03-25 01:18:05 -07:00
*/
public function scopeRejected ( $query )
{
return $query -> where ( " accepted " , " = " , " rejected " );
}
/**
* Query builder scope to get accepted assets
*
2017-06-15 19:42:43 -07:00
* @ param \Illuminate\Database\Query\Builder $query Query builder instance
2016-03-25 01:18:05 -07:00
*
2017-06-15 19:42:43 -07:00
* @ return \Illuminate\Database\Query\Builder Modified query builder
2016-03-25 01:18:05 -07:00
*/
public function scopeAccepted ( $query )
{
2016-07-15 11:11:48 -07:00
return $query -> where ( " accepted " , " = " , " accepted " );
2016-03-25 01:18:05 -07:00
}
2017-11-16 16:49:16 -08:00
/**
* Query builder scope to search on text for complex Bootstrap Tables API .
*
* @ param \Illuminate\Database\Query\Builder $query Query builder instance
* @ param text $search Search term
*
* @ return \Illuminate\Database\Query\Builder Modified query builder
*/
public function scopeAssignedSearch ( $query , $search )
{
$search = explode ( ' OR ' , $search );
return $query -> leftJoin ( 'users as assets_users' , function ( $leftJoin ) {
$leftJoin -> on ( " assets_users.id " , " = " , " assets.assigned_to " )
-> where ( " assets.assigned_type " , " = " , User :: class );
}) -> leftJoin ( 'locations as assets_locations' , function ( $leftJoin ) {
$leftJoin -> on ( " assets_locations.id " , " = " , " assets.assigned_to " )
-> where ( " assets.assigned_type " , " = " , Location :: class );
}) -> leftJoin ( 'assets as assigned_assets' , function ( $leftJoin ) {
$leftJoin -> on ( 'assigned_assets.id' , '=' , 'assets.assigned_to' )
-> where ( 'assets.assigned_type' , '=' , Asset :: class );
}) -> where ( function ( $query ) use ( $search ) {
foreach ( $search as $search ) {
$query -> whereHas ( 'model' , function ( $query ) use ( $search ) {
$query -> whereHas ( 'category' , function ( $query ) use ( $search ) {
$query -> where ( function ( $query ) use ( $search ) {
$query -> where ( 'categories.name' , 'LIKE' , '%' . $search . '%' )
-> orWhere ( 'models.name' , 'LIKE' , '%' . $search . '%' )
-> orWhere ( 'models.model_number' , 'LIKE' , '%' . $search . '%' );
});
});
}) -> orWhereHas ( 'model' , function ( $query ) use ( $search ) {
$query -> whereHas ( 'manufacturer' , function ( $query ) use ( $search ) {
$query -> where ( function ( $query ) use ( $search ) {
$query -> where ( 'manufacturers.name' , 'LIKE' , '%' . $search . '%' );
});
});
}) -> orWhere ( function ( $query ) use ( $search ) {
$query -> where ( 'assets_users.first_name' , 'LIKE' , '%' . $search . '%' )
-> orWhere ( 'assets_users.last_name' , 'LIKE' , '%' . $search . '%' )
2017-12-28 20:09:36 -08:00
-> orWhereRaw ( 'CONCAT(' . DB :: getTablePrefix () . 'assets_users.first_name," ",' . DB :: getTablePrefix () . 'assets_users.last_name) LIKE ?' , [ " % $search % " , " % $search % " ])
2017-11-16 16:49:16 -08:00
-> orWhere ( 'assets_users.username' , 'LIKE' , '%' . $search . '%' )
-> orWhere ( 'assets_locations.name' , 'LIKE' , '%' . $search . '%' )
-> orWhere ( 'assigned_assets.name' , 'LIKE' , '%' . $search . '%' );
2016-03-25 01:18:05 -07:00
}) -> orWhere ( 'assets.name' , 'LIKE' , '%' . $search . '%' )
-> orWhere ( 'assets.asset_tag' , 'LIKE' , '%' . $search . '%' )
-> orWhere ( 'assets.serial' , 'LIKE' , '%' . $search . '%' )
-> orWhere ( 'assets.order_number' , 'LIKE' , '%' . $search . '%' )
-> orWhere ( 'assets.notes' , 'LIKE' , '%' . $search . '%' );
}
foreach ( CustomField :: all () as $field ) {
2017-09-29 01:21:08 -07:00
$query -> orWhere ( 'assets.' . $field -> db_column_name (), 'LIKE' , " % $search % " );
2016-03-25 01:18:05 -07:00
}
2017-09-29 01:21:08 -07:00
}) -> withTrashed () -> whereNull ( " assets.deleted_at " ); //workaround for laravel bug
2016-03-25 01:18:05 -07:00
}
2018-10-31 15:19:13 -07:00
/**
* Query builder scope to search the department ID of users assigned to assets
*
* @ author [ A . Gianotto ] [ < snipe @ snipe . net > ]
* @ since [ v5 . 0 ]
* @ return string | false
*
* @ return \Illuminate\Database\Query\Builder Modified query builder
*/
public function scopeCheckedOutToTargetInDepartment ( $query , $search )
{
return $query -> leftJoin ( 'users as assets_dept_users' , function ( $leftJoin ) {
$leftJoin -> on ( " assets_dept_users.id " , " = " , " assets.assigned_to " )
-> where ( " assets.assigned_type " , " = " , User :: class );
}) -> where ( function ( $query ) use ( $search ) {
$query -> where ( 'assets_dept_users.department_id' , '=' , $search );
}) -> withTrashed () -> whereNull ( " assets.deleted_at " ); //workaround for laravel bug
}
2017-03-11 04:26:01 -08:00
/**
* Query builder scope to search on text filters for complex Bootstrap Tables API
*
* @ param \Illuminate\Database\Query\Builder $query Query builder instance
* @ param text $filter JSON array of search keys and terms
*
* @ return \Illuminate\Database\Query\Builder Modified query builder
*/
public function scopeByFilter ( $query , $filter )
{
return $query -> where ( function ( $query ) use ( $filter ) {
foreach ( $filter as $key => $search_val ) {
2017-10-18 10:07:35 -07:00
$fieldname = str_replace ( 'custom_fields.' , '' , $key ) ;
if ( $fieldname == 'asset_tag' ) {
2017-03-11 04:26:01 -08:00
$query -> where ( 'assets.asset_tag' , 'LIKE' , '%' . $search_val . '%' );
}
2017-10-18 10:07:35 -07:00
if ( $fieldname == 'name' ) {
2017-03-11 04:26:01 -08:00
$query -> where ( 'assets.name' , 'LIKE' , '%' . $search_val . '%' );
}
2017-10-18 10:07:35 -07:00
if ( $fieldname == 'product_key' ) {
2017-03-11 04:26:01 -08:00
$query -> where ( 'assets.serial' , 'LIKE' , '%' . $search_val . '%' );
}
2017-10-18 10:07:35 -07:00
if ( $fieldname == 'purchase_date' ) {
2017-03-11 04:26:01 -08:00
$query -> where ( 'assets.purchase_date' , 'LIKE' , '%' . $search_val . '%' );
}
2017-10-18 10:07:35 -07:00
if ( $fieldname == 'purchase_cost' ) {
2017-03-11 04:26:01 -08:00
$query -> where ( 'assets.purchase_cost' , 'LIKE' , '%' . $search_val . '%' );
}
2017-10-18 10:07:35 -07:00
if ( $fieldname == 'notes' ) {
2017-03-11 04:26:01 -08:00
$query -> where ( 'assets.notes' , 'LIKE' , '%' . $search_val . '%' );
}
2017-10-18 10:07:35 -07:00
if ( $fieldname == 'order_number' ) {
2017-03-11 04:26:01 -08:00
$query -> where ( 'assets.order_number' , 'LIKE' , '%' . $search_val . '%' );
}
2017-10-18 10:07:35 -07:00
if ( $fieldname == 'status_label' ) {
2017-03-11 04:26:01 -08:00
$query -> whereHas ( 'assetstatus' , function ( $query ) use ( $search_val ) {
$query -> where ( 'status_labels.name' , 'LIKE' , '%' . $search_val . '%' );
});
}
2017-10-18 10:07:35 -07:00
if ( $fieldname == 'location' ) {
2017-11-02 08:06:10 -07:00
$query -> whereHas ( 'location' , function ( $query ) use ( $search_val ) {
2017-03-11 04:26:01 -08:00
$query -> where ( 'locations.name' , 'LIKE' , '%' . $search_val . '%' );
});
}
2017-10-18 10:07:35 -07:00
if ( $fieldname == 'checkedout_to' ) {
2017-10-05 00:35:37 -07:00
$query -> whereHas ( 'assigneduser' , function ( $query ) use ( $search_val ) {
$query -> where ( function ( $query ) use ( $search_val ) {
$query -> where ( 'users.first_name' , 'LIKE' , '%' . $search_val . '%' )
-> orWhere ( 'users.last_name' , 'LIKE' , '%' . $search_val . '%' );
2017-03-11 04:26:01 -08:00
});
});
}
2017-10-18 10:07:35 -07:00
if ( $fieldname == 'manufacturer' ) {
2017-03-11 04:26:01 -08:00
$query -> whereHas ( 'model' , function ( $query ) use ( $search_val ) {
$query -> whereHas ( 'manufacturer' , function ( $query ) use ( $search_val ) {
$query -> where ( function ( $query ) use ( $search_val ) {
$query -> where ( 'manufacturers.name' , 'LIKE' , '%' . $search_val . '%' );
});
});
});
}
2017-10-18 10:07:35 -07:00
if ( $fieldname == 'category' ) {
2017-10-05 00:35:37 -07:00
$query -> whereHas ( 'model' , function ( $query ) use ( $search_val ) {
$query -> whereHas ( 'category' , function ( $query ) use ( $search_val ) {
2017-03-11 04:26:01 -08:00
$query -> where ( function ( $query ) use ( $search_val ) {
$query -> where ( 'categories.name' , 'LIKE' , '%' . $search_val . '%' )
-> orWhere ( 'models.name' , 'LIKE' , '%' . $search_val . '%' )
-> orWhere ( 'models.model_number' , 'LIKE' , '%' . $search_val . '%' );
});
});
});
}
2017-10-18 10:07:35 -07:00
if ( $fieldname == 'model' ) {
2017-03-11 04:26:01 -08:00
$query -> where ( function ( $query ) use ( $search_val ) {
$query -> whereHas ( 'model' , function ( $query ) use ( $search_val ) {
$query -> where ( 'models.name' , 'LIKE' , '%' . $search_val . '%' );
});
});
}
2017-10-18 10:07:35 -07:00
if ( $fieldname == 'model_number' ) {
2017-03-11 04:26:01 -08:00
$query -> where ( function ( $query ) use ( $search_val ) {
$query -> whereHas ( 'model' , function ( $query ) use ( $search_val ) {
$query -> where ( 'models.model_number' , 'LIKE' , '%' . $search_val . '%' );
});
});
}
2017-10-18 10:07:35 -07:00
if ( $fieldname == 'company' ) {
2017-03-11 04:26:01 -08:00
$query -> where ( function ( $query ) use ( $search_val ) {
$query -> whereHas ( 'company' , function ( $query ) use ( $search_val ) {
$query -> where ( 'companies.name' , 'LIKE' , '%' . $search_val . '%' );
});
});
}
2018-04-25 20:25:03 -07:00
if ( $fieldname == 'supplier' ) {
$query -> where ( function ( $query ) use ( $search_val ) {
$query -> whereHas ( 'supplier' , function ( $query ) use ( $search_val ) {
$query -> where ( 'suppliers.name' , 'LIKE' , '%' . $search_val . '%' );
});
});
}
2017-03-11 04:26:01 -08:00
}
2019-07-31 14:29:19 -07:00
/**
* THIS CLUNKY BIT IS VERY IMPORTANT
*
* Although inelegant , this section matters a lot when querying against fields that do not
* exist on the asset table . There ' s probably a better way to do this moving forward , for
* example using the Schema :: methods to determine whether or not a column actually exists ,
* or even just using the $searchableRelations variable earlier in this file .
*
* In short , this set of statements tells the query builder to ONLY query against an
* actual field that 's being passed if it doesn' t meet known relational fields . This
Integrations/develop into master (#7352)
* Fixes #6204 - added email alerts and web/API access to assets due for audits (#6992)
* Added upcoming audit report
TODO: Fid diff/threshold math
* Added route to list overdue / upcoming assets via API
* Controller/API methods for due/overdue audits
We could probably skip this and just handle it via view in the routes…
* Added query scopes for due and overdue audits
* Added audit due console command to kernel
* Added ability to pass audit specs to main API asset search method
* Added audit presenter
* Added bootstrap-tables presenter formatter to display an audit button
* Added gated sidenav items to left nav
* Added audit due/overdue blades
* Cleanup on audit due/overdue console command
* Added language strings for audit views
* Fixed :threshold placeholder
* Removed unused setting variable
* Fixed next audit date math
* Added scope for both overdue and upcoming
* Derp. Wrong version
* Bumped version
(I will release this version officially tomorrow)
* Leave the activated state for users alone in normal LDAP synchronisation. (#6988)
* Fixed #7003 - crash when warranty months or purchase date is null
* Fixed #6956 - viewKeys policy inconsistent (#7009)
* Fixed #6956 - Added additional gates show showing/hiding license keys
* Modified gate to allow user to see licenses if they can create or edit the license as well
* Added API middleware to API routes to enable throttling
TODO: Figure out how to make this costumizable without touching the code
* Import locations from CSV via command line (#7021)
* Added import locations command
* Small fixes to location importer
* Added country, LDAP OU
* Cleaned up comments, added more clarification to what the script does
* Added ability to update groups via API
Fixes [ch9139]
* Bumped version
* Fixed #6883 - remove escaping of fields on LDAP import
* Fixed #6880 - correctly encrypt encrypted fields via the API
* Fixes #5054: LDAP users deactivated for none-ad (#7032)
When using none-AD ldap, users are automatically deactivated every LDAP
sync. This commit changes the behaviour so that if the active flag isn't set,
the users are enabled.
Fixed #5054, at least for 4.X
* Updated packages
- Updating erusev/parsedown (v1.7.2 => 1.7.3): Downloading (100%)
- Updating squizlabs/php_codesniffer (3.4.1 => 3.4.2): Downloading (100%)
- Updating symfony/polyfill-mbstring (v1.10.0 => v1.11.0): Downloading (100%)
- Updating symfony/var-dumper (v3.4.23 => v3.4.27): Downloading (100%)
- Updating league/flysystem (1.0.50 => 1.0.51): Downloading (100%)
- Updating symfony/translation (v3.4.23 => v3.4.27): Downloading (100%)
- Updating nesbot/carbon (1.36.2 => 1.37.1): Downloading (100%)
- Updating symfony/debug (v3.4.23 => v3.4.27): Downloading (100%)
- Updating symfony/console (v3.4.23 => v3.4.27): Downloading (100%)
- Updating symfony/finder (v3.4.23 => v3.4.27): Downloading (100%)
- Updating symfony/polyfill-ctype (v1.10.0 => v1.11.0): Downloading (100%)
- Updating symfony/polyfill-php70 (v1.10.0 => v1.11.0): Downloading (100%)
- Updating symfony/http-foundation (v3.4.23 => v3.4.27): Downloading (100%)
- Updating symfony/event-dispatcher (v3.4.23 => v3.4.27): Downloading (100%)
- Updating symfony/http-kernel (v3.4.23 => v3.4.27): Downloading (100%)
- Updating symfony/process (v3.4.23 => v3.4.27): Downloading (100%)
- Updating symfony/routing (v3.4.23 => v3.4.27): Downloading (100%)
- Updating symfony/polyfill-util (v1.10.0 => v1.11.0): Downloading (100%)
- Updating symfony/polyfill-php56 (v1.10.0 => v1.11.0): Downloading (100%)
- Updating symfony/psr-http-message-bridge (v1.1.1 => v1.1.2): Downloading (failed)
Downloading (100%)
- Updating rollbar/rollbar (v1.7.5 => v1.8.1): Downloading (100%)
- Updating symfony/yaml (v3.4.23 => v3.4.27): Downloading (100%)
- Updating symfony/browser-kit (v3.4.23 => v3.4.27): Downloading (100%)
* Fixed #7044 - API update deleted custom fields if they are not re-presented
* Fixed XSS vulnerability when creating a new categories, etc via modal on create
Same fix as before, because of the weird select2 post-parsing ajax behavior
* Updated email strings
* Fixed #7046 - added user website url back into UI
* Updated language strings
* Bumped version
* Updated packages
* New backups config for spatie
* Removed debugbar service provider (autodiscovery)
* Use laravel v5.5 withCount manual aliases
* Added spatie language files
* Removed old laravel backups config
This config file was renamed in a newer version of spatie laravel-backup
* Set the serialization
* Added the command loader to console kernel
* Renamed fire() to handle()
* Updated withCount to use manual naming
* Updated backup path in backup admin
* Updated travis with new php versions
* Bumped laravel version in readme
* Fixed custom field edit screen
* Fixed baseUrl is undefined error
I literally cannot figure out how this ever worked before.
* Fix for included files in backup
* Bumped version
* Switch has() to filled()
* Change ->has() to ->filled()
* Removed cosole log
* Bumped packages
* Use getReader instead of fetchAssoc for CSV parser
https://csv.thephpleague.com/9.0/upgrading/
* Handle JSON validation errors like 5.4
* Handle JSON validation errors like 5.4
* Handle JSON validation errors like 5.4
* Trying to fix ajax asset validation
This I think gets us closer, but still not handling the validation on the asset properly.
When I do a print_r of the validation in the other items, its looking for an error bag that looks something like this:
```
Illuminate\Support\MessageBag Object
(
[messages:protected] => Array
(
[name] => Array
(
[0] => The name field is required.
)
[seats] => Array
(
[0] => The seats field is required.
)
[category_id] => Array
(
[0] => The category id field is required.
)
)
[format:protected] => :message
)
```
Currently the Assets ajax returns:
```
[2019-05-24 06:52:06] develop.ERROR: array (
'messages' =>
array (
'model_id' =>
array (
0 => 'The model id field is required.',
),
'status_id' =>
array (
0 => 'The status id field is required.',
),
'asset_tag' =>
array (
0 => 'The asset tag field is required.',
),
),
)
```
So not sure why it’s not working.
* Fixed missing asset validation
* Check that a model exists before trying to fiddle with fieldsets
* Tidied up license check
* Removed extra escaping on checkin
* Updated importer to work with newer CSV Reader::getRecords() method
* Fixed field mapping
* Small fix for reordering fields
Fixes Illuminate\Database\QueryException: SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'order' cannot be null (SQL: insert into `custom_field_custom_fieldset` (`custom_field_id`, `custom_fieldset_id`, `order`, `required`) values (12, 7, , 0)) [ch1151]
This needs revisiting for a more solid fix, especially for data that was already entered bad.
* Fixed bug where sorting by company name in Users API did not work
Fixes [ch9200]
* Removed custom fields from AssignedSearch to prevent confusing data in selectlist
Fixes [ch9193]
* Removed alert-danger from tests
* Fixed missed consumables_count withCount() statement
* Fixed Undefined variable user in $backto if checked out to a non-user
Fixes [ch9194]
* Check for valid model before attempting to access fieldsets
Fixes [ch1249]
* Only build the log upload destination path if there is a matching record
Fixes [ch1232]
* Fixed free_seats_count variable name
(I forgot that Laravel switched camel case to snake case for their old 5.4 withCount variables)
* Only gtry to delete the file if a record is found in the log
* Only try to get fieldset if model is valid
* Fixed more camel-casing -> snake-casing
* Only display the file if the log record can be found
* Fixed casing in sync command
* Updated README
* Derp - typo
* Added link to Atlassian plugin
* More Atlassian clarifications
* Show accessory image on view page
* Increased image size to 800px, added lightboxes
* Fixed #7083 - Removed user_exists constraint on department save
If the user has been deleted, this prevented the department from being successfully saved on edit
* Updated branch in version file
* Dockerfile update to bring us up to php v7.1 for Laravel 5.5 (#7084)
* bump up to php7.1
& change deprecated MAINTAINER to a LABEL so it is visible with `docker inspect`
* AND modapache ><
* 2 updates required to get software-properties+ppa
* Bumped version
* Bumped release again :(
* Missed one
* Fixed #7098 - updated backup config for deleteFile() method
* Fixed #7092 - handle weird port forwarding/port numbers for baseUrl
* Bumped version
* Fixed #7099 - set email to null by default for backup notifications
* Removed old comments
* Fixed #7100 - Check if $user isset on checkin
* Increased throttle to 120 requests per minute
* Added Filipino, corrected order for Spanish variations
* Update language strings
* Bumped hash
* Changed has to filled to fix bulk asset editing
* Bumped point version
* Small fixes for phpleague CSB reader v9
* Improved error checking in locations importer
* Fixed #7145 - rename groups table to permissions_group for mysql 8 reserved word compatibility
* Reduce minimum group name length to 2 (from 3)
eg: IT
* Back in time fix FOR #7145 for new installs on MySQL 8+
* Fixed permission insert
//TODO
Handle this via model
* Possible fix for reporting/admin migration back in time
* Fixed #7164 - change table name to permission_groups
* Fixed LDAP password blanking on save
* fixing previous commit's actual wiping of password (#7183)
replaced Input::fille('ldap_pword') with _filled_. Should be good to go.
https://github.com/snipe/snipe-it/issues/7179
https://github.com/snipe/snipe-it/issues/7169
* Bumped version
* Downgrading rollbar for Laravel 5.5
* Spelling Correction (#7206)
Fixed Spelling for the word reqrite, to be rewrite.
* Fix #6910: Add logic to manipulate the eloquent query. (#7006)
* Added company_id to consumables_users table
* Added logic to manage when a pivot table doesn't have the column company_id trough a join with users
* Remove a migration that tries to fix this problem, but is not longer necessary
* Addresses #7238 - add PWA code to layout
Needs additional UX testing
* Better log message for bad LDAP connection
* Fixed #7186 - has vs filled in User’s API blanking out groups if no group_ids are passed
* Comment clarification on #7186
* Check for valid seat on hardware view
* Added space between footer and custom message
* Cap warranty months to three characters
Filles rollbar 209
* Cap warranty months to 3 on the frontend blade
* Fixed countable() strings on user destroy
* Check that the user has assets and that the aset model is valid
* Bumped hash
* Caps asset warranty to 20 years
* Command to fix custom field unicode conversion differences between PHP versions (#7263)
* Fixes #7252 form request changes (#7272)
* Fixes for #7252 - custom fields not validating / no validaton messages in API w/form requests
* Removed debug info
* More fixes for #7252
This is mostly working as intended, if not yet the way Laravel wants us to do it.
Right now, the API returns correctly, and the form UI will return highlighted errors, with the input filled in ~sometimes~. I’m not sure why it’s only sometimes yet, but this is potentially progress.
* Removed experimental method
* Check for digits_between:0,240 for warranty
* Removed debug code
* Apply fix from PR #7273 to master
* Bumped hash
* Fixed #7250 - permission issue for API fieldsets and fields endpoints
This applies the change from #7294 to master
* Add @mskrip as a contributor
* Fixed #7270 - Checking-in Assets via API Removes the Item's Asset Name
* CORS for api (#7292)
* Added CORS support to API
* Changed order so CORS will still work if throttle hit
* Added APP_CORS_ALLOWED_ORIGINS env option
* Fixed typo
* Clarified header comments
* More clarification
* DIsable CORS allowed origins by default to replicate existing behavior
* Change variable name to be clearer
* Bumped version
* Added condition to deal with fieldname 'rtd_location' which can be tried to be queried in some places and doesn't exist in database (#7317)
* Added comments to the ByFilter query scope for clarity
* Added accessories checkout/checkin API endpoint
* Fixed CVE-2019-10742
https://nvd.nist.gov/vuln/detail/CVE-2019-10742
* Update README.md (#7334)
Add reference to CSV importer.
* Group related variables in .env
* History importer fixes
* Fixes to history importer
2019-08-14 21:48:14 -07:00
* allows us to query custom fields directly in the assetsv table
2019-07-31 14:29:19 -07:00
* ( regardless of their name ) and * skip * any fields that we already know can only be
* searched through relational searches that we do earlier in this method .
*
* For example , we do not store " location " as a field on the assets table , we store
* that relationship through location_id on the assets table , therefore querying
* assets . location would fail , as that field doesn 't exist -- plus we' re already searching
* against those relationships earlier in this method .
*
Integrations/develop into master (#7352)
* Fixes #6204 - added email alerts and web/API access to assets due for audits (#6992)
* Added upcoming audit report
TODO: Fid diff/threshold math
* Added route to list overdue / upcoming assets via API
* Controller/API methods for due/overdue audits
We could probably skip this and just handle it via view in the routes…
* Added query scopes for due and overdue audits
* Added audit due console command to kernel
* Added ability to pass audit specs to main API asset search method
* Added audit presenter
* Added bootstrap-tables presenter formatter to display an audit button
* Added gated sidenav items to left nav
* Added audit due/overdue blades
* Cleanup on audit due/overdue console command
* Added language strings for audit views
* Fixed :threshold placeholder
* Removed unused setting variable
* Fixed next audit date math
* Added scope for both overdue and upcoming
* Derp. Wrong version
* Bumped version
(I will release this version officially tomorrow)
* Leave the activated state for users alone in normal LDAP synchronisation. (#6988)
* Fixed #7003 - crash when warranty months or purchase date is null
* Fixed #6956 - viewKeys policy inconsistent (#7009)
* Fixed #6956 - Added additional gates show showing/hiding license keys
* Modified gate to allow user to see licenses if they can create or edit the license as well
* Added API middleware to API routes to enable throttling
TODO: Figure out how to make this costumizable without touching the code
* Import locations from CSV via command line (#7021)
* Added import locations command
* Small fixes to location importer
* Added country, LDAP OU
* Cleaned up comments, added more clarification to what the script does
* Added ability to update groups via API
Fixes [ch9139]
* Bumped version
* Fixed #6883 - remove escaping of fields on LDAP import
* Fixed #6880 - correctly encrypt encrypted fields via the API
* Fixes #5054: LDAP users deactivated for none-ad (#7032)
When using none-AD ldap, users are automatically deactivated every LDAP
sync. This commit changes the behaviour so that if the active flag isn't set,
the users are enabled.
Fixed #5054, at least for 4.X
* Updated packages
- Updating erusev/parsedown (v1.7.2 => 1.7.3): Downloading (100%)
- Updating squizlabs/php_codesniffer (3.4.1 => 3.4.2): Downloading (100%)
- Updating symfony/polyfill-mbstring (v1.10.0 => v1.11.0): Downloading (100%)
- Updating symfony/var-dumper (v3.4.23 => v3.4.27): Downloading (100%)
- Updating league/flysystem (1.0.50 => 1.0.51): Downloading (100%)
- Updating symfony/translation (v3.4.23 => v3.4.27): Downloading (100%)
- Updating nesbot/carbon (1.36.2 => 1.37.1): Downloading (100%)
- Updating symfony/debug (v3.4.23 => v3.4.27): Downloading (100%)
- Updating symfony/console (v3.4.23 => v3.4.27): Downloading (100%)
- Updating symfony/finder (v3.4.23 => v3.4.27): Downloading (100%)
- Updating symfony/polyfill-ctype (v1.10.0 => v1.11.0): Downloading (100%)
- Updating symfony/polyfill-php70 (v1.10.0 => v1.11.0): Downloading (100%)
- Updating symfony/http-foundation (v3.4.23 => v3.4.27): Downloading (100%)
- Updating symfony/event-dispatcher (v3.4.23 => v3.4.27): Downloading (100%)
- Updating symfony/http-kernel (v3.4.23 => v3.4.27): Downloading (100%)
- Updating symfony/process (v3.4.23 => v3.4.27): Downloading (100%)
- Updating symfony/routing (v3.4.23 => v3.4.27): Downloading (100%)
- Updating symfony/polyfill-util (v1.10.0 => v1.11.0): Downloading (100%)
- Updating symfony/polyfill-php56 (v1.10.0 => v1.11.0): Downloading (100%)
- Updating symfony/psr-http-message-bridge (v1.1.1 => v1.1.2): Downloading (failed)
Downloading (100%)
- Updating rollbar/rollbar (v1.7.5 => v1.8.1): Downloading (100%)
- Updating symfony/yaml (v3.4.23 => v3.4.27): Downloading (100%)
- Updating symfony/browser-kit (v3.4.23 => v3.4.27): Downloading (100%)
* Fixed #7044 - API update deleted custom fields if they are not re-presented
* Fixed XSS vulnerability when creating a new categories, etc via modal on create
Same fix as before, because of the weird select2 post-parsing ajax behavior
* Updated email strings
* Fixed #7046 - added user website url back into UI
* Updated language strings
* Bumped version
* Updated packages
* New backups config for spatie
* Removed debugbar service provider (autodiscovery)
* Use laravel v5.5 withCount manual aliases
* Added spatie language files
* Removed old laravel backups config
This config file was renamed in a newer version of spatie laravel-backup
* Set the serialization
* Added the command loader to console kernel
* Renamed fire() to handle()
* Updated withCount to use manual naming
* Updated backup path in backup admin
* Updated travis with new php versions
* Bumped laravel version in readme
* Fixed custom field edit screen
* Fixed baseUrl is undefined error
I literally cannot figure out how this ever worked before.
* Fix for included files in backup
* Bumped version
* Switch has() to filled()
* Change ->has() to ->filled()
* Removed cosole log
* Bumped packages
* Use getReader instead of fetchAssoc for CSV parser
https://csv.thephpleague.com/9.0/upgrading/
* Handle JSON validation errors like 5.4
* Handle JSON validation errors like 5.4
* Handle JSON validation errors like 5.4
* Trying to fix ajax asset validation
This I think gets us closer, but still not handling the validation on the asset properly.
When I do a print_r of the validation in the other items, its looking for an error bag that looks something like this:
```
Illuminate\Support\MessageBag Object
(
[messages:protected] => Array
(
[name] => Array
(
[0] => The name field is required.
)
[seats] => Array
(
[0] => The seats field is required.
)
[category_id] => Array
(
[0] => The category id field is required.
)
)
[format:protected] => :message
)
```
Currently the Assets ajax returns:
```
[2019-05-24 06:52:06] develop.ERROR: array (
'messages' =>
array (
'model_id' =>
array (
0 => 'The model id field is required.',
),
'status_id' =>
array (
0 => 'The status id field is required.',
),
'asset_tag' =>
array (
0 => 'The asset tag field is required.',
),
),
)
```
So not sure why it’s not working.
* Fixed missing asset validation
* Check that a model exists before trying to fiddle with fieldsets
* Tidied up license check
* Removed extra escaping on checkin
* Updated importer to work with newer CSV Reader::getRecords() method
* Fixed field mapping
* Small fix for reordering fields
Fixes Illuminate\Database\QueryException: SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'order' cannot be null (SQL: insert into `custom_field_custom_fieldset` (`custom_field_id`, `custom_fieldset_id`, `order`, `required`) values (12, 7, , 0)) [ch1151]
This needs revisiting for a more solid fix, especially for data that was already entered bad.
* Fixed bug where sorting by company name in Users API did not work
Fixes [ch9200]
* Removed custom fields from AssignedSearch to prevent confusing data in selectlist
Fixes [ch9193]
* Removed alert-danger from tests
* Fixed missed consumables_count withCount() statement
* Fixed Undefined variable user in $backto if checked out to a non-user
Fixes [ch9194]
* Check for valid model before attempting to access fieldsets
Fixes [ch1249]
* Only build the log upload destination path if there is a matching record
Fixes [ch1232]
* Fixed free_seats_count variable name
(I forgot that Laravel switched camel case to snake case for their old 5.4 withCount variables)
* Only gtry to delete the file if a record is found in the log
* Only try to get fieldset if model is valid
* Fixed more camel-casing -> snake-casing
* Only display the file if the log record can be found
* Fixed casing in sync command
* Updated README
* Derp - typo
* Added link to Atlassian plugin
* More Atlassian clarifications
* Show accessory image on view page
* Increased image size to 800px, added lightboxes
* Fixed #7083 - Removed user_exists constraint on department save
If the user has been deleted, this prevented the department from being successfully saved on edit
* Updated branch in version file
* Dockerfile update to bring us up to php v7.1 for Laravel 5.5 (#7084)
* bump up to php7.1
& change deprecated MAINTAINER to a LABEL so it is visible with `docker inspect`
* AND modapache ><
* 2 updates required to get software-properties+ppa
* Bumped version
* Bumped release again :(
* Missed one
* Fixed #7098 - updated backup config for deleteFile() method
* Fixed #7092 - handle weird port forwarding/port numbers for baseUrl
* Bumped version
* Fixed #7099 - set email to null by default for backup notifications
* Removed old comments
* Fixed #7100 - Check if $user isset on checkin
* Increased throttle to 120 requests per minute
* Added Filipino, corrected order for Spanish variations
* Update language strings
* Bumped hash
* Changed has to filled to fix bulk asset editing
* Bumped point version
* Small fixes for phpleague CSB reader v9
* Improved error checking in locations importer
* Fixed #7145 - rename groups table to permissions_group for mysql 8 reserved word compatibility
* Reduce minimum group name length to 2 (from 3)
eg: IT
* Back in time fix FOR #7145 for new installs on MySQL 8+
* Fixed permission insert
//TODO
Handle this via model
* Possible fix for reporting/admin migration back in time
* Fixed #7164 - change table name to permission_groups
* Fixed LDAP password blanking on save
* fixing previous commit's actual wiping of password (#7183)
replaced Input::fille('ldap_pword') with _filled_. Should be good to go.
https://github.com/snipe/snipe-it/issues/7179
https://github.com/snipe/snipe-it/issues/7169
* Bumped version
* Downgrading rollbar for Laravel 5.5
* Spelling Correction (#7206)
Fixed Spelling for the word reqrite, to be rewrite.
* Fix #6910: Add logic to manipulate the eloquent query. (#7006)
* Added company_id to consumables_users table
* Added logic to manage when a pivot table doesn't have the column company_id trough a join with users
* Remove a migration that tries to fix this problem, but is not longer necessary
* Addresses #7238 - add PWA code to layout
Needs additional UX testing
* Better log message for bad LDAP connection
* Fixed #7186 - has vs filled in User’s API blanking out groups if no group_ids are passed
* Comment clarification on #7186
* Check for valid seat on hardware view
* Added space between footer and custom message
* Cap warranty months to three characters
Filles rollbar 209
* Cap warranty months to 3 on the frontend blade
* Fixed countable() strings on user destroy
* Check that the user has assets and that the aset model is valid
* Bumped hash
* Caps asset warranty to 20 years
* Command to fix custom field unicode conversion differences between PHP versions (#7263)
* Fixes #7252 form request changes (#7272)
* Fixes for #7252 - custom fields not validating / no validaton messages in API w/form requests
* Removed debug info
* More fixes for #7252
This is mostly working as intended, if not yet the way Laravel wants us to do it.
Right now, the API returns correctly, and the form UI will return highlighted errors, with the input filled in ~sometimes~. I’m not sure why it’s only sometimes yet, but this is potentially progress.
* Removed experimental method
* Check for digits_between:0,240 for warranty
* Removed debug code
* Apply fix from PR #7273 to master
* Bumped hash
* Fixed #7250 - permission issue for API fieldsets and fields endpoints
This applies the change from #7294 to master
* Add @mskrip as a contributor
* Fixed #7270 - Checking-in Assets via API Removes the Item's Asset Name
* CORS for api (#7292)
* Added CORS support to API
* Changed order so CORS will still work if throttle hit
* Added APP_CORS_ALLOWED_ORIGINS env option
* Fixed typo
* Clarified header comments
* More clarification
* DIsable CORS allowed origins by default to replicate existing behavior
* Change variable name to be clearer
* Bumped version
* Added condition to deal with fieldname 'rtd_location' which can be tried to be queried in some places and doesn't exist in database (#7317)
* Added comments to the ByFilter query scope for clarity
* Added accessories checkout/checkin API endpoint
* Fixed CVE-2019-10742
https://nvd.nist.gov/vuln/detail/CVE-2019-10742
* Update README.md (#7334)
Add reference to CSV importer.
* Group related variables in .env
* History importer fixes
* Fixes to history importer
2019-08-14 21:48:14 -07:00
* - snipe
2019-07-31 14:29:19 -07:00
*
*/
2019-07-31 13:54:55 -07:00
if (( $fieldname != 'category' ) && ( $fieldname != 'model_number' ) && ( $fieldname != 'rtd_location' ) && ( $fieldname != 'location' ) && ( $fieldname != 'supplier' )
2017-12-05 14:23:46 -08:00
&& ( $fieldname != 'status_label' ) && ( $fieldname != 'model' ) && ( $fieldname != 'company' ) && ( $fieldname != 'manufacturer' )) {
2017-11-06 10:26:09 -08:00
$query -> orWhere ( 'assets.' . $fieldname , 'LIKE' , '%' . $search_val . '%' );
2017-11-02 08:06:10 -07:00
}
2017-10-18 10:07:35 -07:00
2017-10-05 23:09:02 -07:00
2017-03-11 04:26:01 -08:00
});
2017-10-05 23:09:02 -07:00
2017-03-11 04:26:01 -08:00
}
2016-03-25 01:18:05 -07:00
/**
* Query builder scope to order on model
*
2017-02-03 19:34:24 -08:00
* @ param \Illuminate\Database\Query\Builder $query Query builder instance
2016-03-25 01:18:05 -07:00
* @ param text $order Order
*
2017-02-03 19:34:24 -08:00
* @ return \Illuminate\Database\Query\Builder Modified query builder
2016-03-25 01:18:05 -07:00
*/
public function scopeOrderModels ( $query , $order )
{
2017-11-16 14:14:30 -08:00
return $query -> join ( 'models as asset_models' , 'assets.model_id' , '=' , 'asset_models.id' ) -> orderBy ( 'asset_models.name' , $order );
2016-03-25 01:18:05 -07:00
}
2016-06-27 22:32:40 -07:00
/**
* Query builder scope to order on model number
*
2017-02-03 19:34:24 -08:00
* @ param \Illuminate\Database\Query\Builder $query Query builder instance
2016-06-27 22:32:40 -07:00
* @ param text $order Order
*
2017-02-03 19:34:24 -08:00
* @ return \Illuminate\Database\Query\Builder Modified query builder
2016-06-27 22:32:40 -07:00
*/
public function scopeOrderModelNumber ( $query , $order )
{
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
return $query -> join ( 'models' , 'assets.model_id' , '=' , 'models.id' ) -> orderBy ( 'models.model_number' , $order );
2016-06-27 22:32:40 -07:00
}
2016-03-25 01:18:05 -07:00
2016-11-11 19:46:25 -08:00
/**
* Query builder scope to order on assigned user
*
2017-02-03 19:34:24 -08:00
* @ param \Illuminate\Database\Query\Builder $query Query builder instance
2016-11-11 19:46:25 -08:00
* @ param text $order Order
*
2017-02-03 19:34:24 -08:00
* @ return \Illuminate\Database\Query\Builder Modified query builder
2016-11-11 19:46:25 -08:00
*/
2016-03-25 01:18:05 -07:00
public function scopeOrderAssigned ( $query , $order )
{
2017-11-02 13:47:37 -07:00
return $query -> leftJoin ( 'users as users_sort' , 'assets.assigned_to' , '=' , 'users_sort.id' ) -> select ( 'assets.*' ) -> orderBy ( 'users_sort.first_name' , $order ) -> orderBy ( 'users_sort.last_name' , $order );
2016-03-25 01:18:05 -07:00
}
/**
* Query builder scope to order on status
*
2017-02-03 19:34:24 -08:00
* @ param \Illuminate\Database\Query\Builder $query Query builder instance
2016-03-25 01:18:05 -07:00
* @ param text $order Order
*
2017-02-03 19:34:24 -08:00
* @ return \Illuminate\Database\Query\Builder Modified query builder
2016-03-25 01:18:05 -07:00
*/
public function scopeOrderStatus ( $query , $order )
{
2017-11-02 13:47:37 -07:00
return $query -> join ( 'status_labels as status_sort' , 'assets.status_id' , '=' , 'status_sort.id' ) -> orderBy ( 'status_sort.name' , $order );
2016-03-25 01:18:05 -07:00
}
2017-05-15 20:55:39 -07:00
/**
2016-03-25 01:18:05 -07:00
* Query builder scope to order on company
*
2017-02-03 19:34:24 -08:00
* @ param \Illuminate\Database\Query\Builder $query Query builder instance
2016-03-25 01:18:05 -07:00
* @ param text $order Order
*
2017-02-03 19:34:24 -08:00
* @ return \Illuminate\Database\Query\Builder Modified query builder
2016-03-25 01:18:05 -07:00
*/
public function scopeOrderCompany ( $query , $order )
{
2017-11-02 13:47:37 -07:00
return $query -> leftJoin ( 'companies as company_sort' , 'assets.company_id' , '=' , 'company_sort.id' ) -> orderBy ( 'company_sort.name' , $order );
2016-03-25 01:18:05 -07:00
}
2017-02-03 19:34:24 -08:00
/**
* Query builder scope to return results of a category
*
* @ param \Illuminate\Database\Query\Builder $query Query builder instance
* @ param text $order Order
*
* @ return \Illuminate\Database\Query\Builder Modified query builder
*/
public function scopeInCategory ( $query , $category_id )
{
2018-09-07 03:56:17 -07:00
return $query -> join ( 'models as category_models' , 'assets.model_id' , '=' , 'category_models.id' )
-> join ( 'categories' , 'category_models.category_id' , '=' , 'categories.id' ) -> where ( 'category_models.category_id' , '=' , $category_id );
2017-02-03 19:34:24 -08:00
}
2017-02-03 19:52:00 -08:00
/**
* Query builder scope to return results of a manufacturer
*
* @ param \Illuminate\Database\Query\Builder $query Query builder instance
* @ param text $order Order
*
* @ return \Illuminate\Database\Query\Builder Modified query builder
*/
public function scopeByManufacturer ( $query , $manufacturer_id )
{
return $query -> join ( 'models' , 'assets.model_id' , '=' , 'models.id' )
2017-03-14 08:37:39 -07:00
-> join ( 'manufacturers' , 'models.manufacturer_id' , '=' , 'manufacturers.id' ) -> where ( 'models.manufacturer_id' , '=' , $manufacturer_id );
2017-02-03 19:52:00 -08:00
}
2017-02-03 19:34:24 -08:00
/**
* Query builder scope to order on category
*
* @ param \Illuminate\Database\Query\Builder $query Query builder instance
* @ param text $order Order
*
* @ return \Illuminate\Database\Query\Builder Modified query builder
*/
2016-03-25 01:18:05 -07:00
public function scopeOrderCategory ( $query , $order )
{
2017-11-02 13:47:37 -07:00
return $query -> join ( 'models as order_model_category' , 'assets.model_id' , '=' , 'order_model_category.id' )
-> join ( 'categories as category_order' , 'order_model_category.category_id' , '=' , 'category_order.id' )
-> orderBy ( 'category_order.name' , $order );
2016-03-25 01:18:05 -07:00
}
2016-05-12 10:38:57 -07:00
/**
* Query builder scope to order on manufacturer
*
2017-02-03 19:34:24 -08:00
* @ param \Illuminate\Database\Query\Builder $query Query builder instance
2016-05-12 10:38:57 -07:00
* @ param text $order Order
*
2017-02-03 19:34:24 -08:00
* @ return \Illuminate\Database\Query\Builder Modified query builder
2016-05-12 10:38:57 -07:00
*/
public function scopeOrderManufacturer ( $query , $order )
{
return $query -> join ( 'models' , 'assets.model_id' , '=' , 'models.id' )
-> join ( 'manufacturers' , 'models.manufacturer_id' , '=' , 'manufacturers.id' )
-> orderBy ( 'manufacturers.name' , $order );
}
2017-02-08 03:31:42 -08:00
/**
2016-06-28 12:19:14 -07:00
* Query builder scope to order on location
2016-03-25 01:18:05 -07:00
*
2017-02-03 19:34:24 -08:00
* @ param \Illuminate\Database\Query\Builder $query Query builder instance
2016-03-25 01:18:05 -07:00
* @ param text $order Order
*
2017-02-03 19:34:24 -08:00
* @ return \Illuminate\Database\Query\Builder Modified query builder
2016-03-25 01:18:05 -07:00
*/
public function scopeOrderLocation ( $query , $order )
{
2017-11-16 16:49:48 -08:00
return $query -> leftJoin ( 'locations as asset_locations' , 'asset_locations.id' , '=' , 'assets.location_id' ) -> orderBy ( 'asset_locations.name' , $order );
2016-03-25 01:18:05 -07:00
}
2017-02-08 03:31:42 -08:00
2018-01-24 14:27:12 -08:00
/**
* Query builder scope to order on default
* @ param \Illuminate\Database\Query\Builder $query Query builder instance
* @ param text $order Order
*
* @ return \Illuminate\Database\Query\Builder Modified query builder
*/
public function scopeOrderRtdLocation ( $query , $order )
{
return $query -> leftJoin ( 'locations as rtd_asset_locations' , 'rtd_asset_locations.id' , '=' , 'assets.rtd_location_id' ) -> orderBy ( 'rtd_asset_locations.name' , $order );
}
2017-05-15 20:55:39 -07:00
/**
* Query builder scope to order on supplier name
*
* @ param \Illuminate\Database\Query\Builder $query Query builder instance
* @ param text $order Order
*
* @ return \Illuminate\Database\Query\Builder Modified query builder
*/
public function scopeOrderSupplier ( $query , $order )
{
2017-11-03 13:28:57 -07:00
return $query -> leftJoin ( 'suppliers as suppliers_assets' , 'assets.supplier_id' , '=' , 'suppliers_assets.id' ) -> orderBy ( 'suppliers_assets.name' , $order );
2017-05-15 20:55:39 -07:00
}
2017-02-08 03:31:42 -08:00
/**
* Query builder scope to search on location ID
*
* @ param \Illuminate\Database\Query\Builder $query Query builder instance
* @ param text $search Search term
*
* @ return \Illuminate\Database\Query\Builder Modified query builder
*/
public function scopeByLocationId ( $query , $search )
{
return $query -> where ( function ( $query ) use ( $search ) {
2017-11-16 16:49:48 -08:00
$query -> whereHas ( 'location' , function ( $query ) use ( $search ) {
2017-02-08 03:31:42 -08:00
$query -> where ( 'locations.id' , '=' , $search );
2017-08-25 06:30:10 -07:00
});
2017-02-08 03:31:42 -08:00
});
2017-11-03 20:10:05 -07:00
2017-02-08 03:31:42 -08:00
}
2017-05-15 20:55:39 -07:00
2017-10-17 11:20:05 -07:00
/**
* Query builder scope to search on location ID
*
* @ param \Illuminate\Database\Query\Builder $query Query builder instance
* @ param text $search Search term
*
* @ return \Illuminate\Database\Query\Builder Modified query builder
*/
public function scopeByDepreciationId ( $query , $search )
{
return $query -> join ( 'models' , 'assets.model_id' , '=' , 'models.id' )
-> join ( 'depreciations' , 'models.depreciation_id' , '=' , 'depreciations.id' ) -> where ( 'models.depreciation_id' , '=' , $search );
}
2016-03-25 01:18:05 -07:00
}