Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use sharing token from URL for sharing links if it exists #6438

Merged
merged 5 commits into from
Sep 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.unreleased.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions frontend/javascripts/admin/admin_rest_api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ function requestUserToken(): Promise<string> {
return tokenRequestPromise;
}

export function getSharingToken(): string | null | undefined {
export function getSharingTokenFromUrlParameters(): string | null | undefined {
if (location != null) {
const params = Utils.getUrlParamsObject();

Expand All @@ -134,7 +134,7 @@ export function getSharingToken(): string | null | undefined {

let tokenPromise: Promise<string>;
export function doWithToken<T>(fn: (token: string) => Promise<T>, tries: number = 1): Promise<any> {
const sharingToken = getSharingToken();
const sharingToken = getSharingTokenFromUrlParameters();

if (sharingToken != null) {
return fn(sharingToken);
Expand Down
8 changes: 4 additions & 4 deletions frontend/javascripts/oxalis/model_initialization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import {
getAnnotationInformation,
getEmptySandboxAnnotationInformation,
getDataset,
getSharingToken,
getSharingTokenFromUrlParameters,
getUserConfiguration,
getDatasetViewConfiguration,
getEditableMapping,
Expand Down Expand Up @@ -148,7 +148,7 @@ export async function initialize(
annotation = await getEmptySandboxAnnotationInformation(
datasetId,
initialCommandType.tracingType,
getSharingToken(),
getSharingTokenFromUrlParameters(),
);
} else {
const { name, owningOrganization } = initialCommandType;
Expand All @@ -169,7 +169,7 @@ export async function initialize(
const initialDatasetSettings = await getDatasetViewConfiguration(
dataset,
serverVolumeTracingIds,
getSharingToken(),
getSharingTokenFromUrlParameters(),
);
const annotationSpecificDatasetSettings = applyAnnotationSpecificViewConfiguration(
annotation,
Expand Down Expand Up @@ -230,7 +230,7 @@ async function fetchParallel(
versions?: Versions,
): Promise<[APIDataset, UserConfiguration, Array<ServerTracing>]> {
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) : [],
]);
Expand Down
21 changes: 16 additions & 5 deletions frontend/javascripts/oxalis/view/action-bar/share_modal_view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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,
Expand All @@ -73,10 +87,7 @@ export function useDatasetSharingToken(dataset: APIDataset) {
};

useEffect(() => {
if (!activeUser) {
return;
}
fetchAndSetToken();
getAndSetToken();
}, [dataset, activeUser]);
return datasetToken;
}
Expand Down