diff --git a/app/Http/Controllers/SettingsController.php b/app/Http/Controllers/SettingsController.php index a3c3cab8f77b..7fefbf909022 100755 --- a/app/Http/Controllers/SettingsController.php +++ b/app/Http/Controllers/SettingsController.php @@ -348,7 +348,6 @@ public function postSettings(Request $request) } $setting->default_eula_text = $request->input('default_eula_text'); - $setting->load_remote = $request->input('load_remote', 0); $setting->thumbnail_max_h = $request->input('thumbnail_max_h'); $setting->privacy_policy_link = $request->input('privacy_policy_link'); $setting->depreciation_method = $request->input('depreciation_method'); @@ -393,10 +392,11 @@ public function getBranding() * * @since [v1.0] * - * @return View + * @return \Illuminate\Contracts\View\View | \Illuminate\Http\RedirectResponse */ public function postBranding(ImageUploadRequest $request) { + // Something has gone horribly wrong - no settings record exists! if (is_null($setting = Setting::getSettings())) { return redirect()->to('admin')->with('error', trans('admin/settings/message.update.error')); } @@ -407,51 +407,75 @@ public function postBranding(ImageUploadRequest $request) $setting->version_footer = $request->input('version_footer'); $setting->footer_text = $request->input('footer_text'); $setting->skin = $request->input('skin'); - $setting->allow_user_skin = $request->input('allow_user_skin'); + $setting->allow_user_skin = $request->input('allow_user_skin', '0'); $setting->show_url_in_emails = $request->input('show_url_in_emails', '0'); $setting->logo_print_assets = $request->input('logo_print_assets', '0'); + $setting->load_remote = $request->input('load_remote', 0); - // Only allow the site name and CSS to be changed if lock_passwords is false + // Only allow the site name, images, and CSS to be changed if lock_passwords is false // Because public demos make people act like dicks - if (! config('app.lock_passwords')) { - $request->validate(['site_name' => 'required']); - $setting->site_name = $request->input('site_name'); + if (!config('app.lock_passwords')) { + + if ($request->has('site_name')) { + $request->validate(['site_name' => 'required']); + } + + $setting->site_name = $request->input('site_name', 'Snipe-IT'); $setting->custom_css = $request->input('custom_css'); + + // Logo upload $setting = $request->handleImages($setting, 600, 'logo', '', 'logo'); - if ('1' == $request->input('clear_logo')) { - Storage::disk('public')->delete($setting->logo); + if ($request->input('clear_logo') == '1') { + + if (($setting->logo) && (Storage::exists($setting->logo))) { + Storage::disk('public')->delete($setting->logo); + } $setting->logo = null; $setting->brand = 1; } - + // Email logo upload $setting = $request->handleImages($setting, 600, 'email_logo', '', 'email_logo'); + if ($request->input('clear_email_logo') == '1') { - - if ('1' == $request->input('clear_email_logo')) { - Storage::disk('public')->delete($setting->email_logo); + if (($setting->email_logo) && (Storage::exists($setting->email_logo))) { + Storage::disk('public')->delete($setting->email_logo); + } $setting->email_logo = null; // If they are uploading an image, validate it and upload it } - + // Label logo upload $setting = $request->handleImages($setting, 600, 'label_logo', '', 'label_logo'); + if ($request->input('clear_label_logo') == '1') { - if ('1' == $request->input('clear_label_logo')) { - Storage::disk('public')->delete($setting->label_logo); + if (($setting->label_logo) && (Storage::exists($setting->label_logo))) { + Storage::disk('public')->delete($setting->label_logo); + } $setting->label_logo = null; } - - $setting = $request->handleImages($setting, 600, 'favicon', '', 'favicon'); - - // If the user wants to clear the favicon... + // Favicon upload + $setting = $request->handleImages($setting, 100, 'favicon', '', 'favicon'); if ('1' == $request->input('clear_favicon')) { - Storage::disk('public')->delete($setting->favicon); + + if (($setting->favicon) && (Storage::exists($setting->favicon))) { + Storage::disk('public')->delete($setting->favicon); + } $setting->favicon = null; } + + // Default avatar upload + $setting = $request->handleImages($setting, 500, 'default_avatar', 'avatars', 'default_avatar'); + if ($request->input('clear_default_avatar') == '1') { + + if (($setting->default_avatar) && (Storage::exists('avatars/'.$setting->default_avatar))) { + Storage::disk('public')->delete('avatars/'.$setting->default_avatar); + } + $setting->default_avatar = null; + } } if ($setting->save()) { diff --git a/app/Http/Requests/ImageUploadRequest.php b/app/Http/Requests/ImageUploadRequest.php index c75454d0f334..8b9aed499bf3 100644 --- a/app/Http/Requests/ImageUploadRequest.php +++ b/app/Http/Requests/ImageUploadRequest.php @@ -96,10 +96,7 @@ public function handleImages($item, $w = 600, $form_fieldname = 'image', $path = $ext = $image->guessExtension(); $file_name = $type.'-'.$form_fieldname.'-'.$item->id.'-'.str_random(10).'.'.$ext; - - Log::info('File name will be: '.$file_name); - Log::debug('File extension is: '.$ext); - + if (($image->getMimeType() == 'image/vnd.microsoft.icon') || ($image->getMimeType() == 'image/x-icon') || ($image->getMimeType() == 'image/avif') || ($image->getMimeType() == 'image/webp')) { // If the file is an icon, webp or avif, we need to just move it since gd doesn't support resizing // icons or avif, and webp support and needs to be compiled into gd for resizing to be available diff --git a/app/Http/Transformers/UsersTransformer.php b/app/Http/Transformers/UsersTransformer.php index 64752d0445a7..0b573b83889b 100644 --- a/app/Http/Transformers/UsersTransformer.php +++ b/app/Http/Transformers/UsersTransformer.php @@ -24,7 +24,7 @@ public function transformUser(User $user) $array = [ 'id' => (int) $user->id, - 'avatar' => e($user->present()->gravatar), + 'avatar' => e($user->present()->gravatar) ?? null, 'name' => e($user->getFullNameAttribute()), 'first_name' => e($user->first_name), 'last_name' => e($user->last_name), diff --git a/app/Presenters/UserPresenter.php b/app/Presenters/UserPresenter.php index d0f5c13fecb6..7c6d46573ecf 100644 --- a/app/Presenters/UserPresenter.php +++ b/app/Presenters/UserPresenter.php @@ -432,6 +432,8 @@ public function name() */ public function gravatar() { + + // User's specific avatar if ($this->avatar) { // Check if it's a google avatar or some external avatar @@ -443,6 +445,12 @@ public function gravatar() return Storage::disk('public')->url('avatars/'.e($this->avatar)); } + // If there is a default avatar + if (Setting::getSettings()->default_avatar!= '') { + return Storage::disk('public')->url('avatars/'.e(Setting::getSettings()->default_avatar)); + } + + // Fall back to Gravatar if the settings allow loading remote scripts if (Setting::getSettings()->load_remote == '1') { if ($this->model->gravatar != '') { @@ -456,8 +464,8 @@ public function gravatar() } } - // Set a fun, gender-neutral default icon - return config('app.url').'/img/default-sm.png'; + + return false; } /** diff --git a/database/migrations/2024_07_04_103729_add_default_avatar_to_settings.php b/database/migrations/2024_07_04_103729_add_default_avatar_to_settings.php new file mode 100644 index 000000000000..423f45e9eebb --- /dev/null +++ b/database/migrations/2024_07_04_103729_add_default_avatar_to_settings.php @@ -0,0 +1,28 @@ +string('default_avatar')->after('favicon')->default('default.png')->nullable(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('settings', function (Blueprint $table) { + $table->dropColumn('default_avatar'); + }); + } +}; diff --git a/resources/lang/en-US/admin/settings/general.php b/resources/lang/en-US/admin/settings/general.php index 8074f5082ec6..dca13b98552b 100644 --- a/resources/lang/en-US/admin/settings/general.php +++ b/resources/lang/en-US/admin/settings/general.php @@ -122,8 +122,8 @@ 'ldap_test' => 'Test LDAP', 'ldap_test_sync' => 'Test LDAP Synchronization', 'license' => 'Software License', - 'load_remote' => 'Use Gravatar', - 'load_remote_help_text' => 'Uncheck this box if your install cannot load scripts from the outside internet. This will prevent Snipe-IT from trying load images from Gravatar.', + 'load_remote' => 'Load Remote Avatars', + 'load_remote_help_text' => 'Uncheck this box if your install cannot load scripts from the outside internet. This will prevent Snipe-IT from trying load avatars from Gravatar or other outside sources.', 'login' => 'Login Attempts', 'login_attempt' => 'Login Attempt', 'login_ip' => 'IP Address', @@ -375,5 +375,6 @@ 'timezone' => 'Timezone', 'profile_edit' => 'Edit Profile', 'profile_edit_help' => 'Allow users to edit their own profiles.', + 'default_avatar' => 'Upload default avatar', ]; diff --git a/resources/views/layouts/default.blade.php b/resources/views/layouts/default.blade.php index 5b23db7b8032..74e9d5be6fc5 100644 --- a/resources/views/layouts/default.blade.php +++ b/resources/views/layouts/default.blade.php @@ -324,7 +324,7 @@ @else - + @endif