From 203b60383f133c21b8cef785dcc4f9b070e7c8d8 Mon Sep 17 00:00:00 2001 From: bryanlopezinc Date: Wed, 19 Jun 2024 17:21:49 +0100 Subject: [PATCH 1/2] Added storage path permissions test for SettingsController@getSetupIndex --- app/Http/Controllers/SettingsController.php | 26 ++++++++------- tests/Feature/Settings/ShowSetUpPageTest.php | 34 ++++++++++++++++++++ 2 files changed, 49 insertions(+), 11 deletions(-) diff --git a/app/Http/Controllers/SettingsController.php b/app/Http/Controllers/SettingsController.php index 26ab2b2a8..c0ffec8df 100755 --- a/app/Http/Controllers/SettingsController.php +++ b/app/Http/Controllers/SettingsController.php @@ -25,6 +25,7 @@ use Illuminate\Support\Facades\Artisan; use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Crypt; use Illuminate\Support\Facades\DB; +use Illuminate\Support\Facades\File; use Illuminate\Support\Facades\Http; use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\URL; @@ -106,17 +107,7 @@ class SettingsController extends Controller $start_settings['owner_is_admin'] = false; } - if ((is_writable(storage_path())) - && (is_writable(storage_path().'/framework')) - && (is_writable(storage_path().'/framework/cache')) - && (is_writable(storage_path().'/framework/sessions')) - && (is_writable(storage_path().'/framework/views')) - && (is_writable(storage_path().'/logs')) - ) { - $start_settings['writable'] = true; - } else { - $start_settings['writable'] = false; - } + $start_settings['writable'] = $this->storagePathIsWritable(); $start_settings['gd'] = extension_loaded('gd'); @@ -145,6 +136,19 @@ class SettingsController extends Controller } } + /** + * Determine if the app storage path is writable. + */ + protected function storagePathIsWritable(): bool + { + return File::isWritable(storage_path()) && + File::isWritable(storage_path('framework')) && + File::isWritable(storage_path('framework/cache')) && + File::isWritable(storage_path('framework/sessions')) && + File::isWritable(storage_path('framework/views')) && + File::isWritable(storage_path('logs')); + } + /** * Save the first admin user from Setup. * diff --git a/tests/Feature/Settings/ShowSetUpPageTest.php b/tests/Feature/Settings/ShowSetUpPageTest.php index 44c3d5a42..7f40768db 100644 --- a/tests/Feature/Settings/ShowSetUpPageTest.php +++ b/tests/Feature/Settings/ShowSetUpPageTest.php @@ -9,6 +9,7 @@ use Illuminate\Http\Client\Response; use Illuminate\Log\Events\MessageLogged; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Event; +use Illuminate\Support\Facades\File; use Illuminate\Support\Facades\Http; use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\URL; @@ -267,4 +268,37 @@ class ShowSetUpPageTest extends TestCase $this->assertSeeAppUrlMisconfigurationErrorMessage(); } + + public function testWillSeeDirectoryPermissionErrorWhenStoragePathIsNotWritable(): void + { + File::shouldReceive('isWritable')->andReturn(false); + + $this->getSetUpPageResponse()->assertOk(); + + $this->assertSeeDirectoryPermissionError(); + } + + protected function assertSeeDirectoryPermissionError(bool $shouldSee = true): void + { + $storagePath = storage_path(); + + $errorMessage = "Uh-oh. Your {$storagePath} directory (or sub-directories within) are not writable by the web-server. Those directories need to be writable by the web server in order for the app to work."; + $successMessage = 'Yippee! Your app storage directory seems writable'; + + if ($shouldSee) { + self::$latestResponse->assertSee($errorMessage, false)->assertDontSee($successMessage, false); + return; + } + + self::$latestResponse->assertSee($successMessage, false)->assertDontSee($errorMessage,false); + } + + public function testWillNotSeeDirectoryPermissionErrorWhenStoragePathIsWritable(): void + { + File::shouldReceive('isWritable')->andReturn(true); + + $this->getSetUpPageResponse()->assertOk(); + + $this->assertSeeDirectoryPermissionError(false); + } } From bd1f43f9ee85a34d94e1dacf7c0ee944d87c054e Mon Sep 17 00:00:00 2001 From: snipe Date: Thu, 20 Jun 2024 13:36:48 +0100 Subject: [PATCH 2/2] Added lastname.firstname as email format Signed-off-by: snipe --- app/Models/User.php | 5 +++-- resources/lang/en-US/general.php | 1 + resources/macros/macros.php | 1 + 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/app/Models/User.php b/app/Models/User.php index 438f432c5..22291cd9c 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -572,7 +572,6 @@ class User extends SnipeModel implements AuthenticatableContract, AuthorizableCo if ($format=='firstname.lastname') { $username = str_slug($first_name) . '.' . str_slug($last_name); - } elseif ($format == 'lastnamefirstinitial') { $username = str_slug($last_name.substr($first_name, 0, 1)); } elseif ($format == 'firstintial.lastname') { @@ -589,7 +588,9 @@ class User extends SnipeModel implements AuthenticatableContract, AuthorizableCo $username = str_slug($first_name).str_slug($last_name); } elseif ($format == 'firstnamelastinitial') { $username = str_slug(($first_name.substr($last_name, 0, 1))); - } + } elseif ($format == 'lastname.firstname') { + $username = str_slug($last_name).'.'.str_slug($first_name); + } } $user['first_name'] = $first_name; diff --git a/resources/lang/en-US/general.php b/resources/lang/en-US/general.php index ec0b8e6ee..7777302a6 100644 --- a/resources/lang/en-US/general.php +++ b/resources/lang/en-US/general.php @@ -134,6 +134,7 @@ return [ 'lastname_firstinitial' => 'Last Name First Initial (smith_j@example.com)', 'firstinitial.lastname' => 'First Initial Last Name (j.smith@example.com)', 'firstnamelastinitial' => 'First Name Last Initial (janes@example.com)', + 'lastnamefirstname' => 'Last Name First Name (smith.jane@example.com)', 'first_name' => 'First Name', 'first_name_format' => 'First Name (jane@example.com)', 'files' => 'Files', diff --git a/resources/macros/macros.php b/resources/macros/macros.php index 695fa86b0..584c7df84 100644 --- a/resources/macros/macros.php +++ b/resources/macros/macros.php @@ -190,6 +190,7 @@ Form::macro('username_format', function ($name = 'username_format', $selected = 'lastname_firstinitial' => trans('general.lastname_firstinitial'), 'firstnamelastname' => trans('general.firstnamelastname'), 'firstnamelastinitial' => trans('general.firstnamelastinitial'), + 'lastname.firstname' => trans('general.lastnamefirstname'), ]; $select = '