From d2e6cd8a0d69fd492c41ac00e3086304977727ca Mon Sep 17 00:00:00 2001 From: "Ronald A. Richardson" Date: Thu, 21 Mar 2024 16:26:17 +0800 Subject: [PATCH 1/6] preparing for next release --- composer.json | 2 +- extension.json | 2 +- package.json | 2 +- server/src/Http/Controllers/FleetOpsController.php | 6 ------ 4 files changed, 3 insertions(+), 9 deletions(-) diff --git a/composer.json b/composer.json index 723932ad..8875378c 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,6 @@ { "name": "fleetbase/fleetops-api", - "version": "0.4.22", + "version": "0.4.23", "description": "Fleet & Transport Management Extension for Fleetbase", "keywords": [ "fleetbase-extension", diff --git a/extension.json b/extension.json index b0204c29..bbc0ff6d 100644 --- a/extension.json +++ b/extension.json @@ -1,6 +1,6 @@ { "name": "Fleet-Ops", - "version": "0.4.22", + "version": "0.4.23", "description": "Fleet & Transport Management Extension for Fleetbase", "repository": "https://github.com/fleetbase/fleetops", "license": "MIT", diff --git a/package.json b/package.json index 1bbc27f3..dc857582 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@fleetbase/fleetops-engine", - "version": "0.4.22", + "version": "0.4.23", "description": "Fleet & Transport Management Extension for Fleetbase", "fleetbase": { "route": "fleet-ops" diff --git a/server/src/Http/Controllers/FleetOpsController.php b/server/src/Http/Controllers/FleetOpsController.php index 051d2da4..d8783222 100644 --- a/server/src/Http/Controllers/FleetOpsController.php +++ b/server/src/Http/Controllers/FleetOpsController.php @@ -11,10 +11,4 @@ class FleetOpsController extends FleetbaseController * The package namespace used to resolve from. */ public string $namespace = '\\Fleetbase\\FleetOps'; - - public function test() - { - $order = Order::where('public_id', '')->first(); - dd($order->config()->getNextActivity()); - } } From 80543e8264ca350ad2822b4519056097152675a8 Mon Sep 17 00:00:00 2001 From: Doljinsuren Enkhbayar Date: Tue, 26 Mar 2024 12:11:49 +0800 Subject: [PATCH 2/6] Fixed session data not being changed --- .../Controllers/Api/v1/DriverController.php | 6 ++++-- .../Controllers/Api/v1/OrderController.php | 19 ++++++++++--------- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/server/src/Http/Controllers/Api/v1/DriverController.php b/server/src/Http/Controllers/Api/v1/DriverController.php index 5fc51b84..36775f09 100644 --- a/server/src/Http/Controllers/Api/v1/DriverController.php +++ b/server/src/Http/Controllers/Api/v1/DriverController.php @@ -597,7 +597,9 @@ public function switchOrganization(string $id, SwitchOrganizationRequest $reques } // Assign user to company and update their session - $user->assignCompany($company); + + $user->update(['company_uuid' => $company->uuid]); + Auth::setSession($user); return new Organization($company); @@ -772,4 +774,4 @@ private static function phone(?string $phone = null): string return $phone; } -} +} \ No newline at end of file diff --git a/server/src/Http/Controllers/Api/v1/OrderController.php b/server/src/Http/Controllers/Api/v1/OrderController.php index 77a8fec0..1bc98337 100644 --- a/server/src/Http/Controllers/Api/v1/OrderController.php +++ b/server/src/Http/Controllers/Api/v1/OrderController.php @@ -434,6 +434,7 @@ public function update($id, UpdateOrderRequest $request) public function query(Request $request) { $results = Order::queryWithRequest($request, function (&$query, $request) { + $query->where('company_uuid', session('company')); if ($request->has('payload')) { $query->whereHas('payload', function ($q) use ($request) { $q->where('public_id', $request->input('payload')); @@ -495,9 +496,9 @@ public function query(Request $request) }); } - if ($request->has('on')) { - $on = Carbon::fromString($request->input('on')); - + if ($request->filled('on')) { + $on = Carbon::parse($request->input('on')); + $query->where(function ($q) use ($on) { $q->whereDate('created_at', $on); $q->orWhereDate('scheduled_at', $on); @@ -544,6 +545,8 @@ public function query(Request $request) if ($addedNearbyQuery === false && is_string($nearby) && Str::startsWith($nearby, 'driver_')) { $driver = Driver::where('public_id', $nearby)->first(); + dd($driver); + if ($driver) { $query->whereHas('payload', function ($q) use ($driver, $distance) { $q->whereHas('pickup', function ($q) use ($driver, $distance) { @@ -582,6 +585,8 @@ public function query(Request $request) } }); + info("Result: ", [$results]); + return OrderResource::collection($results); } @@ -1401,14 +1406,10 @@ public function getEditableEntityFields(string $id, Request $request) // Get entity editing settings $savedEntityEditingSettings = Setting::where('key', 'fleet-ops.entity-editing-settings')->value('value'); - if ($orderConfigId && $savedEntityEditingSettings) { - $resolvedEntityEditingSettings = data_get($savedEntityEditingSettings, $orderConfigId, []); - if ($resolvedEntityEditingSettings) { - $entityEditingSettings = data_get($resolvedEntityEditingSettings, 'editable_entity_fields', []); - } + $entityEditingSettings = data_get($savedEntityEditingSettings, $orderConfigId, []); } return response()->json($entityEditingSettings); } -} +} \ No newline at end of file From 802fac233893fcfb1ff4952db1e56e0e478a9c1a Mon Sep 17 00:00:00 2001 From: Doljinsuren Enkhbayar Date: Tue, 26 Mar 2024 13:47:14 +0800 Subject: [PATCH 3/6] removed log --- server/src/Http/Controllers/Api/v1/OrderController.php | 4 ---- 1 file changed, 4 deletions(-) diff --git a/server/src/Http/Controllers/Api/v1/OrderController.php b/server/src/Http/Controllers/Api/v1/OrderController.php index 1bc98337..c050b0e6 100644 --- a/server/src/Http/Controllers/Api/v1/OrderController.php +++ b/server/src/Http/Controllers/Api/v1/OrderController.php @@ -545,8 +545,6 @@ public function query(Request $request) if ($addedNearbyQuery === false && is_string($nearby) && Str::startsWith($nearby, 'driver_')) { $driver = Driver::where('public_id', $nearby)->first(); - dd($driver); - if ($driver) { $query->whereHas('payload', function ($q) use ($driver, $distance) { $q->whereHas('pickup', function ($q) use ($driver, $distance) { @@ -585,8 +583,6 @@ public function query(Request $request) } }); - info("Result: ", [$results]); - return OrderResource::collection($results); } From d7894350f9d8b3e800dd01d95e325fe61b59ed6d Mon Sep 17 00:00:00 2001 From: Doljinsuren Enkhbayar Date: Tue, 26 Mar 2024 16:19:00 +0800 Subject: [PATCH 4/6] checked credential --- .../Http/Controllers/Api/v1/DriverController.php | 3 +-- server/src/Http/Filter/OrderFilter.php | 2 +- server/src/Http/Requests/CreateContactRequest.php | 2 +- server/src/Http/Requests/CreateDriverRequest.php | 2 +- server/src/Http/Requests/CreateEntityRequest.php | 2 +- server/src/Http/Requests/CreateIssueRequest.php | 15 +++++++++++++++ server/src/Http/Requests/CreatePlaceRequest.php | 4 +--- server/src/Http/Requests/CreateVehicleRequest.php | 2 +- server/src/Http/Resources/v1/Driver.php | 2 +- 9 files changed, 23 insertions(+), 11 deletions(-) diff --git a/server/src/Http/Controllers/Api/v1/DriverController.php b/server/src/Http/Controllers/Api/v1/DriverController.php index 36775f09..a27b41c1 100644 --- a/server/src/Http/Controllers/Api/v1/DriverController.php +++ b/server/src/Http/Controllers/Api/v1/DriverController.php @@ -500,7 +500,7 @@ public function verifyCode(Request $request) return response()->apiError($e->getMessage()); } - // $driver->update(['auth_token' => $token->plainTextToken]); + $driver->update(['auth_token' => $token->plainTextToken]); $driver->token = $token->plainTextToken; return new DriverResource($driver); @@ -597,7 +597,6 @@ public function switchOrganization(string $id, SwitchOrganizationRequest $reques } // Assign user to company and update their session - $user->update(['company_uuid' => $company->uuid]); Auth::setSession($user); diff --git a/server/src/Http/Filter/OrderFilter.php b/server/src/Http/Filter/OrderFilter.php index 0f714a8b..2dbff6d8 100644 --- a/server/src/Http/Filter/OrderFilter.php +++ b/server/src/Http/Filter/OrderFilter.php @@ -38,7 +38,7 @@ function ($q) { public function queryForPublic() { - $this->builder->where('company_uuid', $this->session->get('company'))->whereHas('trackingNumber')->whereHas('payload'); + $this->builder->where('company_uuid', $this->session->get('company')); } public function unassigned(bool $unassigned) diff --git a/server/src/Http/Requests/CreateContactRequest.php b/server/src/Http/Requests/CreateContactRequest.php index fc211afd..b17223a1 100644 --- a/server/src/Http/Requests/CreateContactRequest.php +++ b/server/src/Http/Requests/CreateContactRequest.php @@ -14,7 +14,7 @@ class CreateContactRequest extends FleetbaseRequest */ public function authorize() { - return request()->session()->has('storefront_key') || request()->session()->has('api_credential'); + return request()->session()->has('storefront_key') || request()->session()->has('api_credential') || request()->session()->has('is_sanctum_token');; } /** diff --git a/server/src/Http/Requests/CreateDriverRequest.php b/server/src/Http/Requests/CreateDriverRequest.php index dbfb5ad5..90f8fce2 100644 --- a/server/src/Http/Requests/CreateDriverRequest.php +++ b/server/src/Http/Requests/CreateDriverRequest.php @@ -15,7 +15,7 @@ class CreateDriverRequest extends FleetbaseRequest */ public function authorize() { - return request()->is('navigator/v1/*') || request()->session()->has('api_credential'); + return request()->is('navigator/v1/*') || request()->session()->has('api_credential') || request()->session()->has('is_sanctum_token'); } /** diff --git a/server/src/Http/Requests/CreateEntityRequest.php b/server/src/Http/Requests/CreateEntityRequest.php index 39dadba8..96a9f7f3 100644 --- a/server/src/Http/Requests/CreateEntityRequest.php +++ b/server/src/Http/Requests/CreateEntityRequest.php @@ -14,7 +14,7 @@ class CreateEntityRequest extends FleetbaseRequest */ public function authorize() { - return request()->session()->has('api_credential'); + return request()->session()->has('api_credential') || request()->session()->has('is_sanctum_token');; } /** diff --git a/server/src/Http/Requests/CreateIssueRequest.php b/server/src/Http/Requests/CreateIssueRequest.php index 62a2a853..c63ea808 100644 --- a/server/src/Http/Requests/CreateIssueRequest.php +++ b/server/src/Http/Requests/CreateIssueRequest.php @@ -6,6 +6,21 @@ class CreateIssueRequest extends FleetbaseRequest { + /** + * Determine if the user is authorized to make this request. + * + * @return bool + */ + public function authorize() + { + return request()->session()->has('api_credential') || request()->session()->has('is_sanctum_token');; + } + + /** + * Get the validation rules that apply to the request. + * + * @return array + */ public function rules() { return [ diff --git a/server/src/Http/Requests/CreatePlaceRequest.php b/server/src/Http/Requests/CreatePlaceRequest.php index fce9d484..926c82ff 100644 --- a/server/src/Http/Requests/CreatePlaceRequest.php +++ b/server/src/Http/Requests/CreatePlaceRequest.php @@ -16,9 +16,7 @@ class CreatePlaceRequest extends FleetbaseRequest */ public function authorize() { - return request() - ->session() - ->has('api_credential'); + return request()->session()->has('api_credential') || request()->session()->has('is_sanctum_token');; } /** diff --git a/server/src/Http/Requests/CreateVehicleRequest.php b/server/src/Http/Requests/CreateVehicleRequest.php index a0ce4842..479438f5 100644 --- a/server/src/Http/Requests/CreateVehicleRequest.php +++ b/server/src/Http/Requests/CreateVehicleRequest.php @@ -14,7 +14,7 @@ class CreateVehicleRequest extends FleetbaseRequest */ public function authorize() { - return request()->session()->has('api_credential'); + return request()->session()->has('api_credential') || request()->session()->has('is_sanctum_token');; } /** diff --git a/server/src/Http/Resources/v1/Driver.php b/server/src/Http/Resources/v1/Driver.php index 0ce292ee..c7650b5d 100644 --- a/server/src/Http/Resources/v1/Driver.php +++ b/server/src/Http/Resources/v1/Driver.php @@ -53,7 +53,7 @@ public function toArray($request) 'city' => data_get($this, 'city', Utils::getCapitalCityFromCountryCode($this->country)), 'online' => data_get($this, 'online', false), 'status' => $this->status, - 'token' => data_get($this, 'token'), + 'token' => $this->auth_token, 'meta' => $this->meta, 'updated_at' => $this->updated_at, 'created_at' => $this->created_at, From 1686c0222ca98d30d4e8a7847a18e4786851b621 Mon Sep 17 00:00:00 2001 From: "Ronald A. Richardson" Date: Tue, 26 Mar 2024 18:59:46 +0800 Subject: [PATCH 5/6] added much needed purchase rate model to polymorph relation fix script --- .../Commands/FixInvalidPolymorphicRelationTypeNamespaces.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/src/Console/Commands/FixInvalidPolymorphicRelationTypeNamespaces.php b/server/src/Console/Commands/FixInvalidPolymorphicRelationTypeNamespaces.php index 3289db9c..8e6a5883 100644 --- a/server/src/Console/Commands/FixInvalidPolymorphicRelationTypeNamespaces.php +++ b/server/src/Console/Commands/FixInvalidPolymorphicRelationTypeNamespaces.php @@ -36,7 +36,7 @@ public function handle() ['model' => \Fleetbase\FleetOps\Models\Order::class, 'columns' => ['customer_type', 'facilitator_type']], ['model' => \Fleetbase\FleetOps\Models\Place::class, 'columns' => ['owner_type']], ['model' => \Fleetbase\FleetOps\Models\Entity::class, 'columns' => ['customer_type']], - ['model' => \Fleetbase\FleetOps\Models\PurchaseRate::class, 'columns' => ['customer_type']], + ['model' => \Fleetbase\FleetOps\Models\PurchaseRate::class, 'columns' => ['customer_type']] ]; foreach ($models as $modelConfig) { From 3f981c034c842573d0d284d9f78ee298d909a168 Mon Sep 17 00:00:00 2001 From: "Ronald A. Richardson" Date: Wed, 27 Mar 2024 20:29:36 +0800 Subject: [PATCH 6/6] upgrade core-api dependency --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 8875378c..fa78253d 100644 --- a/composer.json +++ b/composer.json @@ -22,7 +22,7 @@ ], "require": { "php": "^8.0", - "fleetbase/core-api": "^1.4.14", + "fleetbase/core-api": "^1.4.15", "barryvdh/laravel-dompdf": "^2.0", "brick/geo": "0.7.2", "cknow/laravel-money": "^7.1",