From e457b2e98d9b34d335c6d79d0c606c8a8f50d9b5 Mon Sep 17 00:00:00 2001 From: Phan Nguyen Date: Mon, 17 Oct 2022 13:10:09 +0700 Subject: [PATCH 01/16] Correct assignedusers relation setting --- app/Models/License.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Models/License.php b/app/Models/License.php index d0e6f5c969..d74d69546a 100755 --- a/app/Models/License.php +++ b/app/Models/License.php @@ -357,7 +357,7 @@ class License extends Depreciable */ public function assignedusers() { - return $this->belongsToMany(\App\Models\User::class, 'license_seats', 'assigned_to', 'license_id'); + return $this->belongsToMany(\App\Models\User::class, 'license_seats', 'license_id', 'assigned_to'); } /** From 45636b81148c5bf1d3d62991ea6747d4ab6145e7 Mon Sep 17 00:00:00 2001 From: Godfrey M Date: Tue, 15 Nov 2022 15:42:57 -0800 Subject: [PATCH 02/16] adds should_autoassign boolean to users table --- .../Commands/CheckoutLicenseToAllUsers.php | 2 +- .../Controllers/Users/UsersController.php | 2 ++ ..._should_autoassign_bool_to_users_table.php | 32 +++++++++++++++++++ resources/lang/en/admin/users/general.php | 2 ++ resources/views/users/edit.blade.php | 13 ++++++++ 5 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 database/migrations/2022_11_15_232525_adds_should_autoassign_bool_to_users_table.php diff --git a/app/Console/Commands/CheckoutLicenseToAllUsers.php b/app/Console/Commands/CheckoutLicenseToAllUsers.php index fab2b318c6..e29b8991b6 100644 --- a/app/Console/Commands/CheckoutLicenseToAllUsers.php +++ b/app/Console/Commands/CheckoutLicenseToAllUsers.php @@ -56,7 +56,7 @@ class CheckoutLicenseToAllUsers extends Command return false; } - $users = User::whereNull('deleted_at')->with('licenses')->get(); + $users = User::whereNull('deleted_at')->where('should_autoassign', '==', 1)->with('licenses')->get(); if ($users->count() > $license->getAvailSeatsCountAttribute()) { $this->info('You do not have enough free seats to complete this task, so we will check out as many as we can. '); diff --git a/app/Http/Controllers/Users/UsersController.php b/app/Http/Controllers/Users/UsersController.php index 52d423036f..b863fb966b 100755 --- a/app/Http/Controllers/Users/UsersController.php +++ b/app/Http/Controllers/Users/UsersController.php @@ -121,6 +121,7 @@ class UsersController extends Controller $user->created_by = Auth::user()->id; $user->start_date = $request->input('start_date', null); $user->end_date = $request->input('end_date', null); + $user->should_autoassign= $request->input('should_autoassign', 0); // Strip out the superuser permission if the user isn't a superadmin $permissions_array = $request->input('permission'); @@ -274,6 +275,7 @@ class UsersController extends Controller $user->website = $request->input('website', null); $user->start_date = $request->input('start_date', null); $user->end_date = $request->input('end_date', null); + $user->should_autoassign = $request->input('should_autoassign', 0); // Update the location of any assets checked out to this user Asset::where('assigned_type', User::class) diff --git a/database/migrations/2022_11_15_232525_adds_should_autoassign_bool_to_users_table.php b/database/migrations/2022_11_15_232525_adds_should_autoassign_bool_to_users_table.php new file mode 100644 index 0000000000..6f6f308e44 --- /dev/null +++ b/database/migrations/2022_11_15_232525_adds_should_autoassign_bool_to_users_table.php @@ -0,0 +1,32 @@ +boolean('should_autoassign')->nullable(false)->default(0); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('users', function (Blueprint $table) { + $table->dropColumn('should_autoassign'); + }); + } +} diff --git a/resources/lang/en/admin/users/general.php b/resources/lang/en/admin/users/general.php index daa568e8bf..2ae8709251 100644 --- a/resources/lang/en/admin/users/general.php +++ b/resources/lang/en/admin/users/general.php @@ -19,6 +19,8 @@ return [ 'print_assigned' => 'Print All Assigned', 'email_assigned' => 'Email List of All Assigned', 'user_notified' => 'User has been emailed a list of their currently assigned items.', + 'auto_assign_label' => 'User should skipped during auto assignment commands', + 'auto_assign_help' => 'Skip this user in auto assignment of licenses', 'software_user' => 'Software Checked out to :name', 'send_email_help' => 'You must provide an email address for this user to send them credentials. Emailing credentials can only be done on user creation. Passwords are stored in a one-way hash and cannot be retrieved once saved.', 'view_user' => 'View User :name', diff --git a/resources/views/users/edit.blade.php b/resources/views/users/edit.blade.php index 7947d65a68..a689ab8983 100755 --- a/resources/views/users/edit.blade.php +++ b/resources/views/users/edit.blade.php @@ -376,6 +376,19 @@ + +
+
+ +

{{ trans('admin/users/general.auto_assign_help') }} +

+
+
+ @include ('partials.forms.edit.location-select', ['translated_name' => trans('general.location'), 'fieldname' => 'location_id']) From 90828e3a873f548d7bbb16f065c484204303178c Mon Sep 17 00:00:00 2001 From: Godfrey M Date: Tue, 15 Nov 2022 15:51:52 -0800 Subject: [PATCH 03/16] fixes variable name --- app/Console/Commands/CheckoutLicenseToAllUsers.php | 4 ++-- resources/lang/en/admin/users/general.php | 2 +- resources/views/users/edit.blade.php | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/Console/Commands/CheckoutLicenseToAllUsers.php b/app/Console/Commands/CheckoutLicenseToAllUsers.php index e29b8991b6..003c32c738 100644 --- a/app/Console/Commands/CheckoutLicenseToAllUsers.php +++ b/app/Console/Commands/CheckoutLicenseToAllUsers.php @@ -56,8 +56,8 @@ class CheckoutLicenseToAllUsers extends Command return false; } - $users = User::whereNull('deleted_at')->where('should_autoassign', '==', 1)->with('licenses')->get(); - + $users = User::whereNull('deleted_at')->where('should_autoassign', '==', 0)->with('licenses')->get(); + dd($users); if ($users->count() > $license->getAvailSeatsCountAttribute()) { $this->info('You do not have enough free seats to complete this task, so we will check out as many as we can. '); } diff --git a/resources/lang/en/admin/users/general.php b/resources/lang/en/admin/users/general.php index 2ae8709251..71f56c7a15 100644 --- a/resources/lang/en/admin/users/general.php +++ b/resources/lang/en/admin/users/general.php @@ -19,7 +19,7 @@ return [ 'print_assigned' => 'Print All Assigned', 'email_assigned' => 'Email List of All Assigned', 'user_notified' => 'User has been emailed a list of their currently assigned items.', - 'auto_assign_label' => 'User should skipped during auto assignment commands', + 'auto_assign_label' => 'User should be skipped during auto assignment commands', 'auto_assign_help' => 'Skip this user in auto assignment of licenses', 'software_user' => 'Software Checked out to :name', 'send_email_help' => 'You must provide an email address for this user to send them credentials. Emailing credentials can only be done on user creation. Passwords are stored in a one-way hash and cannot be retrieved once saved.', diff --git a/resources/views/users/edit.blade.php b/resources/views/users/edit.blade.php index a689ab8983..f0bbc989f6 100755 --- a/resources/views/users/edit.blade.php +++ b/resources/views/users/edit.blade.php @@ -380,7 +380,7 @@
From 8a0517fb5d83ef055b1a90bdb07903265d8a4011 Mon Sep 17 00:00:00 2001 From: Godfrey M Date: Tue, 15 Nov 2022 15:59:47 -0800 Subject: [PATCH 04/16] removes data dump --- app/Console/Commands/CheckoutLicenseToAllUsers.php | 2 +- resources/views/users/edit.blade.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/Console/Commands/CheckoutLicenseToAllUsers.php b/app/Console/Commands/CheckoutLicenseToAllUsers.php index 003c32c738..44ec72e13c 100644 --- a/app/Console/Commands/CheckoutLicenseToAllUsers.php +++ b/app/Console/Commands/CheckoutLicenseToAllUsers.php @@ -57,7 +57,7 @@ class CheckoutLicenseToAllUsers extends Command } $users = User::whereNull('deleted_at')->where('should_autoassign', '==', 0)->with('licenses')->get(); - dd($users); + if ($users->count() > $license->getAvailSeatsCountAttribute()) { $this->info('You do not have enough free seats to complete this task, so we will check out as many as we can. '); } diff --git a/resources/views/users/edit.blade.php b/resources/views/users/edit.blade.php index f0bbc989f6..7126428607 100755 --- a/resources/views/users/edit.blade.php +++ b/resources/views/users/edit.blade.php @@ -380,7 +380,7 @@
From 6fbb484dfd5362c8300d2710fe2a3815a63d87ed Mon Sep 17 00:00:00 2001 From: Godfrey M Date: Wed, 18 Jan 2023 08:43:03 -0800 Subject: [PATCH 05/16] renames db column for auto_assign boolean, rewords trans string, default value of 1 now --- ..._11_15_232525_adds_should_autoassign_bool_to_users_table.php | 2 +- resources/lang/en/admin/users/general.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/database/migrations/2022_11_15_232525_adds_should_autoassign_bool_to_users_table.php b/database/migrations/2022_11_15_232525_adds_should_autoassign_bool_to_users_table.php index 6f6f308e44..854feebfea 100644 --- a/database/migrations/2022_11_15_232525_adds_should_autoassign_bool_to_users_table.php +++ b/database/migrations/2022_11_15_232525_adds_should_autoassign_bool_to_users_table.php @@ -14,7 +14,7 @@ class AddsShouldAutoassignBoolToUsersTable extends Migration public function up() { Schema::table('users', function (Blueprint $table) { - $table->boolean('should_autoassign')->nullable(false)->default(0); + $table->boolean('autoassign_licenses')->nullable(false)->default(1); }); } diff --git a/resources/lang/en/admin/users/general.php b/resources/lang/en/admin/users/general.php index 71f56c7a15..58c54a7d27 100644 --- a/resources/lang/en/admin/users/general.php +++ b/resources/lang/en/admin/users/general.php @@ -19,7 +19,7 @@ return [ 'print_assigned' => 'Print All Assigned', 'email_assigned' => 'Email List of All Assigned', 'user_notified' => 'User has been emailed a list of their currently assigned items.', - 'auto_assign_label' => 'User should be skipped during auto assignment commands', + 'auto_assign_label' => 'Include this user when auto-assigning eligible licenses', 'auto_assign_help' => 'Skip this user in auto assignment of licenses', 'software_user' => 'Software Checked out to :name', 'send_email_help' => 'You must provide an email address for this user to send them credentials. Emailing credentials can only be done on user creation. Passwords are stored in a one-way hash and cannot be retrieved once saved.', From 7ce230fadcb47a4d1b5f39184bacdb18125059aa Mon Sep 17 00:00:00 2001 From: Godfrey M Date: Wed, 18 Jan 2023 08:57:59 -0800 Subject: [PATCH 06/16] missed a few renames --- app/Console/Commands/CheckoutLicenseToAllUsers.php | 2 +- app/Http/Controllers/Users/UsersController.php | 4 ++-- ...1_15_232525_adds_should_autoassign_bool_to_users_table.php | 2 +- resources/views/users/edit.blade.php | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/app/Console/Commands/CheckoutLicenseToAllUsers.php b/app/Console/Commands/CheckoutLicenseToAllUsers.php index 44ec72e13c..1ba57895c2 100644 --- a/app/Console/Commands/CheckoutLicenseToAllUsers.php +++ b/app/Console/Commands/CheckoutLicenseToAllUsers.php @@ -56,7 +56,7 @@ class CheckoutLicenseToAllUsers extends Command return false; } - $users = User::whereNull('deleted_at')->where('should_autoassign', '==', 0)->with('licenses')->get(); + $users = User::whereNull('deleted_at')->where('autoassign_licenses', '==', 1)->with('licenses')->get(); if ($users->count() > $license->getAvailSeatsCountAttribute()) { $this->info('You do not have enough free seats to complete this task, so we will check out as many as we can. '); diff --git a/app/Http/Controllers/Users/UsersController.php b/app/Http/Controllers/Users/UsersController.php index b863fb966b..eecce0aea6 100755 --- a/app/Http/Controllers/Users/UsersController.php +++ b/app/Http/Controllers/Users/UsersController.php @@ -121,7 +121,7 @@ class UsersController extends Controller $user->created_by = Auth::user()->id; $user->start_date = $request->input('start_date', null); $user->end_date = $request->input('end_date', null); - $user->should_autoassign= $request->input('should_autoassign', 0); + $user->autoassign_licenses= $request->input('autoassign_licenses', 1); // Strip out the superuser permission if the user isn't a superadmin $permissions_array = $request->input('permission'); @@ -275,7 +275,7 @@ class UsersController extends Controller $user->website = $request->input('website', null); $user->start_date = $request->input('start_date', null); $user->end_date = $request->input('end_date', null); - $user->should_autoassign = $request->input('should_autoassign', 0); + $user->autoassign_licenses = $request->input('autoassign_licenses', 1); // Update the location of any assets checked out to this user Asset::where('assigned_type', User::class) diff --git a/database/migrations/2022_11_15_232525_adds_should_autoassign_bool_to_users_table.php b/database/migrations/2022_11_15_232525_adds_should_autoassign_bool_to_users_table.php index 854feebfea..b728e1f22b 100644 --- a/database/migrations/2022_11_15_232525_adds_should_autoassign_bool_to_users_table.php +++ b/database/migrations/2022_11_15_232525_adds_should_autoassign_bool_to_users_table.php @@ -26,7 +26,7 @@ class AddsShouldAutoassignBoolToUsersTable extends Migration public function down() { Schema::table('users', function (Blueprint $table) { - $table->dropColumn('should_autoassign'); + $table->dropColumn('autoassign_licenses'); }); } } diff --git a/resources/views/users/edit.blade.php b/resources/views/users/edit.blade.php index 7126428607..e4666a4d0c 100755 --- a/resources/views/users/edit.blade.php +++ b/resources/views/users/edit.blade.php @@ -379,8 +379,8 @@
-