From 2aa50859b325ea0d31a0ab1e64da1acd34b1c937 Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Tue, 10 Jan 2023 17:01:03 -0800 Subject: [PATCH 001/127] Bump Dusk version to fix broken macOS chrome driver link --- composer.json | 2 +- composer.lock | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/composer.json b/composer.json index 07dbf20639..06d8563039 100644 --- a/composer.json +++ b/composer.json @@ -73,7 +73,7 @@ }, "require-dev": { "fakerphp/faker": "^1.16", - "laravel/dusk": "^6.19", + "laravel/dusk": "^6.25", "mockery/mockery": "^1.4", "phpunit/php-token-stream": "^3.1", "phpunit/phpunit": "^9.0", diff --git a/composer.lock b/composer.lock index bf8cb1f758..7c8b7030ba 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "0c1f3848f8c9ede2b5f1513e4feaa7d7", + "content-hash": "4fed0ab76a34ef85a44568e470abab48", "packages": [ { "name": "alek13/slack", @@ -11847,16 +11847,16 @@ }, { "name": "laravel/dusk", - "version": "v6.25.0", + "version": "v6.25.2", "source": { "type": "git", "url": "https://github.com/laravel/dusk.git", - "reference": "b4632b7493a187d31afc5c9ddec437c81b16421a" + "reference": "25a595ac3dc82089a91af10dd23b0d58fd3f6d0b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/laravel/dusk/zipball/b4632b7493a187d31afc5c9ddec437c81b16421a", - "reference": "b4632b7493a187d31afc5c9ddec437c81b16421a", + "url": "https://api.github.com/repos/laravel/dusk/zipball/25a595ac3dc82089a91af10dd23b0d58fd3f6d0b", + "reference": "25a595ac3dc82089a91af10dd23b0d58fd3f6d0b", "shasum": "" }, "require": { @@ -11914,9 +11914,9 @@ ], "support": { "issues": "https://github.com/laravel/dusk/issues", - "source": "https://github.com/laravel/dusk/tree/v6.25.0" + "source": "https://github.com/laravel/dusk/tree/v6.25.2" }, - "time": "2022-07-11T11:38:43+00:00" + "time": "2022-09-29T09:37:07+00:00" }, { "name": "mockery/mockery", From 581655f7562199c61267e15e8ba05f1b3fd32b52 Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Tue, 10 Jan 2023 17:02:11 -0800 Subject: [PATCH 002/127] Run database migrations for all Dusk tests --- tests/DuskTestCase.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/DuskTestCase.php b/tests/DuskTestCase.php index ac750d9efc..e591a7c771 100644 --- a/tests/DuskTestCase.php +++ b/tests/DuskTestCase.php @@ -5,11 +5,13 @@ namespace Tests; use Facebook\WebDriver\Chrome\ChromeOptions; use Facebook\WebDriver\Remote\DesiredCapabilities; use Facebook\WebDriver\Remote\RemoteWebDriver; +use Illuminate\Foundation\Testing\DatabaseMigrations; use Laravel\Dusk\TestCase as BaseTestCase; abstract class DuskTestCase extends BaseTestCase { use CreatesApplication; + use DatabaseMigrations; /** * Prepare for Dusk test execution. From bc0f666906d81eaedc0d9273ed54fb1cc8a6e496 Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Tue, 10 Jan 2023 17:03:09 -0800 Subject: [PATCH 003/127] Create Setting in test to avoid being redirected to the setup screen --- tests/Browser/LoginTest.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/Browser/LoginTest.php b/tests/Browser/LoginTest.php index 5ed055cda9..18f5172f15 100644 --- a/tests/Browser/LoginTest.php +++ b/tests/Browser/LoginTest.php @@ -2,8 +2,8 @@ namespace Tests\Browser; +use App\Models\Setting; use App\Models\User; -use Illuminate\Foundation\Testing\DatabaseMigrations; use Laravel\Dusk\Browser; use Tests\DuskTestCase; @@ -26,6 +26,9 @@ class LoginTest extends DuskTestCase $user->permissions = '{"superuser": 1}'; $user->save(); + + Setting::factory()->create(); + $this->browse(function (Browser $browser) { $browser->visitRoute('login') ->assertSee(trans('auth/general.login_prompt')); @@ -37,10 +40,7 @@ class LoginTest extends DuskTestCase ->type('password', 'password') ->press(trans('auth/general.login')) ->assertPathIs('/'); - $browser->screenshot('dashboard'); + $browser->screenshot('dashboard'); }); - - // Delete the user afterwards - $user->delete(); } } From b8b2543b0dca61c29e90eac45a44d6852b6d4491 Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Tue, 10 Jan 2023 17:04:21 -0800 Subject: [PATCH 004/127] Reference the correct table in migration down method --- .../migrations/2017_03_10_210807_add_fields_to_manufacturer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/database/migrations/2017_03_10_210807_add_fields_to_manufacturer.php b/database/migrations/2017_03_10_210807_add_fields_to_manufacturer.php index 0d05a680c1..05af7c8316 100644 --- a/database/migrations/2017_03_10_210807_add_fields_to_manufacturer.php +++ b/database/migrations/2017_03_10_210807_add_fields_to_manufacturer.php @@ -28,7 +28,7 @@ class AddFieldsToManufacturer extends Migration */ public function down() { - Schema::table('settings', function ($table) { + Schema::table('manufacturers', function ($table) { $table->dropColumn('url'); $table->dropColumn('support_url'); $table->dropColumn('support_phone'); From e5cb68cc5ebc73fda5266b783440117550f72f6c Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Tue, 10 Jan 2023 17:06:16 -0800 Subject: [PATCH 005/127] Move drop column command to correct migration --- .../2016_08_23_145619_add_show_in_nav_to_status_labels.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/database/migrations/2016_08_23_145619_add_show_in_nav_to_status_labels.php b/database/migrations/2016_08_23_145619_add_show_in_nav_to_status_labels.php index c4e1a18177..5ea26bf4c1 100644 --- a/database/migrations/2016_08_23_145619_add_show_in_nav_to_status_labels.php +++ b/database/migrations/2016_08_23_145619_add_show_in_nav_to_status_labels.php @@ -25,7 +25,7 @@ class AddShowInNavToStatusLabels extends Migration public function down() { Schema::table('status_labels', function (Blueprint $table) { - $table->dropColumn('show_in_nav', 'field_encrypted'); + $table->dropColumn('show_in_nav'); }); } } From 39ab545cf5b08d3a79d6d4a84d96874db11519ba Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Tue, 10 Jan 2023 17:08:28 -0800 Subject: [PATCH 006/127] Update alter statement to use correct suffix for column This is brittle... --- database/migrations/2015_09_22_003413_migrate_mac_address.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/database/migrations/2015_09_22_003413_migrate_mac_address.php b/database/migrations/2015_09_22_003413_migrate_mac_address.php index 516b5c2ec7..8167e28adf 100644 --- a/database/migrations/2015_09_22_003413_migrate_mac_address.php +++ b/database/migrations/2015_09_22_003413_migrate_mac_address.php @@ -55,6 +55,6 @@ class MigrateMacAddress extends Migration Schema::table('models', function (Blueprint $table) { $table->renameColumn('deprecated_mac_address', 'show_mac_address'); }); - DB::statement('ALTER TABLE assets CHANGE _snipeit_mac_address mac_address varchar(255)'); + DB::statement('ALTER TABLE assets CHANGE _snipeit_mac_address_1 mac_address varchar(255)'); } } From 4ee3cbf60e5b6f17ecae9e6fc2025795f26008bd Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Tue, 10 Jan 2023 17:20:20 -0800 Subject: [PATCH 007/127] Comment out migration's down method to match its up method --- ...015_07_29_230054_add_thread_id_to_asset_logs_table.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/database/migrations/2015_07_29_230054_add_thread_id_to_asset_logs_table.php b/database/migrations/2015_07_29_230054_add_thread_id_to_asset_logs_table.php index eefc283e3f..f14dc078cc 100644 --- a/database/migrations/2015_07_29_230054_add_thread_id_to_asset_logs_table.php +++ b/database/migrations/2015_07_29_230054_add_thread_id_to_asset_logs_table.php @@ -105,10 +105,10 @@ */ public function down() { - Schema::table('asset_logs', function (Blueprint $table) { - $table->dropIndex('thread_id'); - $table->dropColumn('thread_id'); - }); + // Schema::table('asset_logs', function (Blueprint $table) { + // $table->dropIndex('thread_id'); + // $table->dropColumn('thread_id'); + // }); } /** From c5b09ed95584b01e649c670f9d8b8e2a8778e041 Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Tue, 10 Jan 2023 17:21:46 -0800 Subject: [PATCH 008/127] Fix column name typo --- .../migrations/2013_12_10_084038_add_eol_on_models_table.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/database/migrations/2013_12_10_084038_add_eol_on_models_table.php b/database/migrations/2013_12_10_084038_add_eol_on_models_table.php index d8d222deec..97e7b266e6 100755 --- a/database/migrations/2013_12_10_084038_add_eol_on_models_table.php +++ b/database/migrations/2013_12_10_084038_add_eol_on_models_table.php @@ -24,7 +24,7 @@ class AddEolOnModelsTable extends Migration public function down() { Schema::table('models', function ($table) { - $table->dropColumn('old'); + $table->dropColumn('eol'); }); } } From 296c9a723d25ec46190273ec39426d489cbe25c3 Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Tue, 10 Jan 2023 17:22:29 -0800 Subject: [PATCH 009/127] Reverse column rename in migration's down method --- .../2013_11_25_104343_alter_warranty_column_on_assets.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/database/migrations/2013_11_25_104343_alter_warranty_column_on_assets.php b/database/migrations/2013_11_25_104343_alter_warranty_column_on_assets.php index be62374dce..d63a6ad9b4 100755 --- a/database/migrations/2013_11_25_104343_alter_warranty_column_on_assets.php +++ b/database/migrations/2013_11_25_104343_alter_warranty_column_on_assets.php @@ -23,6 +23,8 @@ class AlterWarrantyColumnOnAssets extends Migration */ public function down() { - // + Schema::table('assets', function ($table) { + $table->renameColumn('warranty_months', 'warrantee_months'); + }); } } From 03938d0f32fd6f1b6891d5aa75e83edc7f8eccc1 Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Tue, 10 Jan 2023 17:24:38 -0800 Subject: [PATCH 010/127] Conditionally drop table --- .../migrations/2013_11_25_013244_recreate_licenses_table.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/database/migrations/2013_11_25_013244_recreate_licenses_table.php b/database/migrations/2013_11_25_013244_recreate_licenses_table.php index fb18452794..a22349dcd6 100755 --- a/database/migrations/2013_11_25_013244_recreate_licenses_table.php +++ b/database/migrations/2013_11_25_013244_recreate_licenses_table.php @@ -37,7 +37,7 @@ class ReCreateLicensesTable extends Migration */ public function down() { - // - Schema::drop('licenses'); + // This was most likely handled in 2013_11_17_054359_drop_licenses_table.php + Schema::dropIfExists('licenses'); } } From aec64fa64ac2a7b59e953972af55c349de7864d7 Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Tue, 10 Jan 2023 17:25:25 -0800 Subject: [PATCH 011/127] Comment out migration's down method to match its up method --- .../migrations/2013_11_17_054526_add_physical_to_assets.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/database/migrations/2013_11_17_054526_add_physical_to_assets.php b/database/migrations/2013_11_17_054526_add_physical_to_assets.php index 2ccc7c43dc..28d1117201 100755 --- a/database/migrations/2013_11_17_054526_add_physical_to_assets.php +++ b/database/migrations/2013_11_17_054526_add_physical_to_assets.php @@ -26,6 +26,6 @@ class AddPhysicalToAssets extends Migration */ public function down() { - $table->dropColumn('physical'); + // $table->dropColumn('physical'); } } From b5ea8b8a4fd17bc27ddffb05881a748fec4526b2 Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Tue, 10 Jan 2023 17:29:38 -0800 Subject: [PATCH 012/127] Conditionally drop table --- ..._12_06_225929_migration_cartalyst_sentry_install_groups.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/database/migrations/2012_12_06_225929_migration_cartalyst_sentry_install_groups.php b/database/migrations/2012_12_06_225929_migration_cartalyst_sentry_install_groups.php index cd45847bc7..49242f2e30 100644 --- a/database/migrations/2012_12_06_225929_migration_cartalyst_sentry_install_groups.php +++ b/database/migrations/2012_12_06_225929_migration_cartalyst_sentry_install_groups.php @@ -44,6 +44,7 @@ class MigrationCartalystSentryInstallGroups extends Migration */ public function down() { - Schema::drop('permission_groups'); + // See 2014_11_04_231416_update_group_field_for_reporting.php and 2019_06_12_184327_rename_groups_table.php + Schema::dropIfExists('permission_groups'); } } From e8c2b84d24b7fcfbd0bcced9bee09e0e701b5bed Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Wed, 11 Jan 2023 12:51:15 -0800 Subject: [PATCH 013/127] Add example dusk environment file --- .env.dusk.example | 106 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100644 .env.dusk.example diff --git a/.env.dusk.example b/.env.dusk.example new file mode 100644 index 0000000000..074f6fc3d7 --- /dev/null +++ b/.env.dusk.example @@ -0,0 +1,106 @@ +# -------------------------------------------- +# REQUIRED: BASIC APP SETTINGS +# -------------------------------------------- +APP_ENV=local +APP_DEBUG=false +APP_KEY=base64:hTUIUh9CP6dQx+6EjSlfWTgbaMaaRvlpEwk45vp+xmk= +APP_URL=http://127.0.0.1:8000 +APP_TIMEZONE='US/Eastern' +APP_LOCALE=en +APP_LOCKED=false +MAX_RESULTS=200 + +# -------------------------------------------- +# REQUIRED: UPLOADED FILE STORAGE SETTINGS +# -------------------------------------------- +PRIVATE_FILESYSTEM_DISK=local +PUBLIC_FILESYSTEM_DISK=local_public + +# -------------------------------------------- +# REQUIRED: DATABASE SETTINGS +# -------------------------------------------- +DB_CONNECTION=mysql +DB_HOST=127.0.0.1 +DB_PORT=3306 +DB_DATABASE=null +DB_USERNAME=null +DB_PASSWORD=null +DB_PREFIX=null +#DB_DUMP_PATH= + +# -------------------------------------------- +# OPTIONAL: SSL DATABASE SETTINGS +# -------------------------------------------- +DB_SSL=false +DB_SSL_KEY_PATH=null +DB_SSL_CERT_PATH=null +DB_SSL_CA_PATH=null +DB_SSL_CIPHER=null + +# -------------------------------------------- +# REQUIRED: OUTGOING MAIL SERVER SETTINGS +# -------------------------------------------- +MAIL_DRIVER="log" + + +# -------------------------------------------- +# REQUIRED: IMAGE LIBRARY +# This should be gd or imagick +# -------------------------------------------- +IMAGE_LIB=gd + + +# -------------------------------------------- +# OPTIONAL: SESSION SETTINGS +# -------------------------------------------- +SESSION_LIFETIME=12000 +EXPIRE_ON_CLOSE=false +ENCRYPT=true +COOKIE_NAME=snipeit_v5_local +SECURE_COOKIES=true + +# -------------------------------------------- +# OPTIONAL: SECURITY HEADER SETTINGS +# -------------------------------------------- +REFERRER_POLICY=same-origin +ENABLE_CSP=true +CORS_ALLOWED_ORIGINS="*" + +# -------------------------------------------- +# OPTIONAL: CACHE SETTINGS +# -------------------------------------------- +CACHE_DRIVER=file +SESSION_DRIVER=file +QUEUE_DRIVER=sync + +# -------------------------------------------- +# OPTIONAL: LOGIN THROTTLING +# -------------------------------------------- +LOGIN_MAX_ATTEMPTS=50000 +LOGIN_LOCKOUT_DURATION=1000 +RESET_PASSWORD_LINK_EXPIRES=15 + +# -------------------------------------------- +# OPTIONAL: API +# -------------------------------------------- +API_MAX_REQUESTS_PER_HOUR=200 + +# -------------------------------------------- +# OPTIONAL: SAML SETTINGS +# -------------------------------------------- +DISABLE_NOSAML_LOCAL_LOGIN=true + + +# -------------------------------------------- +# OPTIONAL: MISC +# -------------------------------------------- +LOG_CHANNEL=single +LOG_LEVEL=debug +LOG_CHANNEL=stack +LOG_SLACK_WEBHOOK_URL=null +APP_TRUSTED_PROXIES=192.168.1.1,10.0.0.1 +ALLOW_IFRAMING=true +ENABLE_HSTS=false +WARN_DEBUG=false +APP_CIPHER=AES-256-CBC + From 9a3a796e176ad593619d8633b73db77fe1d81ed7 Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Wed, 11 Jan 2023 12:57:05 -0800 Subject: [PATCH 014/127] Add dusk environment files to gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 37e9d3f68c..cc67e5c40d 100755 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ .couscous .DS_Store .env +.env.dusk.* .idea /bin/ /bootstrap/compiled.php From 49383ddbe0fd3c6a37a5a22a7cfeaa67c0c49926 Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Wed, 11 Jan 2023 12:58:57 -0800 Subject: [PATCH 015/127] Delete old dusk local configuration --- .env.dusk.local | 106 ------------------------------------------------ 1 file changed, 106 deletions(-) delete mode 100644 .env.dusk.local diff --git a/.env.dusk.local b/.env.dusk.local deleted file mode 100644 index 33343ffc51..0000000000 --- a/.env.dusk.local +++ /dev/null @@ -1,106 +0,0 @@ -# -------------------------------------------- -# REQUIRED: BASIC APP SETTINGS -# -------------------------------------------- -APP_ENV=local -APP_DEBUG=false -APP_KEY=base64:hTUIUh9CP6dQx+6EjSlfWTgbaMaaRvlpEwk45vp+xmk= -APP_URL=http://127.0.0.1:8000 -APP_TIMEZONE='US/Eastern' -APP_LOCALE=en -APP_LOCKED=false -MAX_RESULTS=200 - -# -------------------------------------------- -# REQUIRED: UPLOADED FILE STORAGE SETTINGS -# -------------------------------------------- -PRIVATE_FILESYSTEM_DISK=local -PUBLIC_FILESYSTEM_DISK=local_public - -# -------------------------------------------- -# REQUIRED: DATABASE SETTINGS -# -------------------------------------------- -DB_CONNECTION=mysql -DB_HOST=localhost -DB_PORT=3306 -DB_DATABASE=snipeit-local -DB_USERNAME=snipeit-local -DB_PASSWORD=snipeit-local -DB_PREFIX=null -DB_DUMP_PATH='/Applications/MAMP/Library/bin' - -# -------------------------------------------- -# OPTIONAL: SSL DATABASE SETTINGS -# -------------------------------------------- -DB_SSL=false -DB_SSL_KEY_PATH=null -DB_SSL_CERT_PATH=null -DB_SSL_CA_PATH=null -DB_SSL_CIPHER=null - -# -------------------------------------------- -# REQUIRED: OUTGOING MAIL SERVER SETTINGS -# -------------------------------------------- -MAIL_DRIVER="log" - - -# -------------------------------------------- -# REQUIRED: IMAGE LIBRARY -# This should be gd or imagick -# -------------------------------------------- -IMAGE_LIB=gd - - -# -------------------------------------------- -# OPTIONAL: SESSION SETTINGS -# -------------------------------------------- -SESSION_LIFETIME=12000 -EXPIRE_ON_CLOSE=false -ENCRYPT=true -COOKIE_NAME=snipeit_v5_local -SECURE_COOKIES=true - -# -------------------------------------------- -# OPTIONAL: SECURITY HEADER SETTINGS -# -------------------------------------------- -REFERRER_POLICY=same-origin -ENABLE_CSP=true -CORS_ALLOWED_ORIGINS="*" - -# -------------------------------------------- -# OPTIONAL: CACHE SETTINGS -# -------------------------------------------- -CACHE_DRIVER=file -SESSION_DRIVER=file -QUEUE_DRIVER=sync - -# -------------------------------------------- -# OPTIONAL: LOGIN THROTTLING -# -------------------------------------------- -LOGIN_MAX_ATTEMPTS=50000 -LOGIN_LOCKOUT_DURATION=1000 -RESET_PASSWORD_LINK_EXPIRES=15 - -# -------------------------------------------- -# OPTIONAL: API -# -------------------------------------------- -API_MAX_REQUESTS_PER_HOUR=200 - -# -------------------------------------------- -# OPTIONAL: SAML SETTINGS -# -------------------------------------------- -DISABLE_NOSAML_LOCAL_LOGIN=true - - -# -------------------------------------------- -# OPTIONAL: MISC -# -------------------------------------------- -LOG_CHANNEL=single -LOG_LEVEL=debug -LOG_CHANNEL=stack -LOG_SLACK_WEBHOOK_URL=null -APP_TRUSTED_PROXIES=192.168.1.1,10.0.0.1 -ALLOW_IFRAMING=true -ENABLE_HSTS=false -WARN_DEBUG=false -APP_CIPHER=AES-256-CBC - From bc80f672ee1f88e8d4bc66facee410f439bcdedd Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Wed, 11 Jan 2023 13:00:34 -0800 Subject: [PATCH 016/127] Keep the example dusk environment file --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index cc67e5c40d..078a7e4b8a 100755 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ .DS_Store .env .env.dusk.* +!.env.dusk.example .idea /bin/ /bootstrap/compiled.php From 49f2573f36602370666808494d9d738cd96ee436 Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Wed, 11 Jan 2023 13:51:01 -0800 Subject: [PATCH 017/127] Update testing readme --- TESTING.md | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/TESTING.md b/TESTING.md index 6624289758..f7034895a3 100644 --- a/TESTING.md +++ b/TESTING.md @@ -43,23 +43,25 @@ you want to run. ## Browser Tests -The browser tests use [Dusk](https://laravel.com/docs/8.x/dusk) to run them. -When troubleshooting any problems, make sure that your `.env` file is configured -correctly to run the existing application. +Browser tests are run via [Laravel Dusk](https://laravel.com/docs/8.x/dusk) and require Google Chrome to be installed. + +Before attempting to run Dusk tests copy the example environment file for Dusk and update the values to match your environment: + +`cp .env.dusk.example .env.dusk.local` +> `local` refers to the value of `APP_ENV` in your `.env` so if you have it set to `dev` then the file should be named `.env.dusk.dev`. ### Test Setup -Your application needs to be configued and up and running in order for the browser +Your application needs to be configured and up and running in order for the browser tests to actually run. When running the tests locally, you can start the application using the following command: `php artisan serve` - -To run the test suite use the following command from another terminal tab or window: +Now you are ready to run the test suite. Use the following command from another terminal tab or window: `php artisan dusk` -To run individual test files, you can pass the path to the test that you want to run. +To run individual test files, you can pass the path to the test that you want to run: `php artisan dusk tests/Browser/LoginTest.php` From 0dd7cc9967941a821fe9d45864ab0c6844c8be4d Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Wed, 11 Jan 2023 13:54:28 -0800 Subject: [PATCH 018/127] Add note about installing ChromeDriver to testing readme --- TESTING.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/TESTING.md b/TESTING.md index f7034895a3..a1706177a9 100644 --- a/TESTING.md +++ b/TESTING.md @@ -65,3 +65,9 @@ Now you are ready to run the test suite. Use the following command from another To run individual test files, you can pass the path to the test that you want to run: `php artisan dusk tests/Browser/LoginTest.php` + +If you get an error when attempting to run Dusk tests that says `Couldn't connect to server` run: + +`php artisan dusk:chrome-driver --detect` + +This command will install the specific ChromeDriver Dusk needs for your operating system and Chrome version. From 51da747809ff039d5d294f493f13cd726cd4fbc3 Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Wed, 11 Jan 2023 18:05:07 -0800 Subject: [PATCH 019/127] Add note about database requirements when running Dusk tests --- TESTING.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/TESTING.md b/TESTING.md index a1706177a9..8a430d498e 100644 --- a/TESTING.md +++ b/TESTING.md @@ -50,6 +50,8 @@ Before attempting to run Dusk tests copy the example environment file for Dusk a `cp .env.dusk.example .env.dusk.local` > `local` refers to the value of `APP_ENV` in your `.env` so if you have it set to `dev` then the file should be named `.env.dusk.dev`. +**Important**: Dusk tests cannot be run using an in-memory SQLite database. Additionally, the Dusk test suite uses the `DatabaseMigrations` trait which will leave the database in a fresh state after running. Therefore, it is recommended that you create a test database and point `DB_DATABASE` in `.env.dusk.local` to it. + ### Test Setup Your application needs to be configured and up and running in order for the browser From e6dc61d2cffe712f9f0a77b78eed83f84ed7f5f1 Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Mon, 23 Jan 2023 15:42:05 -0800 Subject: [PATCH 020/127] Revert column names to legacy versions in down method --- ...357_fix_utf8_custom_field_column_names.php | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/database/migrations/2017_01_25_063357_fix_utf8_custom_field_column_names.php b/database/migrations/2017_01_25_063357_fix_utf8_custom_field_column_names.php index 72e85698e0..4725cccfe1 100644 --- a/database/migrations/2017_01_25_063357_fix_utf8_custom_field_column_names.php +++ b/database/migrations/2017_01_25_063357_fix_utf8_custom_field_column_names.php @@ -4,6 +4,7 @@ use App\Models\CustomField; use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; +use Illuminate\Support\Str; /** * Fixes issue #2551 where columns got donked if the field name in non-ascii @@ -71,6 +72,25 @@ class FixUtf8CustomFieldColumnNames extends Migration */ public function down() { + // In the up method above, updateLegacyColumnName is called and custom fields in the assets table are prefixed + // with "_snipe_it_", suffixed with "_{id of the CustomField}", and stored in custom_fields.db_column. + // The following reverses those changes. + foreach (CustomField::all() as $field) { + $currentColumnName = $field->db_column; + + // "_snipeit_imei_1" becomes "_snipeit_imei" + $legacyColumnName = (string) Str::of($currentColumnName)->replaceMatches('/_(\d)+$/', ''); + + if (Schema::hasColumn(CustomField::$table_name, $currentColumnName)) { + Schema::table(CustomField::$table_name, function (Blueprint $table) use ($currentColumnName, $legacyColumnName) { + $table->renameColumn( + $currentColumnName, + $legacyColumnName + ); + }); + } + } + Schema::table('custom_fields', function ($table) { $table->dropColumn('db_column'); $table->dropColumn('help_text'); From 760844de6fb252bd7f979d8eaa6fa3a92283caf2 Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Mon, 23 Jan 2023 15:42:33 -0800 Subject: [PATCH 021/127] Add conditionals --- .../2015_09_22_003413_migrate_mac_address.php | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/database/migrations/2015_09_22_003413_migrate_mac_address.php b/database/migrations/2015_09_22_003413_migrate_mac_address.php index 8167e28adf..3c4bf93e15 100644 --- a/database/migrations/2015_09_22_003413_migrate_mac_address.php +++ b/database/migrations/2015_09_22_003413_migrate_mac_address.php @@ -48,13 +48,19 @@ class MigrateMacAddress extends Migration */ public function down() { - // $f = \App\Models\CustomFieldset::where(['name' => 'Asset with MAC Address'])->first(); - $f->fields()->delete(); - $f->delete(); + + if ($f) { + $f->fields()->delete(); + $f->delete(); + } + Schema::table('models', function (Blueprint $table) { $table->renameColumn('deprecated_mac_address', 'show_mac_address'); }); - DB::statement('ALTER TABLE assets CHANGE _snipeit_mac_address_1 mac_address varchar(255)'); + + if (Schema::hasColumn('assets', '_snipeit_mac_address')) { + DB::statement('ALTER TABLE assets CHANGE _snipeit_mac_address mac_address varchar(255)'); + } } } From cd582be851b6dff9d1c3135ff3c0a7d79519ecae Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Mon, 23 Jan 2023 15:42:45 -0800 Subject: [PATCH 022/127] Drop tables that may exist in down methods --- ...2_12_06_225929_migration_cartalyst_sentry_install_groups.php | 1 + .../migrations/2013_11_25_031458_create_license_seats_table.php | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/database/migrations/2012_12_06_225929_migration_cartalyst_sentry_install_groups.php b/database/migrations/2012_12_06_225929_migration_cartalyst_sentry_install_groups.php index 49242f2e30..55d7318736 100644 --- a/database/migrations/2012_12_06_225929_migration_cartalyst_sentry_install_groups.php +++ b/database/migrations/2012_12_06_225929_migration_cartalyst_sentry_install_groups.php @@ -46,5 +46,6 @@ class MigrationCartalystSentryInstallGroups extends Migration { // See 2014_11_04_231416_update_group_field_for_reporting.php and 2019_06_12_184327_rename_groups_table.php Schema::dropIfExists('permission_groups'); + Schema::dropIfExists('groups'); } } diff --git a/database/migrations/2013_11_25_031458_create_license_seats_table.php b/database/migrations/2013_11_25_031458_create_license_seats_table.php index 466ef00870..d023b8ebec 100755 --- a/database/migrations/2013_11_25_031458_create_license_seats_table.php +++ b/database/migrations/2013_11_25_031458_create_license_seats_table.php @@ -31,6 +31,6 @@ class CreateLicenseSeatsTable extends Migration */ public function down() { - // + Schema::dropIfExists('license_seats'); } } From 0f8ee220534b89fe5ef3b7a8f652ce306d3c0752 Mon Sep 17 00:00:00 2001 From: Godfrey M Date: Tue, 24 Jan 2023 09:25:05 -0800 Subject: [PATCH 023/127] Creates Slack Setting Form --- app/Http/Livewire/SlackSettingsForm.php | 21 +++++++++++++++++++ .../livewire/slack-settings-form.blade.php | 3 +++ 2 files changed, 24 insertions(+) create mode 100644 app/Http/Livewire/SlackSettingsForm.php create mode 100644 resources/views/livewire/slack-settings-form.blade.php diff --git a/app/Http/Livewire/SlackSettingsForm.php b/app/Http/Livewire/SlackSettingsForm.php new file mode 100644 index 0000000000..c796ee53cc --- /dev/null +++ b/app/Http/Livewire/SlackSettingsForm.php @@ -0,0 +1,21 @@ + + {{-- In work, do what you enjoy. --}} + From 3c4f254583d8454a70c50f95538b7f61f4c7ba10 Mon Sep 17 00:00:00 2001 From: snipe Date: Tue, 24 Jan 2023 13:38:53 -0800 Subject: [PATCH 024/127] Enforce Y-m-d as date format for date fields Signed-off-by: snipe --- app/Models/Accessory.php | 1 + app/Models/Asset.php | 9 +++++---- app/Models/Component.php | 2 +- app/Models/Consumable.php | 1 + app/Models/License.php | 3 +++ app/Models/User.php | 4 ++-- 6 files changed, 13 insertions(+), 7 deletions(-) diff --git a/app/Models/Accessory.php b/app/Models/Accessory.php index 3f2004b047..9569917ab3 100755 --- a/app/Models/Accessory.php +++ b/app/Models/Accessory.php @@ -63,6 +63,7 @@ class Accessory extends SnipeModel 'company_id' => 'integer|nullable', 'min_amt' => 'integer|min:0|nullable', 'purchase_cost' => 'numeric|nullable|gte:0', + 'purchase_date' => 'date_format:Y-m-d|nullable', ]; diff --git a/app/Models/Asset.php b/app/Models/Asset.php index f8e0cab314..75e1f38e45 100644 --- a/app/Models/Asset.php +++ b/app/Models/Asset.php @@ -105,16 +105,17 @@ class Asset extends Depreciable 'company_id' => 'integer|nullable', 'warranty_months' => 'numeric|nullable|digits_between:0,240', 'physical' => 'numeric|max:1|nullable', - 'checkout_date' => 'date|max:10|min:10|nullable', - 'checkin_date' => 'date|max:10|min:10|nullable', + 'checkout_date' => 'date_format:Y-m-d|max:10|min:10|nullable', + 'checkin_date' => 'date_format:Y-m-d|max:10|min:10|nullable', 'location_id' => 'exists:locations,id|nullable', 'rtd_location_id' => 'exists:locations,id|nullable', 'asset_tag' => 'required|min:1|max:255|unique_undeleted', 'status' => 'integer', + 'purchase_date' => 'date_format:Y-m-d|nullable', 'serial' => 'unique_serial|nullable', 'purchase_cost' => 'numeric|nullable|gte:0', - 'next_audit_date' => 'date|nullable', - 'last_audit_date' => 'date|nullable', + 'next_audit_date' => 'date_format:Y-m-d|nullable', + 'last_audit_date' => 'date_format:Y-m-d|nullable', 'supplier_id' => 'exists:suppliers,id|nullable', ]; diff --git a/app/Models/Component.php b/app/Models/Component.php index dc353d288c..98230132be 100644 --- a/app/Models/Component.php +++ b/app/Models/Component.php @@ -35,7 +35,7 @@ class Component extends SnipeModel 'category_id' => 'required|integer|exists:categories,id', 'company_id' => 'integer|nullable', 'min_amt' => 'integer|min:0|nullable', - 'purchase_date' => 'date|nullable', + 'purchase_date' => 'date_format:Y-m-d|nullable', 'purchase_cost' => 'numeric|nullable|gte:0', ]; diff --git a/app/Models/Consumable.php b/app/Models/Consumable.php index c04c9b53d5..ea4ac6086b 100644 --- a/app/Models/Consumable.php +++ b/app/Models/Consumable.php @@ -41,6 +41,7 @@ class Consumable extends SnipeModel 'company_id' => 'integer|nullable', 'min_amt' => 'integer|min:0|nullable', 'purchase_cost' => 'numeric|nullable|gte:0', + 'purchase_date' => 'date_format:Y-m-d|nullable', ]; /** diff --git a/app/Models/License.php b/app/Models/License.php index b59387a42e..d3c4d8a1c3 100755 --- a/app/Models/License.php +++ b/app/Models/License.php @@ -50,6 +50,9 @@ class License extends Depreciable 'category_id' => 'required|exists:categories,id', 'company_id' => 'integer|nullable', 'purchase_cost'=> 'numeric|nullable|gte:0', + 'purchase_date' => 'date_format:Y-m-d|nullable', + 'expiration_date' => 'date_format:Y-m-d|nullable', + 'termination_date' => 'date_format:Y-m-d|nullable', ]; /** diff --git a/app/Models/User.php b/app/Models/User.php index 34c0af6b2e..4d430af741 100755 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -98,8 +98,8 @@ class User extends SnipeModel implements AuthenticatableContract, AuthorizableCo 'website' => 'url|nullable|max:191', 'manager_id' => 'nullable|exists:users,id|cant_manage_self', 'location_id' => 'exists:locations,id|nullable', - 'start_date' => 'nullable|date', - 'end_date' => 'nullable|date|after_or_equal:start_date', + 'start_date' => 'nullable|date_format:Y-m-d', + 'end_date' => 'nullable|date_format:Y-m-d|after_or_equal:start_date', ]; /** From 91394f72624a501fde291c5631044e4bbb4fa261 Mon Sep 17 00:00:00 2001 From: snipe Date: Tue, 24 Jan 2023 17:23:06 -0800 Subject: [PATCH 025/127] Removed duplicate comment section Signed-off-by: snipe --- resources/lang/en/validation.php | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/resources/lang/en/validation.php b/resources/lang/en/validation.php index 04f8d65303..18387310f8 100644 --- a/resources/lang/en/validation.php +++ b/resources/lang/en/validation.php @@ -103,17 +103,6 @@ return [ ], - /* - |-------------------------------------------------------------------------- - | Custom Validation Language Lines - |-------------------------------------------------------------------------- - | - | Here you may specify custom validation messages for attributes using the - | convention "attribute.rule" to name the lines. This makes it quick to - | specify a specific custom language line for a given attribute rule. - | - */ - /* |-------------------------------------------------------------------------- | Custom Validation Language Lines From a61ccbb9658da024185575fe017fe81b86b64776 Mon Sep 17 00:00:00 2001 From: snipe Date: Tue, 24 Jan 2023 17:33:49 -0800 Subject: [PATCH 026/127] Added very clunky but better error messages on that validation for date_format Signed-off-by: snipe --- resources/lang/en/validation.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/resources/lang/en/validation.php b/resources/lang/en/validation.php index 18387310f8..31c9dcd85d 100644 --- a/resources/lang/en/validation.php +++ b/resources/lang/en/validation.php @@ -120,6 +120,18 @@ return [ 'hashed_pass' => 'Your current password is incorrect', 'dumbpwd' => 'That password is too common.', 'statuslabel_type' => 'You must select a valid status label type', + + // date_format validation with slightly less stupid messages. It duplicates a lot, but it gets the job done :( + // We use this because the default error message for date_format is reflects php Y-m-d, which non-PHP + // people won't know how to format. + 'purchase_date.date_format' => 'The :attribute must be a valid date in YYYY-MM-DD format', + 'last_audit_date.date_format' => 'The :attribute must be a valid date in YYYY-MM-DD hh:mm:ss format', + 'expiration_date.date_format' => 'The :attribute must be a valid date in YYYY-MM-DD format', + 'termination_date.date_format' => 'The :attribute must be a valid date in YYYY-MM-DD format', + 'expected_checkin.date_format' => 'The :attribute must be a valid date in YYYY-MM-DD format', + 'start_date.date_format' => 'The :attribute must be a valid date in YYYY-MM-DD format', + 'end_date.date_format' => 'The :attribute must be a valid date in YYYY-MM-DD format', + ], /* From fd2a057d384d9a57b6717fd92020e2f44c4f460f Mon Sep 17 00:00:00 2001 From: snipe Date: Tue, 24 Jan 2023 17:36:58 -0800 Subject: [PATCH 027/127] Make audit dates fillable Signed-off-by: snipe --- app/Models/Asset.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/Models/Asset.php b/app/Models/Asset.php index 75e1f38e45..e3e2e96b0c 100644 --- a/app/Models/Asset.php +++ b/app/Models/Asset.php @@ -146,6 +146,9 @@ class Asset extends Depreciable 'last_checkout', 'expected_checkin', 'byod', + 'last_audit_date', + 'next_audit_date', + ]; use Searchable; From 9c79fc19cb6eab3f31d587120b1c9c9534a34dd9 Mon Sep 17 00:00:00 2001 From: snipe Date: Tue, 24 Jan 2023 17:37:15 -0800 Subject: [PATCH 028/127] =?UTF-8?q?Tightened=20up=20and=20removed=20some?= =?UTF-8?q?=20validation=20that=20wasn=E2=80=99t=20needed?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: snipe --- app/Models/Asset.php | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/app/Models/Asset.php b/app/Models/Asset.php index e3e2e96b0c..3c1bc9beca 100644 --- a/app/Models/Asset.php +++ b/app/Models/Asset.php @@ -84,11 +84,11 @@ class Asset extends Depreciable protected $casts = [ - 'purchase_date' => 'datetime', + 'purchase_date' => 'date', 'last_checkout' => 'datetime', - 'expected_checkin' => 'datetime', + 'expected_checkin' => 'date', 'last_audit_date' => 'datetime', - 'next_audit_date' => 'datetime', + 'next_audit_date' => 'date', 'model_id' => 'integer', 'status_id' => 'integer', 'company_id' => 'integer', @@ -105,17 +105,14 @@ class Asset extends Depreciable 'company_id' => 'integer|nullable', 'warranty_months' => 'numeric|nullable|digits_between:0,240', 'physical' => 'numeric|max:1|nullable', - 'checkout_date' => 'date_format:Y-m-d|max:10|min:10|nullable', - 'checkin_date' => 'date_format:Y-m-d|max:10|min:10|nullable', + 'last_checkout' => 'date|date_format:Y-m-d H:i:s|nullable', + 'expected_checkin' => 'date|date_format:Y-m-d|nullable', 'location_id' => 'exists:locations,id|nullable', 'rtd_location_id' => 'exists:locations,id|nullable', 'asset_tag' => 'required|min:1|max:255|unique_undeleted', - 'status' => 'integer', - 'purchase_date' => 'date_format:Y-m-d|nullable', + 'purchase_date' => 'date|date_format:Y-m-d|nullable', 'serial' => 'unique_serial|nullable', 'purchase_cost' => 'numeric|nullable|gte:0', - 'next_audit_date' => 'date_format:Y-m-d|nullable', - 'last_audit_date' => 'date_format:Y-m-d|nullable', 'supplier_id' => 'exists:suppliers,id|nullable', ]; From 2e22eeade548c18228a9852e63a0472051bad29e Mon Sep 17 00:00:00 2001 From: Godfrey M Date: Wed, 25 Jan 2023 14:29:20 -0800 Subject: [PATCH 029/127] adds one input --- app/Http/Livewire/SlackSettingsForm.php | 5 +++++ .../livewire/slack-settings-form.blade.php | 19 ++++++++++++++++++- resources/views/settings/slack.blade.php | 17 +---------------- 3 files changed, 24 insertions(+), 17 deletions(-) diff --git a/app/Http/Livewire/SlackSettingsForm.php b/app/Http/Livewire/SlackSettingsForm.php index c796ee53cc..0193aa7daf 100644 --- a/app/Http/Livewire/SlackSettingsForm.php +++ b/app/Http/Livewire/SlackSettingsForm.php @@ -11,6 +11,11 @@ class SlackSettingsForm extends Component { public Setting $setting; + protected $rules = [ + 'setting.slack_endpoint' => 'url|required_with:slack_channel|starts_with:https://hooks.slack.com/|nullable', + 'setting.slack_channel' => 'required_with:slack_endpoint|starts_with:#|nullable', + 'setting.slack_botname' => 'string|nullable', + ]; public function render() diff --git a/resources/views/livewire/slack-settings-form.blade.php b/resources/views/livewire/slack-settings-form.blade.php index cdda2ce1ff..4846aa95fb 100644 --- a/resources/views/livewire/slack-settings-form.blade.php +++ b/resources/views/livewire/slack-settings-form.blade.php @@ -1,3 +1,20 @@
- {{-- In work, do what you enjoy. --}} +
+
+
+ {{ Form::label('slack_endpoint', trans('admin/settings/general.slack_endpoint')) }} +
+
+ @if (config('app.lock_passwords')===true) + {{-- {{ Form::text('slack_endpoint', old('slack_endpoint', $setting->slack_endpoint), array('class' => 'form-control','disabled'=>'disabled','placeholder' => 'https://hooks.slack.com/services/XXXXXXXXXXXXXXXXXXXXX', 'id' => 'slack_endpoint')) }}--}} +

{{ trans('general.feature_disabled') }}

+ slack_endpoint)}} > + @else + slack_endpoint)}} > + {{-- {{ Form::text('slack_endpoint', old('slack_endpoint', $setting->slack_endpoint), array('class' => 'form-control','placeholder' => 'https://hooks.slack.com/services/XXXXXXXXXXXXXXXXXXXXX', 'id' => 'slack_endpoint')) }}--}} + @endif + {!! $errors->first('slack_endpoint', '') !!} +
+
+
diff --git a/resources/views/settings/slack.blade.php b/resources/views/settings/slack.blade.php index 705510ab8e..f5f21c5aa9 100644 --- a/resources/views/settings/slack.blade.php +++ b/resources/views/settings/slack.blade.php @@ -50,22 +50,7 @@
- -
-
- {{ Form::label('slack_endpoint', trans('admin/settings/general.slack_endpoint')) }} -
-
- @if (config('app.lock_passwords')===true) - {{ Form::text('slack_endpoint', old('slack_endpoint', $setting->slack_endpoint), array('class' => 'form-control','disabled'=>'disabled','placeholder' => 'https://hooks.slack.com/services/XXXXXXXXXXXXXXXXXXXXX', 'id' => 'slack_endpoint')) }} -

{{ trans('general.feature_disabled') }}

- - @else - {{ Form::text('slack_endpoint', old('slack_endpoint', $setting->slack_endpoint), array('class' => 'form-control','placeholder' => 'https://hooks.slack.com/services/XXXXXXXXXXXXXXXXXXXXX', 'id' => 'slack_endpoint')) }} - @endif - {!! $errors->first('slack_endpoint', '') !!} -
-
+ @livewire('slack-settings-form', ['setting' => $setting])
From a69cb6204a603edf4d861dffed532f5e8784b62f Mon Sep 17 00:00:00 2001 From: Godfrey M Date: Wed, 25 Jan 2023 16:22:34 -0800 Subject: [PATCH 030/127] adds rest of inputs, and corrects Data binding --- app/Http/Livewire/SlackSettingsForm.php | 29 ++++++++++++-- .../livewire/slack-settings-form.blade.php | 40 ++++++++++++++++++- resources/views/settings/slack.blade.php | 34 +--------------- 3 files changed, 65 insertions(+), 38 deletions(-) diff --git a/app/Http/Livewire/SlackSettingsForm.php b/app/Http/Livewire/SlackSettingsForm.php index 0193aa7daf..42d5a70824 100644 --- a/app/Http/Livewire/SlackSettingsForm.php +++ b/app/Http/Livewire/SlackSettingsForm.php @@ -4,23 +4,46 @@ namespace App\Http\Livewire; use Livewire\Component; use App\Models\Setting; +use App\Http\Requests\Request; class SlackSettingsForm extends Component { + public $slack_endpoint; + public $slack_channel; + public $slack_botname; + public Setting $setting; protected $rules = [ - 'setting.slack_endpoint' => 'url|required_with:slack_channel|starts_with:https://hooks.slack.com/|nullable', - 'setting.slack_channel' => 'required_with:slack_endpoint|starts_with:#|nullable', - 'setting.slack_botname' => 'string|nullable', + 'slack_endpoint' => 'url|required_with:slack_channel|starts_with:https://hooks.slack.com/|nullable', + 'slack_channel' => 'required_with:slack_endpoint|starts_with:#|nullable', + 'slack_botname' => 'string|nullable', ]; + public function mount(){ + + $this->setting= Setting::getSettings(); + $this->slack_endpoint = $this->setting->slack_endpoint; + $this->slack_channel = $this->setting->slack_channel; + $this->slack_botname = $this->setting->slack_botname; + + } public function render() { return view('livewire.slack-settings-form'); } + public function submit() + { + + $this->validate(); + + $this->setting->slack_endpoint = $this->slack_endpoint; + $this->setting->slack_channel = $this->slack_channel; + $this->setting->slack_botname = $this->slack_botname; + + } } diff --git a/resources/views/livewire/slack-settings-form.blade.php b/resources/views/livewire/slack-settings-form.blade.php index 4846aa95fb..cd7978f08e 100644 --- a/resources/views/livewire/slack-settings-form.blade.php +++ b/resources/views/livewire/slack-settings-form.blade.php @@ -8,13 +8,49 @@ @if (config('app.lock_passwords')===true) {{-- {{ Form::text('slack_endpoint', old('slack_endpoint', $setting->slack_endpoint), array('class' => 'form-control','disabled'=>'disabled','placeholder' => 'https://hooks.slack.com/services/XXXXXXXXXXXXXXXXXXXXX', 'id' => 'slack_endpoint')) }}--}}

{{ trans('general.feature_disabled') }}

- slack_endpoint)}} > + @else - slack_endpoint)}} > + {{-- {{ Form::text('slack_endpoint', old('slack_endpoint', $setting->slack_endpoint), array('class' => 'form-control','placeholder' => 'https://hooks.slack.com/services/XXXXXXXXXXXXXXXXXXXXX', 'id' => 'slack_endpoint')) }}--}} @endif {!! $errors->first('slack_endpoint', '') !!}
+ + +
+
+ {{ Form::label('slack_channel', trans('admin/settings/general.slack_channel')) }} +
+
+ @if (config('app.lock_passwords')===true) + +

{{ trans('general.feature_disabled') }}

+ + @else + + @endif + {!! $errors->first('slack_channel', '') !!} +
+
+ + +
+
+ {{ Form::label('slack_botname', trans('admin/settings/general.slack_botname')) }} +
+
+ @if (config('app.lock_passwords')===true) + {{ Form::text('slack_botname', old('slack_botname', $setting->slack_botname), array('class' => 'form-control','disabled'=>'disabled','placeholder' => 'Snipe-Bot')) }} + + +

{{ trans('general.feature_disabled') }}

+ + @else + + @endif + {!! $errors->first('slack_botname', '') !!} +
+
diff --git a/resources/views/settings/slack.blade.php b/resources/views/settings/slack.blade.php index f5f21c5aa9..6bbd321662 100644 --- a/resources/views/settings/slack.blade.php +++ b/resources/views/settings/slack.blade.php @@ -50,41 +50,9 @@
- @livewire('slack-settings-form', ['setting' => $setting]) + @livewire('slack-settings-form') - -
-
- {{ Form::label('slack_channel', trans('admin/settings/general.slack_channel')) }} -
-
- @if (config('app.lock_passwords')===true) - {{ Form::text('slack_channel', old('slack_channel', $setting->slack_channel), array('class' => 'form-control','disabled'=>'disabled','placeholder' => '#IT-Ops')) }} -

{{ trans('general.feature_disabled') }}

- @else - {{ Form::text('slack_channel', old('slack_channel', $setting->slack_channel), array('class' => 'form-control','placeholder' => '#IT-Ops')) }} - @endif - {!! $errors->first('slack_channel', '') !!} -
-
- - -
-
- {{ Form::label('slack_botname', trans('admin/settings/general.slack_botname')) }} -
-
- @if (config('app.lock_passwords')===true) - {{ Form::text('slack_botname', old('slack_botname', $setting->slack_botname), array('class' => 'form-control','disabled'=>'disabled','placeholder' => 'Snipe-Bot')) }} -

{{ trans('general.feature_disabled') }}

- - @else - {{ Form::text('slack_botname', old('slack_botname', $setting->slack_botname), array('class' => 'form-control','placeholder' => 'Snipe-Bot')) }} - @endif - {!! $errors->first('slack_botname', '') !!} -
-
- +
diff --git a/resources/views/hardware/checkout.blade.php b/resources/views/hardware/checkout.blade.php index 2b3cdbc19e..bdb03d3147 100755 --- a/resources/views/hardware/checkout.blade.php +++ b/resources/views/hardware/checkout.blade.php @@ -36,8 +36,8 @@ @else - This asset's model is invalid! - The asset should be edited to correct this before attempting to check it in or out. + {{ trans('admin/hardware/general.model_invalid')}} + {{ trans(admin/hardware/general.model_invalid_fix')}} @endif

diff --git a/resources/views/hardware/quickscan-checkin.blade.php b/resources/views/hardware/quickscan-checkin.blade.php index b2075c51d0..8884821809 100644 --- a/resources/views/hardware/quickscan-checkin.blade.php +++ b/resources/views/hardware/quickscan-checkin.blade.php @@ -73,7 +73,7 @@
@@ -88,129 +80,129 @@ @stop -@push('js') - +{{-- --}} -@endpush +{{--@endpush--}} From 214a1af61a804ccda8f490e7fa53cf3efadceeee Mon Sep 17 00:00:00 2001 From: akemidx Date: Mon, 30 Jan 2023 16:54:23 -0500 Subject: [PATCH 036/127] apostrophe updates --- resources/views/hardware/checkin.blade.php | 2 +- resources/views/hardware/checkout.blade.php | 2 +- resources/views/hardware/quickscan-checkin.blade.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/resources/views/hardware/checkin.blade.php b/resources/views/hardware/checkin.blade.php index 7f9087ae3d..f7fe067c8a 100755 --- a/resources/views/hardware/checkin.blade.php +++ b/resources/views/hardware/checkin.blade.php @@ -47,7 +47,7 @@ @else {{ trans('admin/hardware/general.model_invalid')}} - {{ trans(admin/hardware/general.model_invalid_fix')}} + {{ trans('admin/hardware/general.model_invalid_fix')}} @endif

diff --git a/resources/views/hardware/checkout.blade.php b/resources/views/hardware/checkout.blade.php index bdb03d3147..31dff70eaa 100755 --- a/resources/views/hardware/checkout.blade.php +++ b/resources/views/hardware/checkout.blade.php @@ -37,7 +37,7 @@ @else {{ trans('admin/hardware/general.model_invalid')}} - {{ trans(admin/hardware/general.model_invalid_fix')}} + {{ trans('admin/hardware/general.model_invalid_fix')}} @endif

diff --git a/resources/views/hardware/quickscan-checkin.blade.php b/resources/views/hardware/quickscan-checkin.blade.php index 8884821809..677e0c0f15 100644 --- a/resources/views/hardware/quickscan-checkin.blade.php +++ b/resources/views/hardware/quickscan-checkin.blade.php @@ -86,7 +86,7 @@ - {{ trans(general.processing') }}... + {{ trans('general.processing') }}... From fc044528b89249efc4852fb8ec992bfa702b7f1c Mon Sep 17 00:00:00 2001 From: Godfrey M Date: Mon, 30 Jan 2023 16:10:02 -0800 Subject: [PATCH 037/127] validation is working, success message appears, database is not updating --- app/Http/Livewire/SlackSettingsForm.php | 11 +- app/Models/Setting.php | 3 + .../livewire/slack-settings-form.blade.php | 138 ++++++++------ resources/views/settings/slack.blade.php | 175 +----------------- 4 files changed, 95 insertions(+), 232 deletions(-) diff --git a/app/Http/Livewire/SlackSettingsForm.php b/app/Http/Livewire/SlackSettingsForm.php index 63b9383a93..ddc38f36b3 100644 --- a/app/Http/Livewire/SlackSettingsForm.php +++ b/app/Http/Livewire/SlackSettingsForm.php @@ -10,6 +10,7 @@ class SlackSettingsForm extends Component public $slack_endpoint; public $slack_channel; public $slack_botname; + public $successMessage; public Setting $setting; @@ -41,13 +42,17 @@ class SlackSettingsForm extends Component public function submit() { - dd("we here now"); - - $this->validate(); + $this->validate([ + 'slack_endpoint' => 'url|required_with:slack_channel|starts_with:https://hooks.slack.com/|nullable', + 'slack_channel' => 'required_with:slack_endpoint|starts_with:#|nullable', + 'slack_botname' => 'string|nullable', + ]); $this->setting->slack_endpoint = $this->slack_endpoint; $this->setting->slack_channel = $this->slack_channel; $this->setting->slack_botname = $this->slack_botname; + $this->successMessage= trans('admin/settings/message.update.success'); + } } diff --git a/app/Models/Setting.php b/app/Models/Setting.php index f2a4184178..8289260647 100755 --- a/app/Models/Setting.php +++ b/app/Models/Setting.php @@ -83,6 +83,9 @@ class Setting extends Model 'email_domain', 'email_format', 'username_format', + 'slack_endpoint', + 'slack_channel', + 'slack_botname', ]; /** diff --git a/resources/views/livewire/slack-settings-form.blade.php b/resources/views/livewire/slack-settings-form.blade.php index a42a99fd7f..5d41ff2a6f 100644 --- a/resources/views/livewire/slack-settings-form.blade.php +++ b/resources/views/livewire/slack-settings-form.blade.php @@ -1,65 +1,85 @@
-
-
-
- {{ Form::label('slack_endpoint', trans('admin/settings/general.slack_endpoint')) }} -
-
- @if (config('app.lock_passwords')===true) - {{-- {{ Form::text('slack_endpoint', old('slack_endpoint', $setting->slack_endpoint), array('class' => 'form-control','disabled'=>'disabled','placeholder' => 'https://hooks.slack.com/services/XXXXXXXXXXXXXXXXXXXXX', 'id' => 'slack_endpoint')) }}--}} -

{{ trans('general.feature_disabled') }}

- - @else - - {{-- {{ Form::text('slack_endpoint', old('slack_endpoint', $setting->slack_endpoint), array('class' => 'form-control','placeholder' => 'https://hooks.slack.com/services/XXXXXXXXXXXXXXXXXXXXX', 'id' => 'slack_endpoint')) }}--}} - @endif - {!! $errors->first('slack_endpoint', '') !!} -
-
+
+
+
+
+

+ {{ trans('admin/settings/general.slack') }} +

+
+
+
+ {{$successMessage}} + + {{csrf_field()}} +
+
+ {{ Form::label('slack_endpoint', trans('admin/settings/general.slack_endpoint')) }} +
+
+ @if (config('app.lock_passwords')===true) + {{-- {{ Form::text('slack_endpoint', old('slack_endpoint', $setting->slack_endpoint), array('class' => 'form-control','disabled'=>'disabled','placeholder' => 'https://hooks.slack.com/services/XXXXXXXXXXXXXXXXXXXXX', 'id' => 'slack_endpoint')) }}--}} +

{{ trans('general.feature_disabled') }}

+ + @else + + {{-- {{ Form::text('slack_endpoint', old('slack_endpoint', $setting->slack_endpoint), array('class' => 'form-control','placeholder' => 'https://hooks.slack.com/services/XXXXXXXXXXXXXXXXXXXXX', 'id' => 'slack_endpoint')) }}--}} + @endif + {!! $errors->first('slack_endpoint', '') !!} +
+
- -
-
- {{ Form::label('slack_channel', trans('admin/settings/general.slack_channel')) }} -
-
- @if (config('app.lock_passwords')===true) - -

{{ trans('general.feature_disabled') }}

+ +
+
+ {{ Form::label('slack_channel', trans('admin/settings/general.slack_channel')) }} +
+
+ @if (config('app.lock_passwords')===true) + +

{{ trans('general.feature_disabled') }}

- @else - - @endif - {!! $errors->first('slack_channel', '') !!} -
-
- - -
-
- {{ Form::label('slack_botname', trans('admin/settings/general.slack_botname')) }} -
-
- @if (config('app.lock_passwords')===true) - {{ Form::text('slack_botname', old('slack_botname', $setting->slack_botname), array('class' => 'form-control','disabled'=>'disabled','placeholder' => 'Snipe-Bot')) }} - - -

{{ trans('general.feature_disabled') }}

- - @else - - @endif - {!! $errors->first('slack_botname', '') !!} -
-
- -
- + +
+
+ {{ Form::label('slack_botname', trans('admin/settings/general.slack_botname')) }} +
+
+ @if (config('app.lock_passwords')===true) + {{ Form::text('slack_botname', old('slack_botname', $setting->slack_botname), array('class' => 'form-control','disabled'=>'disabled','placeholder' => 'Snipe-Bot')) }} + +

{{ trans('general.feature_disabled') }}

+ + @else + + @endif + {!! $errors->first('slack_botname', '') !!} +
+
+ + + +
+
+ +
+
+
+
diff --git a/resources/views/settings/slack.blade.php b/resources/views/settings/slack.blade.php index 67a3550536..9e0286c61b 100644 --- a/resources/views/settings/slack.blade.php +++ b/resources/views/settings/slack.blade.php @@ -20,189 +20,24 @@ } - - {{ Form::open(['method' => 'POST', 'files' => false, 'autocomplete' => 'off', 'class' => 'form-horizontal', 'role' => 'form' ]) }} - {{csrf_field()}} - -
-
-
-
-

- {{ trans('admin/settings/general.slack') }} -

-
-
+

{!! trans('admin/settings/general.slack_integration_help',array('slack_link' => 'https://my.slack.com/services/new/incoming-webhook')) !!} - @if (($setting->slack_channel=='') && ($setting->slack_endpoint=='')) - {{ trans('admin/settings/general.slack_integration_help_button') }} - @endif -

+{{-- @if (($setting->slack_channel=='') && ($setting->slack_endpoint==''))--}} +{{-- {{ trans('admin/settings/general.slack_integration_help_button') }}--}} +{{-- @endif--}} +{{--

--}} -
@livewire('slack-settings-form') - -
-
- -
-
-
- - {{Form::close()}} - -@stop - -{{--@push('js')--}} -{{-- --}} - -{{--@endpush--}} From 1e0c58c3cf77beb07c2e9e6624bf233dcd0466ab Mon Sep 17 00:00:00 2001 From: Godfrey M Date: Tue, 31 Jan 2023 11:32:05 -0800 Subject: [PATCH 038/127] saves data correctly now --- app/Http/Livewire/SlackSettingsForm.php | 5 +- .../livewire/slack-settings-form.blade.php | 141 ++++++++---------- resources/views/settings/slack.blade.php | 28 +++- 3 files changed, 90 insertions(+), 84 deletions(-) diff --git a/app/Http/Livewire/SlackSettingsForm.php b/app/Http/Livewire/SlackSettingsForm.php index ddc38f36b3..2cb153734c 100644 --- a/app/Http/Livewire/SlackSettingsForm.php +++ b/app/Http/Livewire/SlackSettingsForm.php @@ -52,7 +52,10 @@ class SlackSettingsForm extends Component $this->setting->slack_channel = $this->slack_channel; $this->setting->slack_botname = $this->slack_botname; - $this->successMessage= trans('admin/settings/message.update.success'); + $this->setting->save(); + + session()->flash('message',trans('admin/settings/message.update.success')); + } } diff --git a/resources/views/livewire/slack-settings-form.blade.php b/resources/views/livewire/slack-settings-form.blade.php index 5d41ff2a6f..b01ffa867f 100644 --- a/resources/views/livewire/slack-settings-form.blade.php +++ b/resources/views/livewire/slack-settings-form.blade.php @@ -1,85 +1,76 @@ -
-
-
-
-
-

- {{ trans('admin/settings/general.slack') }} -

-
-
-
- {{$successMessage}} -
- {{csrf_field()}} -
-
- {{ Form::label('slack_endpoint', trans('admin/settings/general.slack_endpoint')) }} -
-
- @if (config('app.lock_passwords')===true) - {{-- {{ Form::text('slack_endpoint', old('slack_endpoint', $setting->slack_endpoint), array('class' => 'form-control','disabled'=>'disabled','placeholder' => 'https://hooks.slack.com/services/XXXXXXXXXXXXXXXXXXXXX', 'id' => 'slack_endpoint')) }}--}} -

{{ trans('general.feature_disabled') }}

- - @else - - {{-- {{ Form::text('slack_endpoint', old('slack_endpoint', $setting->slack_endpoint), array('class' => 'form-control','placeholder' => 'https://hooks.slack.com/services/XXXXXXXXXXXXXXXXXXXXX', 'id' => 'slack_endpoint')) }}--}} - @endif - {!! $errors->first('slack_endpoint', '') !!} -
-
- -
-
- {{ Form::label('slack_channel', trans('admin/settings/general.slack_channel')) }} -
-
- @if (config('app.lock_passwords')===true) - -

{{ trans('general.feature_disabled') }}

- @else - - @endif - {!! $errors->first('slack_channel', '') !!} -
+
+ @if (session()->has('message')) +
+ {{session('message')}} +
+ @endif + + {{csrf_field()}} + +
+
+ {{ Form::label('slack_endpoint', trans('admin/settings/general.slack_endpoint')) }}
- - -
-
- {{ Form::label('slack_botname', trans('admin/settings/general.slack_botname')) }} -
-
- @if (config('app.lock_passwords')===true) - {{ Form::text('slack_botname', old('slack_botname', $setting->slack_botname), array('class' => 'form-control','disabled'=>'disabled','placeholder' => 'Snipe-Bot')) }} - -

{{ trans('general.feature_disabled') }}

- - @else - - @endif - {!! $errors->first('slack_botname', '') !!} -
+
+ @if (config('app.lock_passwords')===true) +{{-- {{ Form::text('slack_endpoint', old('slack_endpoint', $setting->slack_endpoint), array('class' => 'form-control','disabled'=>'disabled','placeholder' => 'https://hooks.slack.com/services/XXXXXXXXXXXXXXXXXXXXX', 'id' => 'slack_endpoint')) }}--}} +

{{ trans('general.feature_disabled') }}

+
+ @else +
+{{-- {{ Form::text('slack_endpoint', old('slack_endpoint', $setting->slack_endpoint), array('class' => 'form-control','placeholder' => 'https://hooks.slack.com/services/XXXXXXXXXXXXXXXXXXXXX', 'id' => 'slack_endpoint')) }}--}} + @endif + {!! $errors->first('slack_endpoint', '') !!}
- +
+ + +
+
+ {{ Form::label('slack_botname', trans('admin/settings/general.slack_botname')) }} +
+
+ @if (config('app.lock_passwords')===true) +{{-- {{ Form::text('slack_botname', old('slack_botname', $setting->slack_botname), array('class' => 'form-control','disabled'=>'disabled','placeholder' => 'Snipe-Bot')) }}--}} +
+

{{ trans('general.feature_disabled') }}

+ + @else +
+ @endif + {!! $errors->first('slack_botname', '') !!} +
+
+ + -
-
+
-
-
-
-
diff --git a/resources/views/settings/slack.blade.php b/resources/views/settings/slack.blade.php index 9e0286c61b..25480a1c1e 100644 --- a/resources/views/settings/slack.blade.php +++ b/resources/views/settings/slack.blade.php @@ -19,25 +19,37 @@ padding-right: 40px; } + {{csrf_field()}} - - +
+
+
+
+

+ {{ trans('admin/settings/general.slack') }} +

+
+

{!! trans('admin/settings/general.slack_integration_help',array('slack_link' => 'https://my.slack.com/services/new/incoming-webhook')) !!} +

-{{-- @if (($setting->slack_channel=='') && ($setting->slack_endpoint==''))--}} -{{-- {{ trans('admin/settings/general.slack_integration_help_button') }}--}} -{{-- @endif--}} -{{--

--}} + @livewire('slack-settings-form') + + + +
+
+ + +@stop - @livewire('slack-settings-form') - From 3580bdae86cfcecd0a257d95be861fb3f709af11 Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Wed, 1 Feb 2023 11:44:35 -0800 Subject: [PATCH 039/127] Use object accessor instead of array accessor --- app/Models/CheckoutAcceptance.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Models/CheckoutAcceptance.php b/app/Models/CheckoutAcceptance.php index d68ac7ab7c..4cdc5b073b 100644 --- a/app/Models/CheckoutAcceptance.php +++ b/app/Models/CheckoutAcceptance.php @@ -21,7 +21,7 @@ class CheckoutAcceptance extends Model { // At this point the endpoint is the same for everything. // In the future this may want to be adapted for individual notifications. - return Setting::getSettings()['alert_email']; + return Setting::getSettings()->alert_email; } /** From a45ce468cc8472f98d81fb78983830b064465d52 Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Wed, 1 Feb 2023 11:44:56 -0800 Subject: [PATCH 040/127] Update return type for routing mail notifications --- app/Models/CheckoutAcceptance.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/app/Models/CheckoutAcceptance.php b/app/Models/CheckoutAcceptance.php index 4cdc5b073b..45fc6ec088 100644 --- a/app/Models/CheckoutAcceptance.php +++ b/app/Models/CheckoutAcceptance.php @@ -16,8 +16,12 @@ class CheckoutAcceptance extends Model 'declined_at' => 'datetime', ]; - // Get the mail recipient from the config - public function routeNotificationForMail(): string + /** + * Get the mail recipient from the config + * + * @return mixed|string|null + */ + public function routeNotificationForMail() { // At this point the endpoint is the same for everything. // In the future this may want to be adapted for individual notifications. From f95a904d90f0523ff70ebb8076fc492152c5f64f Mon Sep 17 00:00:00 2001 From: Godfrey M Date: Wed, 1 Feb 2023 12:08:13 -0800 Subject: [PATCH 041/127] adds integration button, working on its functionality --- .../Controllers/Api/SettingsController.php | 22 +++-------- app/Http/Controllers/SettingsController.php | 8 ++-- app/Http/Livewire/SlackSettingsForm.php | 19 +++------- app/Http/Requests/SlackSettingsRequest.php | 1 - .../livewire/slack-settings-form.blade.php | 37 ++++++++++++++++--- resources/views/settings/slack.blade.php | 5 --- 6 files changed, 47 insertions(+), 45 deletions(-) diff --git a/app/Http/Controllers/Api/SettingsController.php b/app/Http/Controllers/Api/SettingsController.php index 62380b2212..26d380353f 100644 --- a/app/Http/Controllers/Api/SettingsController.php +++ b/app/Http/Controllers/Api/SettingsController.php @@ -143,21 +143,11 @@ class SettingsController extends Controller } - public function slacktest(SlackSettingsRequest $request) + public function slacktest($slack_endpoint,$slack_channel,$slack_botname) { - - $validator = Validator::make($request->all(), [ - 'slack_endpoint' => 'url|required_with:slack_channel|starts_with:https://hooks.slack.com/|nullable', - 'slack_channel' => 'required_with:slack_endpoint|starts_with:#|nullable', - ]); - - if ($validator->fails()) { - return response()->json(['message' => 'Validation failed', 'errors' => $validator->errors()], 422); - } - // If validation passes, continue to the curl request $slack = new Client([ - 'base_url' => e($request->input('slack_endpoint')), + 'base_url' => e($slack_endpoint), 'defaults' => [ 'exceptions' => false, ], @@ -165,18 +155,18 @@ class SettingsController extends Controller $payload = json_encode( [ - 'channel' => e($request->input('slack_channel')), + 'channel' => e($slack_channel), 'text' => trans('general.slack_test_msg'), - 'username' => e($request->input('slack_botname')), + 'username' => e($slack_botname), 'icon_emoji' => ':heart:', ]); try { - $slack->post($request->input('slack_endpoint'), ['body' => $payload]); + $slack->post($slack_endpoint, ['body' => $payload]); return response()->json(['message' => 'Success'], 200); } catch (\Exception $e) { - return response()->json(['message' => 'Please check the channel name and webhook endpoint URL ('.e($request->input('slack_endpoint')).'). Slack responded with: '.$e->getMessage()], 400); + return response()->json(['message' => 'Please check the channel name and webhook endpoint URL ('.e($slack_endpoint).'). Slack responded with: '.$e->getMessage()], 400); } //} diff --git a/app/Http/Controllers/SettingsController.php b/app/Http/Controllers/SettingsController.php index 9a7c2cc7d5..6daaabdc9f 100755 --- a/app/Http/Controllers/SettingsController.php +++ b/app/Http/Controllers/SettingsController.php @@ -688,15 +688,15 @@ class SettingsController extends Controller * * @return View */ - public function postSlack(SlackSettingsRequest $request) + public function postSlack($slack_endpoint,$slack_channel,$slack_botname) { if (is_null($setting = Setting::getSettings())) { return redirect()->to('admin')->with('error', trans('admin/settings/message.update.error')); } - $setting->slack_endpoint = $request->input('slack_endpoint'); - $setting->slack_channel = $request->input('slack_channel'); - $setting->slack_botname = $request->input('slack_botname'); + $setting->slack_endpoint = $slack_endpoint; + $setting->slack_channel = $slack_channel; + $setting->slack_botname = $slack_botname; if ($setting->save()) { return redirect()->route('settings.index') diff --git a/app/Http/Livewire/SlackSettingsForm.php b/app/Http/Livewire/SlackSettingsForm.php index 2cb153734c..fbc54a0517 100644 --- a/app/Http/Livewire/SlackSettingsForm.php +++ b/app/Http/Livewire/SlackSettingsForm.php @@ -4,28 +4,16 @@ namespace App\Http\Livewire; use Livewire\Component; use App\Models\Setting; +use App\Http\Controllers\Api\SettingsController; class SlackSettingsForm extends Component { public $slack_endpoint; public $slack_channel; public $slack_botname; - public $successMessage; public Setting $setting; - protected $rules = [ - 'slack_endpoint' => 'url|required_with:slack_channel|starts_with:https://hooks.slack.com/|nullable', - 'slack_channel' => 'required_with:slack_endpoint|starts_with:#|nullable', - 'slack_botname' => 'string|nullable', - ]; - protected $messages = [ - 'slack_endpoint.required_with' => 'Slack endpoint is required', - 'slack_endpoint.starts_with' => 'Slack endpoint must start with https://hooks.slack.com', - - - ]; - public function mount(){ $this->setting = Setting::getSettings(); @@ -40,6 +28,11 @@ class SlackSettingsForm extends Component return view('livewire.slack-settings-form'); } + public function testSlack($slack_endpoint, $slack_channel, $slack_botname){ + SettingsController::testSlack($slack_endpoint,$slack_channel,$slack_botname); + + + } public function submit() { $this->validate([ diff --git a/app/Http/Requests/SlackSettingsRequest.php b/app/Http/Requests/SlackSettingsRequest.php index 1f44215198..e8f7d2f0ea 100644 --- a/app/Http/Requests/SlackSettingsRequest.php +++ b/app/Http/Requests/SlackSettingsRequest.php @@ -25,7 +25,6 @@ class SlackSettingsRequest extends Request 'slack_endpoint' => 'url|required_with:slack_channel|starts_with:"https://hooks.slack.com"|nullable', 'slack_channel' => 'required_with:slack_endpoint|starts_with:#|nullable', 'slack_botname' => 'string|nullable', - ]; } diff --git a/resources/views/livewire/slack-settings-form.blade.php b/resources/views/livewire/slack-settings-form.blade.php index b01ffa867f..6562f41b33 100644 --- a/resources/views/livewire/slack-settings-form.blade.php +++ b/resources/views/livewire/slack-settings-form.blade.php @@ -8,6 +8,7 @@ @endif
{{csrf_field()}} +
@@ -17,9 +18,9 @@ @if (config('app.lock_passwords')===true) {{-- {{ Form::text('slack_endpoint', old('slack_endpoint', $setting->slack_endpoint), array('class' => 'form-control','disabled'=>'disabled','placeholder' => 'https://hooks.slack.com/services/XXXXXXXXXXXXXXXXXXXXX', 'id' => 'slack_endpoint')) }}--}}

{{ trans('general.feature_disabled') }}

-
+
@else -
+
{{-- {{ Form::text('slack_endpoint', old('slack_endpoint', $setting->slack_endpoint), array('class' => 'form-control','placeholder' => 'https://hooks.slack.com/services/XXXXXXXXXXXXXXXXXXXXX', 'id' => 'slack_endpoint')) }}--}} @endif {!! $errors->first('slack_endpoint', '') !!} @@ -33,11 +34,11 @@
@if (config('app.lock_passwords')===true) -
+

{{ trans('general.feature_disabled') }}

@else -
+
@endif {!! $errors->first('slack_channel', '') !!}
@@ -51,16 +52,40 @@
@if (config('app.lock_passwords')===true) {{-- {{ Form::text('slack_botname', old('slack_botname', $setting->slack_botname), array('class' => 'form-control','disabled'=>'disabled','placeholder' => 'Snipe-Bot')) }}--}} -
+

{{ trans('general.feature_disabled') }}

@else -
+
@endif {!! $errors->first('slack_botname', '') !!}
+ + @if($slack_endpoint != null && $slack_channel != null && $slack_botname != null) +
+
+ {{ Form::label('test_slack', 'Test Slack') }} +
+
+ +
+ @if($response == 'success') + message here + @endif + @if($response == 'error') + message here + @endif +
+
+ @endif +{{--
--}} +{{-- --}} +{{-- --}} +{{-- --}} +{{--
--}} +