From fa63d9ef422d55df1e33d123c61ebe960540673c Mon Sep 17 00:00:00 2001 From: Beesafe Date: Mon, 23 Dec 2024 09:46:39 +0100 Subject: [PATCH] Remove referings to bing map #259 (#451) - Removes BingMapService (backend) - Removes bingMapKey field in MapSettings model - Removes front reference to bing map Key --- .../Exceptions/InvalidBingApiKeyException.php | 5 --- .../Controllers/MapSettingsController.php | 18 ++------- .../app/Services/BingMapApiService.php | 39 ------------------- ...12_23_165814_create_map_settings_table.php | 1 - src/frontend/src/mixins/mapSharing.js | 20 ++-------- .../src/modules/Settings/MapSettings.vue | 39 ------------------- .../src/repositories/MapSettingsRepository.js | 3 -- .../src/services/MapSettingsService.js | 14 ------- 8 files changed, 7 insertions(+), 132 deletions(-) delete mode 100644 src/backend/app/Exceptions/InvalidBingApiKeyException.php delete mode 100644 src/backend/app/Services/BingMapApiService.php diff --git a/src/backend/app/Exceptions/InvalidBingApiKeyException.php b/src/backend/app/Exceptions/InvalidBingApiKeyException.php deleted file mode 100644 index 76a1e6db7..000000000 --- a/src/backend/app/Exceptions/InvalidBingApiKeyException.php +++ /dev/null @@ -1,5 +0,0 @@ -bingMapApiService = $bingMapApiService; - } + public function __construct() {} public function index(): ApiResource { return new ApiResource(MapSettings::all()); @@ -27,20 +21,14 @@ public function update($id): ApiResource { 'latitude' => request('latitude'), 'longitude' => request('longitude'), 'provider' => request('provider'), - 'bingMapApiKey' => request('bingMapApiKey'), ] ); return new ApiResource([$mapSettings->fresh()]); } + // TODO: remove this method and associated route references when docs can be updated public function checkBingApiKey($key): ApiResource { - try { - $apiAuthentication = $this->bingMapApiService->checkAuthenticationKey($key); - } catch (InvalidBingApiKeyException $exception) { - $apiAuthentication = false; - } - - return ApiResource::make(['authentication' => $apiAuthentication]); + return ApiResource::make(['authentication' => '']); } } diff --git a/src/backend/app/Services/BingMapApiService.php b/src/backend/app/Services/BingMapApiService.php deleted file mode 100644 index b850b9505..000000000 --- a/src/backend/app/Services/BingMapApiService.php +++ /dev/null @@ -1,39 +0,0 @@ -httpClient = $httpClient; - } - - /** - * @throws InvalidBingApiKeyException - */ - public function checkAuthenticationKey($key): bool { - try { - $response = $this->httpClient->get(config('services.bingMapApi.url').$key)->getBody()->getContents(); - } catch (GuzzleException $e) { - throw new InvalidBingApiKeyException($e->getMessage()); - } - - return $this->isRequestAuthenticated($response); - } - - private function isRequestAuthenticated($body): bool { - try { - $jsonBody = json_decode($body, true, 512, JSON_THROW_ON_ERROR); - $authenticated = $jsonBody['statusDescription'] === 'OK'; - } catch (\JsonException $exception) { - $authenticated = false; - } - - return $authenticated; - } -} diff --git a/src/backend/database/migrations/micropowermanager/2020_12_23_165814_create_map_settings_table.php b/src/backend/database/migrations/micropowermanager/2020_12_23_165814_create_map_settings_table.php index e4ef06f47..c2a2f3893 100644 --- a/src/backend/database/migrations/micropowermanager/2020_12_23_165814_create_map_settings_table.php +++ b/src/backend/database/migrations/micropowermanager/2020_12_23_165814_create_map_settings_table.php @@ -19,7 +19,6 @@ public function up() { $table->double('latitude', 10); $table->double('longitude', 10); $table->string('provider')->nullable(); - $table->string('bingMapApiKey')->nullable(); $table->timestamps(); }); diff --git a/src/frontend/src/mixins/mapSharing.js b/src/frontend/src/mixins/mapSharing.js index b1a325072..2ed9267a3 100644 --- a/src/frontend/src/mixins/mapSharing.js +++ b/src/frontend/src/mixins/mapSharing.js @@ -132,19 +132,10 @@ export const sharedMap = { this.nonEditableLayer = new L.FeatureGroup() }, setTileLayer() { - if (this.mapProvider) { - L.tileLayer - .bing(this.bingMapApiKey, { - maxZoom: this.maxZoom, - attribution: this.osmAttrib, - }) - .addTo(this.map) - } else { - L.tileLayer(this.osmUrl, { - maxZoom: this.maxZoom, - attribution: this.osmAttrib, - }).addTo(this.map) - } + L.tileLayer(this.osmUrl, { + maxZoom: this.maxZoom, + attribution: this.osmAttrib, + }).addTo(this.map) }, reGenerateMap(mutatingCenter) { this.map.flyTo(mutatingCenter, this.zoom, this.drawingOptions) @@ -182,9 +173,6 @@ export const sharedMap = { mapProvider() { return store.getters["settings/getMapSettings"].provider === "Bing Maps" }, - bingMapApiKey() { - return store.getters["settings/getMapSettings"].bingMapApiKey - }, }, watch: { mutatingCenter() { diff --git a/src/frontend/src/modules/Settings/MapSettings.vue b/src/frontend/src/modules/Settings/MapSettings.vue index 79f01c561..e1fc90f3f 100644 --- a/src/frontend/src/modules/Settings/MapSettings.vue +++ b/src/frontend/src/modules/Settings/MapSettings.vue @@ -36,29 +36,6 @@ -
- - - - - {{ errors.first("Bing Api Key") }} - - -
Set Map Starting Points
@@ -162,17 +139,6 @@ export default { return } - if ( - this.bingMapsProviderSelected && - !(await this.mapSettingsService.checkBingMapApiKey()) - ) { - this.alertNotify( - "error", - "Bing Map Api Key is wrong, please check again", - ) - this.hideLoadingIndicator() - return - } try { await this.mapSettingsService.update() this.updateMapSettingsStore() @@ -223,11 +189,6 @@ export default { this.mapKey++ }, }, - computed: { - bingMapsProviderSelected() { - return this.mapSettingsService.mapSettings.provider === "Bing Maps" - }, - }, } diff --git a/src/frontend/src/repositories/MapSettingsRepository.js b/src/frontend/src/repositories/MapSettingsRepository.js index 07f724845..5bc0e1f5e 100644 --- a/src/frontend/src/repositories/MapSettingsRepository.js +++ b/src/frontend/src/repositories/MapSettingsRepository.js @@ -10,7 +10,4 @@ export default { update(id, mapSettings) { return Client.put(`${resource}/${id}`, mapSettings) }, - checkBingApiKey(key) { - return Client.get(`${resource}/key/${key}`) - }, } diff --git a/src/frontend/src/services/MapSettingsService.js b/src/frontend/src/services/MapSettingsService.js index f5d20f7f9..9201c4781 100644 --- a/src/frontend/src/services/MapSettingsService.js +++ b/src/frontend/src/services/MapSettingsService.js @@ -9,7 +9,6 @@ export class MapSettingsService { latitude: null, longitude: null, provider: null, - bingMapApiKey: null, } } @@ -32,7 +31,6 @@ export class MapSettingsService { latitude: this.mapSettings.latitude, longitude: this.mapSettings.longitude, provider: this.mapSettings.provider, - bingMapApiKey: this.mapSettings.bingMapApiKey, } let response = await this.repository.update( mapSettingsPm.id, @@ -49,17 +47,6 @@ export class MapSettingsService { } } - async checkBingMapApiKey() { - try { - const { data } = await this.repository.checkBingApiKey( - this.mapSettings.bingMapApiKey, - ) - return data.data.authentication - } catch (error) { - return new ErrorHandler(error.response.data.message, "http") - } - } - fromJson(mapSettings) { this.mapSettings = { id: mapSettings.id, @@ -67,7 +54,6 @@ export class MapSettingsService { latitude: mapSettings.latitude, longitude: mapSettings.longitude, provider: mapSettings.provider, - bingMapApiKey: mapSettings.bingMapApiKey, } return this.mapSettings }