From 9575cd265171fa72aa4c6236a79e1d8d771c58a1 Mon Sep 17 00:00:00 2001 From: snipe Date: Fri, 1 Mar 2019 17:21:03 -0800 Subject: [PATCH 1/4] Add accessories endpoint to user API (#6775) --- app/Http/Controllers/Api/UsersController.php | 18 ++++++++++++++++++ routes/api.php | 7 +++++++ 2 files changed, 25 insertions(+) diff --git a/app/Http/Controllers/Api/UsersController.php b/app/Http/Controllers/Api/UsersController.php index cdf4d3be64..8783679b9b 100644 --- a/app/Http/Controllers/Api/UsersController.php +++ b/app/Http/Controllers/Api/UsersController.php @@ -12,6 +12,7 @@ use App\Http\Requests\SaveUserRequest; use App\Models\Asset; use App\Http\Transformers\AssetsTransformer; use App\Http\Transformers\SelectlistTransformer; +use App\Http\Transformers\AccessoriesTransformer; class UsersController extends Controller { @@ -302,6 +303,23 @@ class UsersController extends Controller return (new AssetsTransformer)->transformAssets($assets, $assets->count()); } + /** + * Return JSON containing a list of accessories assigned to a user. + * + * @author [A. Gianotto] [] + * @since [v4.6.14] + * @param $userId + * @return string JSON + */ + public function accessories($id) + { + $this->authorize('view', User::class); + $user = User::findOrFail($id); + $this->authorize('view', Accessory::class); + $accessories = $user->accessories; + return (new AccessoriesTransformer)->transformAccessories($accessories, $accessories->count()); + } + /** * Reset the user's two-factor status * diff --git a/routes/api.php b/routes/api.php index c66c388820..fffc46d55a 100644 --- a/routes/api.php +++ b/routes/api.php @@ -715,6 +715,13 @@ Route::group(['prefix' => 'v1','namespace' => 'Api'], function () { ] ); + Route::get('{user}/accessories', + [ + 'as' => 'api.users.accessorieslist', + 'uses' => 'UsersController@accessories' + ] + ); + Route::post('{user}/upload', [ 'as' => 'api.users.uploads', From c1ad2f9376dfbac0234f821a11c76c162829d16e Mon Sep 17 00:00:00 2001 From: snipe Date: Fri, 1 Mar 2019 17:39:50 -0800 Subject: [PATCH 2/4] Added link to Marksman - A Windows agent for Snipe-IT Per https://github.com/Scope-IT/marksman/issues/9#issuecomment-468275142 --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index d5d21ac588..6c1e90ce1d 100644 --- a/README.md +++ b/README.md @@ -59,6 +59,7 @@ Since the release of the JSON REST API, several third-party developers have been - [InQRy](https://github.com/Microsoft/InQRy) by [@Microsoft](https://github.com/Microsoft) - [SnipeitPS](https://github.com/snazy2000/SnipeitPS) by [@snazy2000](https://github.com/snazy2000) - Powershell API Wrapper for Snipe-it - [jamf2snipe](https://github.com/ParadoxGuitarist/jamf2snipe) by [@ParadoxGuitarist](https://github.com/ParadoxGuitarist) - Python script to sync assets between a JAMFPro instance and a Snipe-II instance +- [Marksman](https://github.com/Scope-IT/marksman) - A Windows agent for Snipe-IT As these were created by third-parties, Snipe-IT cannot provide support for these project, and you should contact the developers directly if you need assistance. Additionally, Snipe-IT makes no guarantees as to the reliability, accuracy or maintainability of these libraries. Use at your own risk. :) From 1393f44070c1773a0a04e4fd1bcd2256853f5c20 Mon Sep 17 00:00:00 2001 From: snipe Date: Mon, 4 Mar 2019 23:57:17 -0800 Subject: [PATCH 3/4] Create FUNDING.yml --- .github/FUNDING.yml | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .github/FUNDING.yml diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml new file mode 100644 index 0000000000..f60dda12f0 --- /dev/null +++ b/.github/FUNDING.yml @@ -0,0 +1,5 @@ +# You can add one username per supported platform and one custom link +# patreon: # Replace with your Patreon username +# open_collective: # Replace with your Open Collective username +# ko_fi: # Replace with your Ko-fi username +custom: https://snipeitapp.com/donate From f065bd77849f22acf7ec93e90c287701ee9772fb Mon Sep 17 00:00:00 2001 From: snipe Date: Tue, 5 Mar 2019 20:40:05 -0800 Subject: [PATCH 4/4] Added ability to do full name search in user dropdown selectlist --- app/Http/Controllers/Api/UsersController.php | 3 +-- app/Models/User.php | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/app/Http/Controllers/Api/UsersController.php b/app/Http/Controllers/Api/UsersController.php index 8783679b9b..e91ae8f676 100644 --- a/app/Http/Controllers/Api/UsersController.php +++ b/app/Http/Controllers/Api/UsersController.php @@ -148,8 +148,7 @@ class UsersController extends Controller $users = Company::scopeCompanyables($users); if ($request->has('search')) { - $users = $users->where('first_name', 'LIKE', '%'.$request->get('search').'%') - ->orWhere('last_name', 'LIKE', '%'.$request->get('search').'%') + $users = $users->SimpleNameSearch($request->get('search')) ->orWhere('username', 'LIKE', '%'.$request->get('search').'%') ->orWhere('employee_num', 'LIKE', '%'.$request->get('search').'%'); } diff --git a/app/Models/User.php b/app/Models/User.php index c783bdbba5..15e29657d7 100755 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -413,6 +413,25 @@ class User extends SnipeModel implements AuthenticatableContract, CanResetPasswo return json_decode($this->permissions, true); } + /** + * Query builder scope to search user by name with spaces in it. + * We don't use the advancedTextSearch() scope because that searches + * all of the relations as well, which is more than what we need. + * + * @param \Illuminate\Database\Query\Builder $query Query builder instance + * @param array $terms The search terms + * @return \Illuminate\Database\Query\Builder + */ + public function scopeSimpleNameSearch($query, $search) { + + $query = $query->where('first_name', 'LIKE', '%'.$search.'%') + ->orWhere('last_name', 'LIKE', '%'.$search.'%') + ->orWhereRaw('CONCAT('.DB::getTablePrefix().'users.first_name," ",'.DB::getTablePrefix().'users.last_name) LIKE ?', ["%$search%", "%$search%"]); + return $query; + } + + + /** * Run additional, advanced searches. *