Merge remote-tracking branch 'origin/develop'

This commit is contained in:
snipe 2020-12-02 12:38:16 -08:00
commit 0e1f6a3fd1
9 changed files with 48 additions and 25 deletions

View file

@ -84,7 +84,7 @@ class LdapSync extends Command
}
/* Determine which location to assign users to by default. */
$location = NULL;
$location = NULL; // FIXME - this would be better called "$default_location", which is more explicit about its purpose
if ($this->option('location')!='') {
$location = Location::where('name', '=', $this->option('location'))->first();
@ -106,8 +106,8 @@ class LdapSync extends Command
$ldap_ou_locations = Location::where('ldap_ou', '!=', '')->get()->toArray();
$ldap_ou_lengths = array();
foreach ($ldap_ou_locations as $location) {
$ldap_ou_lengths[] = strlen($location["ldap_ou"]);
foreach ($ldap_ou_locations as $ou_loc) {
$ldap_ou_lengths[] = strlen($ou_loc["ldap_ou"]);
}
array_multisort($ldap_ou_lengths, SORT_ASC, $ldap_ou_locations);

View file

@ -60,6 +60,7 @@ class UsersController extends Controller
'users.updated_at',
'users.username',
'users.zip',
'users.ldap_import',
])->with('manager', 'groups', 'userloc', 'company', 'department','assets','licenses','accessories','consumables')
->withCount('assets as assets_count','licenses as licenses_count','accessories as accessories_count','consumables as consumables_count');
@ -131,7 +132,7 @@ class UsersController extends Controller
'assets','accessories', 'consumables','licenses','groups','activated','created_at',
'two_factor_enrolled','two_factor_optin','last_login', 'assets_count', 'licenses_count',
'consumables_count', 'accessories_count', 'phone', 'address', 'city', 'state',
'country', 'zip', 'id'
'country', 'zip', 'id', 'ldap_import'
];
$sort = in_array($request->get('sort'), $allowed_columns) ? $request->get('sort') : 'first_name';

View file

@ -27,7 +27,7 @@ class ImageUploadRequest extends Request
public function rules()
{
return [
'image' => 'mimes:png,gif,jpg,jpeg,svg,bmp,svg+xml',
'image' => 'mimes:png,gif,jpg,jpeg,svg,bmp,svg+xml,webp',
'avatar' => 'mimes:png,gif,jpg,jpeg,svg,bmp,svg+xml',
];
}
@ -91,8 +91,8 @@ class ImageUploadRequest extends Request
\Log::info('File name will be: '.$file_name);
\Log::debug('File extension is: '. $ext);
if ($image->getClientOriginalExtension()!=='svg') {
\Log::debug('Not an SVG - resize');
if (($image->getClientOriginalExtension()!=='webp') && ($image->getClientOriginalExtension()!=='svg')) {
\Log::debug('Not an SVG or webp - resize');
\Log::debug('Trying to upload to: '.$path.'/'.$file_name);
$upload = Image::make($image->getRealPath())->resize(null, $w, function ($constraint) {
$constraint->aspectRatio();
@ -102,20 +102,27 @@ class ImageUploadRequest extends Request
// This requires a string instead of an object, so we use ($string)
Storage::disk('public')->put($path.'/'.$file_name, (string)$upload->encode());
// If the file is an SVG, we need to clean it and NOT encode it
} else {
\Log::debug('This is an SVG');
$sanitizer = new Sanitizer();
$dirtySVG = file_get_contents($image->getRealPath());
$cleanSVG = $sanitizer->sanitize($dirtySVG);
// If the file is a webp, we need to just move it since webp support
// needs to be compiled into gd for resizing to be available
if ($image->getClientOriginalExtension()=='webp') {
\Log::debug('This is a webp, just move it');
Storage::disk('public')->put($path.'/'.$file_name, file_get_contents($image));
// If the file is an SVG, we need to clean it and NOT encode it
} else {
try {
\Log::debug('Trying to upload to: '.$path.'/'.$file_name);
Storage::disk('public')->put($path.'/'.$file_name, $cleanSVG);
} catch (\Exception $e) {
\Log::debug('Upload no workie :( ');
\Log::debug($e);
\Log::debug('This is an SVG');
$sanitizer = new Sanitizer();
$dirtySVG = file_get_contents($image->getRealPath());
$cleanSVG = $sanitizer->sanitize($dirtySVG);
try {
\Log::debug('Trying to upload to: '.$path.'/'.$file_name);
Storage::disk('public')->put($path.'/'.$file_name, $cleanSVG);
} catch (\Exception $e) {
\Log::debug('Upload no workie :( ');
\Log::debug($e);
}
}
}

View file

@ -52,6 +52,7 @@ class UsersTransformer
'notes'=> e($user->notes),
'permissions' => $user->decodePermissions(),
'activated' => ($user->activated =='1') ? true : false,
'ldap_import' => ($user->ldap_import =='1') ? true : false,
'two_factor_activated' => ($user->two_factor_active()) ? true : false,
'two_factor_enrolled' => ($user->two_factor_active_and_enrolled()) ? true : false,
'assets_count' => (int) $user->assets_count,

View file

@ -225,6 +225,15 @@ class UserPresenter extends Presenter
"visible" => true,
'formatter' => 'groupsFormatter'
],
[
"field" => "ldap_import",
"searchable" => false,
"sortable" => true,
"switchable" => true,
"title" => trans('admin/settings/general.ldap_enabled'),
"visible" => false,
'formatter' => 'trueFalseFormatter'
],
[
"field" => "two_factor_enrolled",
"searchable" => false,

View file

@ -235,15 +235,20 @@ class LdapAd extends LdapAdConfiguration
$user->employee_num = trim($userInfo['employee_number']);
$user->jobtitle = trim($userInfo['title']);
$user->phone = trim($userInfo['telephonenumber']);
if(array_key_exists('activated',$userInfo)) {
if (array_key_exists('activated',$userInfo)) {
$user->activated = $userInfo['activated'];
} else if ( !$user->exists ) { // no 'activated' flag was set or unset, *AND* this user is new - activate by default.
$user->activated = 1;
}
if(array_key_exists('location_id',$userInfo)) {
if (array_key_exists('location_id',$userInfo)) {
$user->location_id = $userInfo['location_id'];
}
$user->notes = 'Imported from LDAP';
// this is a new user
if (!isset($user->id)) {
$user->notes = 'Imported from LDAP';
}
$user->ldap_import = 1;
return $user;

View file

@ -17,7 +17,7 @@ class CreateCheckoutAcceptancesTable extends Migration
$table->increments('id');
$table->morphs('checkoutable');
$table->integer('assigned_to_id')->unsigned();
$table->integer('assigned_to_id')->nullable();
$table->string('signature_filename')->nullable();

View file

@ -112,7 +112,7 @@
'image' => 'Image',
'image_delete' => 'Delete Image',
'image_upload' => 'Upload Image',
'image_filetypes_help' => 'Accepted filetypes are jpg, png, gif, and svg. Max upload size allowed is :size.',
'image_filetypes_help' => 'Accepted filetypes are jpg, webp, png, gif, and svg. Max upload size allowed is :size.',
'import' => 'Import',
'importing' => 'Importing',
'importing_help' => 'You can import assets, accessories, licenses, components, consumables, and users via CSV file. <br><br>The CSV should be comma-delimited and formatted with headers that match the ones in the <a href="https://snipe-it.readme.io/docs/importing" target="_new">sample CSVs in the documentation</a>.',

View file

@ -6,7 +6,7 @@
<label class="btn btn-default" aria-hidden="true">
{{ trans('button.select_file') }}
<input type="file" name="{{ (isset($fieldname) ? $fieldname : 'image') }}" class="js-uploadFile" id="uploadFile" data-maxsize="{{ \App\Helpers\Helper::file_upload_max_size() }}" accept="image/gif,image/jpeg,image/png,image/svg" style="display:none; max-width: 90%" aria-label="image" aria-hidden="true">
<input type="file" name="{{ (isset($fieldname) ? $fieldname : 'image') }}" class="js-uploadFile" id="uploadFile" data-maxsize="{{ \App\Helpers\Helper::file_upload_max_size() }}" accept="image/gif,image/jpeg,image/webp,image/png,image/svg" style="display:none; max-width: 90%" aria-label="image" aria-hidden="true">
</label>
<span class='label label-default' id="uploadFile-info"></span>