diff --git a/CHANGELOG.unreleased.md b/CHANGELOG.unreleased.md index 248dc205fb2..a2a012cbf32 100644 --- a/CHANGELOG.unreleased.md +++ b/CHANGELOG.unreleased.md @@ -17,6 +17,7 @@ For upgrade instructions, please check the [migration guide](MIGRATIONS.released ### Changed ### Fixed +- Fixed sharing button for users who are currently visiting a dataset or annotation which was shared with them. [#6438](https://github.com/scalableminds/webknossos/pull/6438) ### Removed diff --git a/frontend/javascripts/admin/admin_rest_api.ts b/frontend/javascripts/admin/admin_rest_api.ts index 2a81cba9fde..10c47f39be0 100644 --- a/frontend/javascripts/admin/admin_rest_api.ts +++ b/frontend/javascripts/admin/admin_rest_api.ts @@ -120,7 +120,7 @@ function requestUserToken(): Promise { return tokenRequestPromise; } -export function getSharingToken(): string | null | undefined { +export function getSharingTokenFromUrlParameters(): string | null | undefined { if (location != null) { const params = Utils.getUrlParamsObject(); @@ -134,7 +134,7 @@ export function getSharingToken(): string | null | undefined { let tokenPromise: Promise; export function doWithToken(fn: (token: string) => Promise, tries: number = 1): Promise { - const sharingToken = getSharingToken(); + const sharingToken = getSharingTokenFromUrlParameters(); if (sharingToken != null) { return fn(sharingToken); diff --git a/frontend/javascripts/oxalis/model_initialization.ts b/frontend/javascripts/oxalis/model_initialization.ts index e58dba489dc..5555df384d4 100644 --- a/frontend/javascripts/oxalis/model_initialization.ts +++ b/frontend/javascripts/oxalis/model_initialization.ts @@ -38,7 +38,7 @@ import { getAnnotationInformation, getEmptySandboxAnnotationInformation, getDataset, - getSharingToken, + getSharingTokenFromUrlParameters, getUserConfiguration, getDatasetViewConfiguration, getEditableMapping, @@ -148,7 +148,7 @@ export async function initialize( annotation = await getEmptySandboxAnnotationInformation( datasetId, initialCommandType.tracingType, - getSharingToken(), + getSharingTokenFromUrlParameters(), ); } else { const { name, owningOrganization } = initialCommandType; @@ -169,7 +169,7 @@ export async function initialize( const initialDatasetSettings = await getDatasetViewConfiguration( dataset, serverVolumeTracingIds, - getSharingToken(), + getSharingTokenFromUrlParameters(), ); const annotationSpecificDatasetSettings = applyAnnotationSpecificViewConfiguration( annotation, @@ -230,7 +230,7 @@ async function fetchParallel( versions?: Versions, ): Promise<[APIDataset, UserConfiguration, Array]> { return Promise.all([ - getDataset(datasetId, getSharingToken()), + getDataset(datasetId, getSharingTokenFromUrlParameters()), getUserConfiguration(), // Fetch the actual tracing from the datastore, if there is an skeletonAnnotation annotation ? getTracingsForAnnotation(annotation, versions) : [], ]); diff --git a/frontend/javascripts/oxalis/view/action-bar/share_modal_view.tsx b/frontend/javascripts/oxalis/view/action-bar/share_modal_view.tsx index 0702240d5f7..4c69db52059 100644 --- a/frontend/javascripts/oxalis/view/action-bar/share_modal_view.tsx +++ b/frontend/javascripts/oxalis/view/action-bar/share_modal_view.tsx @@ -16,6 +16,7 @@ import { editAnnotation, sendAnalyticsEvent, setOthersMayEditForAnnotation, + getSharingTokenFromUrlParameters, } from "admin/admin_rest_api"; import TeamSelectionComponent from "dashboard/dataset/team_selection_component"; import Toast from "libs/toast"; @@ -61,7 +62,20 @@ export function useDatasetSharingToken(dataset: APIDataset) { const activeUser = useSelector((state: OxalisState) => state.activeUser); const [datasetToken, setDatasetToken] = useState(""); - const fetchAndSetToken = async () => { + const getAndSetToken = async () => { + // If the current URL contains a token, we can simply use + // that as a sharing token. Otherwise, users who are currently + // visiting a sharing URL might not be able to use the share button, + // because they might not have permissions to GET the dataset's + // sharing token. + const urlToken = getSharingTokenFromUrlParameters(); + if (urlToken != null) { + setDatasetToken(urlToken); + return; + } + if (!activeUser) { + return; + } try { const sharingToken = await getDatasetSharingToken(dataset, { doNotInvestigate: true, @@ -73,10 +87,7 @@ export function useDatasetSharingToken(dataset: APIDataset) { }; useEffect(() => { - if (!activeUser) { - return; - } - fetchAndSetToken(); + getAndSetToken(); }, [dataset, activeUser]); return datasetToken; }