From a5c6ddb8ac61baa2869a236bb7656351d9ef2e62 Mon Sep 17 00:00:00 2001 From: snipe Date: Mon, 5 Mar 2018 21:27:17 -0800 Subject: [PATCH 01/11] Change gate for updating assets via the API to edit --- app/Http/Controllers/Api/AssetsController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Http/Controllers/Api/AssetsController.php b/app/Http/Controllers/Api/AssetsController.php index 85019ad90..8abfab88a 100644 --- a/app/Http/Controllers/Api/AssetsController.php +++ b/app/Http/Controllers/Api/AssetsController.php @@ -420,7 +420,7 @@ class AssetsController extends Controller */ public function update(Request $request, $id) { - $this->authorize('create', Asset::class); + $this->authorize('edit', Asset::class); if ($asset = Asset::find($id)) { ($request->has('model_id')) ? From d05dfb18a7ed5f58e48c57f2cc0470242f4b9cc2 Mon Sep 17 00:00:00 2001 From: snipe Date: Mon, 5 Mar 2018 21:39:05 -0800 Subject: [PATCH 02/11] Fixed #5150 - added lastname first initial as username format --- app/Models/User.php | 5 ++++- resources/lang/en/general.php | 1 + resources/macros/macros.php | 1 + tests/unit/UserTest.php | 8 ++++++++ 4 files changed, 14 insertions(+), 1 deletion(-) diff --git a/app/Models/User.php b/app/Models/User.php index 92f3caf9a..d26d5d940 100755 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -346,7 +346,10 @@ class User extends SnipeModel implements AuthenticatableContract, CanResetPasswo $username = str_slug(substr($first_name, 0, 1).$last_name); if ($format=='firstname.lastname') { - $username = str_slug($first_name).'.'.str_slug($last_name); + $username = str_slug($first_name) . '.' . str_slug($last_name); + + } elseif ($format=='lastnamefirstinitial') { + $username = str_slug($last_name.substr($first_name, 0, 1)); } elseif ($format=='firstname_lastname') { $username = str_slug($first_name).'_'.str_slug($last_name); diff --git a/resources/lang/en/general.php b/resources/lang/en/general.php index c33c33381..abd1fe4e5 100644 --- a/resources/lang/en/general.php +++ b/resources/lang/en/general.php @@ -81,6 +81,7 @@ 'filastname_format' => 'First Initial Last Name (jsmith@example.com)', 'firstname_lastname_format' => 'First Name Last Name (jane.smith@example.com)', 'firstname_lastname_underscore_format' => 'First Name Last Name (jane_smith@example.com)', + 'lastnamefirstinitial_format' => 'Last Name First Initial (smithj@example.com)', 'first' => 'First', 'first_name' => 'First Name', 'first_name_format' => 'First Name (jane@example.com)', diff --git a/resources/macros/macros.php b/resources/macros/macros.php index 6446f5926..9539034f4 100644 --- a/resources/macros/macros.php +++ b/resources/macros/macros.php @@ -456,6 +456,7 @@ Form::macro('username_format', function ($name = "username_format", $selected = 'firstname.lastname' => trans('general.firstname_lastname_format'), 'firstname' => trans('general.first_name_format'), 'filastname' => trans('general.filastname_format'), + 'lastnamefirstinitial' => trans('general.lastnamefirstinitial_format'), 'firstname_lastname' => trans('general.firstname_lastname_underscore_format'), ); diff --git a/tests/unit/UserTest.php b/tests/unit/UserTest.php index 8bcd31097..c953beee0 100644 --- a/tests/unit/UserTest.php +++ b/tests/unit/UserTest.php @@ -54,6 +54,14 @@ class UserTest extends BaseTest $this->assertEquals($expected_username, $user['username']); } + public function testLastNameFirstInitial() + { + $fullname = "Natalia Allanovna Romanova-O'Shostakova"; + $expected_username = 'allanovna-romanova-oshostakovan'; + $user = User::generateFormattedNameFromFullName('lastnamefirstinitial', $fullname); + $this->assertEquals($expected_username, $user['username']); + } + public function testFirstInitialLastName() { From 1e22b8e5679e355e8c2b4e20a4bc98472b02a31f Mon Sep 17 00:00:00 2001 From: snipe Date: Mon, 5 Mar 2018 22:04:16 -0800 Subject: [PATCH 03/11] Fixed #5138 - added default_label flag to status labels --- app/Helpers/Helper.php | 2 +- .../Api/StatuslabelsController.php | 2 +- .../Controllers/StatuslabelsController.php | 3 +- .../Transformers/StatuslabelsTransformer.php | 1 + ...54937_add_default_flag_on_statuslabels.php | 32 +++++++++++++++++++ .../lang/en/admin/statuslabels/table.php | 2 ++ resources/views/statuslabels/edit.blade.php | 9 ++++++ resources/views/statuslabels/index.blade.php | 1 + 8 files changed, 49 insertions(+), 3 deletions(-) create mode 100644 database/migrations/2018_03_06_054937_add_default_flag_on_statuslabels.php diff --git a/app/Helpers/Helper.php b/app/Helpers/Helper.php index e92f25a2c..6b0f0f98a 100644 --- a/app/Helpers/Helper.php +++ b/app/Helpers/Helper.php @@ -235,7 +235,7 @@ class Helper */ public static function statusLabelList() { - $statuslabel_list = array('' => trans('general.select_statuslabel')) + Statuslabel::orderBy('deployable', 'desc') + $statuslabel_list = array('' => trans('general.select_statuslabel')) + Statuslabel::orderBy('default_label', 'desc')->orderBy('name','asc')->orderBy('deployable','desc') ->pluck('name', 'id')->toArray(); return $statuslabel_list; } diff --git a/app/Http/Controllers/Api/StatuslabelsController.php b/app/Http/Controllers/Api/StatuslabelsController.php index a3c698fa7..ed6b9e21d 100644 --- a/app/Http/Controllers/Api/StatuslabelsController.php +++ b/app/Http/Controllers/Api/StatuslabelsController.php @@ -22,7 +22,7 @@ class StatuslabelsController extends Controller public function index(Request $request) { $this->authorize('view', Statuslabel::class); - $allowed_columns = ['id','name','created_at', 'assets_count','color']; + $allowed_columns = ['id','name','created_at', 'assets_count','color','default_label']; $statuslabels = Statuslabel::withCount('assets'); diff --git a/app/Http/Controllers/StatuslabelsController.php b/app/Http/Controllers/StatuslabelsController.php index 1a9b772dd..a264dd77f 100755 --- a/app/Http/Controllers/StatuslabelsController.php +++ b/app/Http/Controllers/StatuslabelsController.php @@ -93,9 +93,9 @@ class StatuslabelsController extends Controller $statusLabel->archived = $statusType['archived']; $statusLabel->color = Input::get('color'); $statusLabel->show_in_nav = Input::get('show_in_nav', 0); + $statusLabel->default_label = Input::get('default_label', 0); - // Was the asset created? if ($statusLabel->save()) { // Redirect to the new Statuslabel page return redirect()->route('statuslabels.index')->with('success', trans('admin/statuslabels/message.create.success')); @@ -185,6 +185,7 @@ class StatuslabelsController extends Controller $statuslabel->archived = $statustype['archived']; $statuslabel->color = Input::get('color'); $statuslabel->show_in_nav = Input::get('show_in_nav', 0); + $statuslabel->default_label = Input::get('default_label', 0); // Was the asset created? diff --git a/app/Http/Transformers/StatuslabelsTransformer.php b/app/Http/Transformers/StatuslabelsTransformer.php index e7b356deb..f1a546053 100644 --- a/app/Http/Transformers/StatuslabelsTransformer.php +++ b/app/Http/Transformers/StatuslabelsTransformer.php @@ -26,6 +26,7 @@ class StatuslabelsTransformer 'type' => $statuslabel->getStatuslabelType(), 'color' => ($statuslabel->color) ? e($statuslabel->color) : null, 'show_in_nav' => ($statuslabel->show_in_nav=='1') ? true : false, + 'default_label' => ($statuslabel->default_label =='1') ? true : false, 'assets_count' => (int) $statuslabel->assets_count, 'notes' => e($statuslabel->notes), 'created_at' => Helper::getFormattedDateObject($statuslabel->created_at, 'datetime'), diff --git a/database/migrations/2018_03_06_054937_add_default_flag_on_statuslabels.php b/database/migrations/2018_03_06_054937_add_default_flag_on_statuslabels.php new file mode 100644 index 000000000..54a62bd77 --- /dev/null +++ b/database/migrations/2018_03_06_054937_add_default_flag_on_statuslabels.php @@ -0,0 +1,32 @@ +boolean('default_label')->default(0); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('status_labels', function (Blueprint $table) { + $table->dropColumn('default_label'); + }); + } +} diff --git a/resources/lang/en/admin/statuslabels/table.php b/resources/lang/en/admin/statuslabels/table.php index b9b5b7ec4..27befb5ef 100644 --- a/resources/lang/en/admin/statuslabels/table.php +++ b/resources/lang/en/admin/statuslabels/table.php @@ -5,6 +5,8 @@ return array( 'archived' => 'Archived', 'create' => 'Create Status Label', 'color' => 'Chart Color', + 'default_label' => 'Default Label', + 'default_label_help' => 'This is used to ensure your most commonly used status labels appear at the top of the select box when creating/editing assets.', 'deployable' => 'Deployable', 'info' => 'Status labels are used to describe the various states your assets could be in. They may be out for repair, lost/stolen, etc. You can create new status labels for deployable, pending and archived assets.', 'name' => 'Status Name', diff --git a/resources/views/statuslabels/edit.blade.php b/resources/views/statuslabels/edit.blade.php index 158a43a85..67774a409 100755 --- a/resources/views/statuslabels/edit.blade.php +++ b/resources/views/statuslabels/edit.blade.php @@ -53,6 +53,15 @@ + +
+ + +

{{ trans('admin/statuslabels/table.default_label_help') }}

+
+ @stop @section('moar_scripts') diff --git a/resources/views/statuslabels/index.blade.php b/resources/views/statuslabels/index.blade.php index edb64ceeb..d10976b39 100755 --- a/resources/views/statuslabels/index.blade.php +++ b/resources/views/statuslabels/index.blade.php @@ -48,6 +48,7 @@ {{ trans('general.assets') }} {{ trans('admin/statuslabels/table.color') }} {{ trans('admin/statuslabels/table.show_in_nav') }} + {{ trans('admin/statuslabels/table.default_label') }} {{ trans('table.actions') }} From 9a25cb3ee798bf86bb192983f94043940bb8db8d Mon Sep 17 00:00:00 2001 From: snipe Date: Mon, 5 Mar 2018 22:16:36 -0800 Subject: [PATCH 04/11] Set default labels in seeders --- database/factories/StatusLabelFactory.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/database/factories/StatusLabelFactory.php b/database/factories/StatusLabelFactory.php index 60b0bbc50..bf7ed8bc6 100644 --- a/database/factories/StatusLabelFactory.php +++ b/database/factories/StatusLabelFactory.php @@ -18,13 +18,15 @@ $factory->define(Statuslabel::class, function (Faker\Generator $faker) { $factory->state(Statuslabel::class, 'rtd', function (Faker\Generator $faker) { return [ 'notes' => $faker->sentence, - 'deployable' => 1 + 'deployable' => 1, + 'default_label' => 1, ]; }); $factory->state(Statuslabel::class, 'pending', function (Faker\Generator $faker) { return [ 'notes' => $faker->sentence, 'pending' => 1, + 'default_label' => 0, ]; }); @@ -32,29 +34,34 @@ $factory->state(Statuslabel::class, 'archived', function (Faker\Generator $faker return [ 'notes' => 'These assets are permanently undeployable', 'archived' => 1, + 'default_label' => 0, ]; }); $factory->state(Statuslabel::class, 'out_for_diagnostics', function (Faker\Generator $faker) { return [ 'name' => 'Out for Diagnostics', + 'default_label' => 0, ]; }); $factory->state(Statuslabel::class, 'out_for_repair', function (Faker\Generator $faker) { return [ 'name' => 'Out for Repair', + 'default_label' => 0, ]; }); $factory->state(Statuslabel::class, 'broken', function (Faker\Generator $faker) { return [ 'name' => 'Broken - Not Fixable', + 'default_label' => 0, ]; }); $factory->state(Statuslabel::class, 'lost', function (Faker\Generator $faker) { return [ 'name' => 'Lost/Stolen', + 'default_label' => 0, ]; }); From 04d2542b817115ec6e8bf06f305eef6df1c52209 Mon Sep 17 00:00:00 2001 From: snipe Date: Mon, 5 Mar 2018 22:42:40 -0800 Subject: [PATCH 05/11] Fixed #5078 - check for object or array as location in LDAP sync --- app/Console/Commands/LdapSync.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/app/Console/Commands/LdapSync.php b/app/Console/Commands/LdapSync.php index e0e001a99..7b7571bf4 100755 --- a/app/Console/Commands/LdapSync.php +++ b/app/Console/Commands/LdapSync.php @@ -190,7 +190,13 @@ class LdapSync extends Command if ($item['ldap_location_override'] == true) { $user->location_id = $item['location_id']; } elseif ((isset($location)) && (!empty($location))) { - $user->location_id = e($location->id); + + if (is_array($location)) { + $user->location_id = $location['id']; + } elseif (is_object($location)) { + $user->location_id = $location->id; + } + } $user->notes = 'Imported from LDAP'; From d60c9800c2b4e350a82993983670d1a6dfb3964a Mon Sep 17 00:00:00 2001 From: snipe Date: Mon, 5 Mar 2018 22:44:05 -0800 Subject: [PATCH 06/11] Check that the id key exists to prevent any weird edge cases for location --- app/Console/Commands/LdapSync.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Console/Commands/LdapSync.php b/app/Console/Commands/LdapSync.php index 7b7571bf4..4ec7509d1 100755 --- a/app/Console/Commands/LdapSync.php +++ b/app/Console/Commands/LdapSync.php @@ -191,7 +191,7 @@ class LdapSync extends Command $user->location_id = $item['location_id']; } elseif ((isset($location)) && (!empty($location))) { - if (is_array($location)) { + if ((is_array($location)) && (array_key_exists('id', $location))) { $user->location_id = $location['id']; } elseif (is_object($location)) { $user->location_id = $location->id; From 17e01549950e81be5d517eef045aa9ac9294b418 Mon Sep 17 00:00:00 2001 From: snipe Date: Tue, 6 Mar 2018 13:11:45 -0800 Subject: [PATCH 07/11] Fixed #5160 - make field_values readable via custom fields API --- app/Http/Transformers/CustomFieldsTransformer.php | 1 + 1 file changed, 1 insertion(+) diff --git a/app/Http/Transformers/CustomFieldsTransformer.php b/app/Http/Transformers/CustomFieldsTransformer.php index 6e6a50a7e..5c6e5d4fc 100644 --- a/app/Http/Transformers/CustomFieldsTransformer.php +++ b/app/Http/Transformers/CustomFieldsTransformer.php @@ -26,6 +26,7 @@ class CustomFieldsTransformer 'name' => e($field->name), 'db_column_name' => e($field->db_column_name()), 'format' => e($field->format), + 'field_values' => ($field->field_values) ? e($field->field_values) : null, 'required' => $field->pivot ? $field->pivot->required : false, 'created_at' => Helper::getFormattedDateObject($field->created_at, 'datetime'), 'updated_at' => Helper::getFormattedDateObject($field->updated_at, 'datetime'), From c4db8d37c288bcec5deb315d3d9b0b19e9b8113b Mon Sep 17 00:00:00 2001 From: snipe Date: Wed, 7 Mar 2018 13:37:37 -0800 Subject: [PATCH 08/11] Fixed #5168 - users without superadmin could not see custom fields UI even if granted --- app/Providers/AuthServiceProvider.php | 1 + resources/views/layouts/default.blade.php | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/app/Providers/AuthServiceProvider.php b/app/Providers/AuthServiceProvider.php index 678386423..b0f17f2ec 100644 --- a/app/Providers/AuthServiceProvider.php +++ b/app/Providers/AuthServiceProvider.php @@ -140,6 +140,7 @@ class AuthServiceProvider extends ServiceProvider || $user->can('view', \App\Models\Company::class) || $user->can('view', \App\Models\Manufacturer::class) || $user->can('view', \App\Models\Company::class) + || $user->can('view', \App\Models\CustomField::class) || $user->can('view', \App\Models\Depreciation::class); }); } diff --git a/resources/views/layouts/default.blade.php b/resources/views/layouts/default.blade.php index 054c3744f..da446d9e2 100644 --- a/resources/views/layouts/default.blade.php +++ b/resources/views/layouts/default.blade.php @@ -524,8 +524,8 @@
    - @can('view', \App\Models\Customfield::class) -
  • + @can('view', \App\Models\CustomField::class) +
  • {{ trans('admin/custom_fields/general.custom_fields') }} From 95d935d917489c0f20fb94ce3d5abba385c0e882 Mon Sep 17 00:00:00 2001 From: snipe Date: Wed, 7 Mar 2018 17:39:13 -0800 Subject: [PATCH 09/11] Added warning to not edit config files manually --- config/app.php | 9 +++++++++ config/auth.php | 9 +++++++++ config/broadcasting.php | 10 ++++++++++ config/cache.php | 10 ++++++++++ config/compile.php | 10 ++++++++++ config/database.php | 9 +++++++++ config/filesystems.php | 9 +++++++++ config/image.php | 9 +++++++++ config/laravel-backup.php | 9 +++++++++ config/mail.php | 9 +++++++++ config/permissions.php | 7 +++++++ config/services.php | 9 +++++++++ config/session.php | 10 ++++++++++ config/trustedproxy.php | 9 +++++++++ 14 files changed, 128 insertions(+) diff --git a/config/app.php b/config/app.php index f30388b59..25b7f960b 100755 --- a/config/app.php +++ b/config/app.php @@ -1,5 +1,14 @@ [ diff --git a/config/mail.php b/config/mail.php index eab4ad4d2..9c2aac439 100755 --- a/config/mail.php +++ b/config/mail.php @@ -1,5 +1,14 @@ array( diff --git a/config/services.php b/config/services.php index 83b8cca3e..aaccc92c2 100644 --- a/config/services.php +++ b/config/services.php @@ -1,5 +1,14 @@ Date: Wed, 7 Mar 2018 18:22:49 -0800 Subject: [PATCH 10/11] Fixed asset model permission not granted for edit --- .../Controllers/AssetModelsController.php | 4 +-- app/Policies/DepreciationPolicy.php | 13 ++++++++++ app/Providers/AuthServiceProvider.php | 26 ++++++++++--------- 3 files changed, 29 insertions(+), 14 deletions(-) create mode 100644 app/Policies/DepreciationPolicy.php diff --git a/app/Http/Controllers/AssetModelsController.php b/app/Http/Controllers/AssetModelsController.php index 8cd9a450d..389f1edd9 100755 --- a/app/Http/Controllers/AssetModelsController.php +++ b/app/Http/Controllers/AssetModelsController.php @@ -166,7 +166,7 @@ class AssetModelsController extends Controller */ public function edit($modelId = null) { - $this->authorize('edit', AssetModel::class); + $this->authorize('update', AssetModel::class); if ($item = AssetModel::find($modelId)) { $category_type = 'asset'; $view = View::make('models/edit', compact('item','category_type')); @@ -190,7 +190,7 @@ class AssetModelsController extends Controller */ public function update(ImageUploadRequest $request, $modelId = null) { - $this->authorize('edit', AssetModel::class); + $this->authorize('update', AssetModel::class); // Check if the model exists if (is_null($model = AssetModel::find($modelId))) { // Redirect to the models management page diff --git a/app/Policies/DepreciationPolicy.php b/app/Policies/DepreciationPolicy.php new file mode 100644 index 000000000..cc889b894 --- /dev/null +++ b/app/Policies/DepreciationPolicy.php @@ -0,0 +1,13 @@ + ConsumablePolicy::class, CustomField::class => CustomFieldPolicy::class, Department::class => DepartmentPolicy::class, + Depreciation::class => DepreciationPolicy::class, License::class => LicensePolicy::class, Location::class => LocationPolicy::class, Statuslabel::class => StatuslabelPolicy::class, @@ -130,18 +133,17 @@ class AuthServiceProvider extends ServiceProvider }); Gate::define('backend.interact', function ($user) { - return $user->can('view', \App\Models\Statuslabel::class) - || $user->can('view', \App\Models\AssetModel::class) - || $user->can('view', \App\Models\Category::class) - || $user->can('view', \App\Models\Manufacturer::class) - || $user->can('view', \App\Models\Supplier::class) - || $user->can('view', \App\Models\Department::class) - || $user->can('view', \App\Models\Location::class) - || $user->can('view', \App\Models\Company::class) - || $user->can('view', \App\Models\Manufacturer::class) - || $user->can('view', \App\Models\Company::class) - || $user->can('view', \App\Models\CustomField::class) - || $user->can('view', \App\Models\Depreciation::class); + return $user->can('view', Statuslabel::class) + || $user->can('view', AssetModel::class) + || $user->can('view', Category::class) + || $user->can('view', Manufacturer::class) + || $user->can('view', Supplier::class) + || $user->can('view', Department::class) + || $user->can('view', Location::class) + || $user->can('view', Company::class) + || $user->can('view', Manufacturer::class) + || $user->can('view', CustomField::class) + || $user->can('view', Depreciation::class); }); } } From 238a075c6ae22469924284f46673852878dbafd8 Mon Sep 17 00:00:00 2001 From: snipe Date: Wed, 7 Mar 2018 18:24:09 -0800 Subject: [PATCH 11/11] Bumped hash --- config/version.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/config/version.php b/config/version.php index 53409aba8..10fedec6c 100644 --- a/config/version.php +++ b/config/version.php @@ -1,10 +1,10 @@ 'v4.1.14', - 'full_app_version' => 'v4.1.14 - build 3416-g14af95001', - 'build_version' => '3416', + 'full_app_version' => 'v4.1.14 - build 3446-g90bff709a', + 'build_version' => '3446', 'prerelease_version' => '', - 'hash_version' => 'g14af95001', - 'full_hash' => 'v4.1.14-25-g14af95001', + 'hash_version' => 'g90bff709a', + 'full_hash' => 'v4.1.14-55-g90bff709a', 'branch' => 'develop', ); \ No newline at end of file