Skip to content

Commit

Permalink
Merge pull request #472 from xcube-dev/forman-470-check_viewer_state_api
Browse files Browse the repository at this point in the history
Hide "share" button without persistence API
  • Loading branch information
forman authored Feb 20, 2025
2 parents dafac3a + 991a8fe commit 3f84e08
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
## Changes in version 1.4.2 (in development)

* The new "share" button no longer appears if the xcube Server has no
respective API configuration. (#470)

* Fixed regression when zooming into time-series charts. (#468)

* We now render the new `description` markdown properties received from
Expand Down
43 changes: 43 additions & 0 deletions src/api/hasViewerStateApi.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2019-2024 by the xcube development team and contributors.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
* of the Software, and to permit persons to whom the Software is furnished to do
* so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

import { makeRequestUrl } from "./callApi";

export function hasViewerStateApi(apiServerUrl: string): Promise<boolean> {
const url = makeRequestUrl(`${apiServerUrl}/viewer/state`, [
["key", "sentinel"],
]);
try {
return fetch(url)
.then((response) => {
// status 501 = "Not Implemented"
return response.status !== 501;
})
.catch(() => {
return false;
});
} catch (_) {
return Promise.resolve(false);
}
}
8 changes: 8 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import { Branding, parseBranding } from "@/util/branding";
import baseUrl from "@/util/baseurl";
import { buildPath } from "@/util/path";
import { isNumber } from "./util/types";
import { hasViewerStateApi } from "@/api/hasViewerStateApi";

export const appParams = new URLSearchParams(window.location.search);

Expand Down Expand Up @@ -96,6 +97,13 @@ export class Config {
);
branding = decodeBrandingFlag(branding, "allowUserVariables");
branding = decodeBrandingFlag(branding, "allow3D");
branding = decodeBrandingFlag(branding, "allowSharing");
if (branding.allowSharing) {
const hasStateApi = await hasViewerStateApi(server.url);
if (!hasStateApi) {
branding = { ...branding, allowSharing: false };
}
}
Config._instance = new Config(name, server, branding, authClient);
if (import.meta.env.DEV) {
console.debug("Configuration:", Config._instance);
Expand Down

0 comments on commit 3f84e08

Please sign in to comment.