Merge branch 'develop' of https://github.com/snipe/snipe-it into develop

# Conflicts:
#	app/Models/Asset.php
This commit is contained in:
snipe 2019-07-31 14:26:46 -07:00
commit f721dac2ca
7 changed files with 42 additions and 68 deletions

View file

@ -25,12 +25,12 @@ class LdapSync extends Command
* *
* @var string * @var string
*/ */
protected $signature = 'snipeit:ldap-sync protected $signature = 'snipeit:ldap-sync
{--location= : A location name } {--location= : A location name }
{--location_id= : A location id} {--location_id= : A location id}
{--base_dn= : A diffrent base DN to use } {--base_dn= : A diffrent base DN to use }
{--summary : Print summary } {--summary : Print summary }
{--json_summary : Print summary in json format } {--json_summary : Print summary in json format }
{--dryrun : Run the sync process but don\'t update the database}'; {--dryrun : Run the sync process but don\'t update the database}';
/** /**
@ -142,7 +142,7 @@ class LdapSync extends Command
* @return string * @return string
*/ */
private function getSummary(): string private function getSummary(): string
{ {
if ($this->option('summary') && !$this->dryrun) { if ($this->option('summary') && !$this->dryrun) {
$this->summary->each(function ($item) { $this->summary->each(function ($item) {
if ('ERROR' === $item['status']) { if ('ERROR' === $item['status']) {
@ -218,33 +218,29 @@ class LdapSync extends Command
* *
* @param int $page The page to get the result set * @param int $page The page to get the result set
*/ */
private function processLdapUsers(int $page=0): void private function processLdapUsers(): void
{ {
try { try {
$ldapUsers = $this->ldap->getLdapUsers($page); $ldapUsers = $this->ldap->getLdapUsers();
} catch (Exception $e) { } catch (Exception $e) {
$this->outputError($e); $this->outputError($e);
exit($e->getMessage()); exit($e->getMessage());
} }
if (0 == $ldapUsers->count()) { if (0 == count($ldapUsers)) {
$msg = 'ERROR: No users found!'; $msg = 'ERROR: No users found!';
Log::error($msg); Log::error($msg);
if ($this->dryrun) { if ($this->dryrun) {
$this->error($msg); $this->error($msg);
} }
exit($msg); exit($msg);
} }
// Process each individual users // Process each individual users
foreach ($ldapUsers as $user) { foreach ($ldapUsers as $user) {
$this->updateCreateUser($user); $this->updateCreateUser($user);
} }
}
if ($ldapUsers->getCurrentPage() < $ldapUsers->getPages()) {
$this->processLdapUsers($ldapUsers->getCurrentPage() + 1);
}
}
/** /**
* Get the mapped locations if a base_dn is provided. * Get the mapped locations if a base_dn is provided.

View file

@ -8,6 +8,7 @@ use App\Http\Transformers\CompaniesTransformer;
use App\Http\Transformers\SelectlistTransformer; use App\Http\Transformers\SelectlistTransformer;
use App\Models\Company; use App\Models\Company;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Illuminate\Support\Facades\Storage;
class CompaniesController extends Controller class CompaniesController extends Controller
{ {

View file

@ -23,7 +23,7 @@ class CustomFieldsController extends Controller
public function index() public function index()
{ {
$this->authorize('index', CustomFields::class); $this->authorize('index', CustomField::class);
$fields = CustomField::get(); $fields = CustomField::get();
return (new CustomFieldsTransformer)->transformCustomFields($fields, $fields->count()); return (new CustomFieldsTransformer)->transformCustomFields($fields, $fields->count());
} }
@ -37,7 +37,7 @@ class CustomFieldsController extends Controller
*/ */
public function show($id) public function show($id)
{ {
$this->authorize('show', CustomField::class); $this->authorize('view', CustomField::class);
if ($field = CustomField::find($id)) { if ($field = CustomField::find($id)) {
return (new CustomFieldsTransformer)->transformCustomField($field); return (new CustomFieldsTransformer)->transformCustomField($field);
} }
@ -58,9 +58,9 @@ class CustomFieldsController extends Controller
{ {
$this->authorize('update', CustomField::class); $this->authorize('update', CustomField::class);
$field = CustomField::findOrFail($id); $field = CustomField::findOrFail($id);
/** /**
* Updated values for the field, * Updated values for the field,
* without the "field_encrypted" flag, preventing the change of encryption status * without the "field_encrypted" flag, preventing the change of encryption status
* @var array * @var array
*/ */

View file

@ -50,7 +50,7 @@ class CustomFieldsetsController extends Controller
*/ */
public function show($id) public function show($id)
{ {
$this->authorize('show', CustomFieldset::class); $this->authorize('view', CustomFieldset::class);
if ($fieldset = CustomFieldset::find($id)) { if ($fieldset = CustomFieldset::find($id)) {
return (new CustomFieldsetsTransformer)->transformCustomFieldset($fieldset); return (new CustomFieldsetsTransformer)->transformCustomFieldset($fieldset);
} }

View file

@ -1068,8 +1068,10 @@ class Asset extends Depreciable
public function scopeDueOrOverdueForAudit($query, $settings) public function scopeDueOrOverdueForAudit($query, $settings)
{ {
$interval = $settings->audit_warning_days ?? 0;
return $query->whereNotNull('assets.next_audit_date') return $query->whereNotNull('assets.next_audit_date')
->whereRaw("DATE_SUB(assets.next_audit_date, INTERVAL $settings->audit_warning_days DAY) <= '".Carbon::now()."'") ->whereRaw("DATE_SUB(assets.next_audit_date, INTERVAL $interval DAY) <= '".Carbon::now()."'")
->where('assets.archived', '=', 0) ->where('assets.archived', '=', 0)
->NotArchived(); ->NotArchived();
} }
@ -1376,30 +1378,7 @@ class Asset extends Depreciable
} }
} }
/** if (($fieldname!='category') && ($fieldname!='model_number') && ($fieldname!='rtd_location') && ($fieldname!='location') && ($fieldname!='supplier')
* 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
* allows us to query custom fields directly in the assetsv table
* (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.
*
* - snipe
*
*/
if (($fieldname!='category') && ($fieldname!='model_number') && ($fieldname!='location') && ($fieldname!='supplier')
&& ($fieldname!='status_label') && ($fieldname!='model') && ($fieldname!='company') && ($fieldname!='manufacturer')) { && ($fieldname!='status_label') && ($fieldname!='model') && ($fieldname!='company') && ($fieldname!='manufacturer')) {
$query->orWhere('assets.'.$fieldname, 'LIKE', '%' . $search_val . '%'); $query->orWhere('assets.'.$fieldname, 'LIKE', '%' . $search_val . '%');
} }

View file

@ -430,11 +430,9 @@ class LdapAd extends LdapAdConfiguration
* *
* @since 5.0.0 * @since 5.0.0
* *
* @param int $page The paged results to get
*
* @return \Adldap\Query\Paginator * @return \Adldap\Query\Paginator
*/ */
public function getLdapUsers(int $page=0): Paginator public function getLdapUsers(): Paginator
{ {
$search = $this->ldap->search()->users()->in($this->getBaseDn()); $search = $this->ldap->search()->users()->in($this->getBaseDn());
@ -444,6 +442,6 @@ class LdapAd extends LdapAdConfiguration
} }
return $search->select($this->getSelectedFields()) return $search->select($this->getSelectedFields())
->paginate(self::PAGE_SIZE, $page); ->paginate(self::PAGE_SIZE);
} }
} }

View file

@ -31,12 +31,12 @@ Route::group(
Route::get('audit/due', [ Route::get('audit/due', [
'as' => 'assets.audit.due', 'as' => 'assets.audit.due',
'uses' => 'AssetsController@dueForAudit' 'uses' => 'Assets\AssetsController@dueForAudit'
]); ]);
Route::get('audit/overdue', [ Route::get('audit/overdue', [
'as' => 'assets.audit.overdue', 'as' => 'assets.audit.overdue',
'uses' => 'AssetsController@overdueForAudit' 'uses' => 'Assets\AssetsController@overdueForAudit'
]); ]);
Route::get('audit/{id}', [ Route::get('audit/{id}', [