From: Lucas Di Pentima Date: Thu, 19 May 2022 16:22:00 +0000 (-0300) Subject: 16115: Adds expiration date param to sharing url service method. X-Git-Tag: 2.4.1~1^2~2^2~4 X-Git-Url: https://git.arvados.org/arvados-workbench2.git/commitdiff_plain/4f26fc6e11a411c11fc481b937c2e073f4858081 16115: Adds expiration date param to sharing url service method. Arvados-DCO-1.1-Signed-off-by: Lucas Di Pentima --- diff --git a/src/services/api-client-authorization-service/api-client-authorization-service.test.ts b/src/services/api-client-authorization-service/api-client-authorization-service.test.ts index 3a271f53..4dd01b87 100644 --- a/src/services/api-client-authorization-service/api-client-authorization-service.test.ts +++ b/src/services/api-client-authorization-service/api-client-authorization-service.test.ts @@ -24,7 +24,7 @@ describe('ApiClientAuthorizationService', () => { expect(() => apiClientAuthorizationService.createCollectionSharingToken("foo")).toThrowError("UUID foo is not a collection"); }); - it('should make a create request with proper scopes', async () => { + it('should make a create request with proper scopes and no expiration date', async () => { serverApi.post = jest.fn(() => Promise.resolve( { data: { uuid: 'zzzzz-4zz18-0123456789abcde' } } )); @@ -40,6 +40,25 @@ describe('ApiClientAuthorizationService', () => { } ); }); + + it('should make a create request with proper scopes and expiration date', async () => { + serverApi.post = jest.fn(() => Promise.resolve( + { data: { uuid: 'zzzzz-4zz18-0123456789abcde' } } + )); + const uuid = 'zzzzz-4zz18-0123456789abcde' + const expDate = new Date(2022, 8, 28, 12, 0, 0); + await apiClientAuthorizationService.createCollectionSharingToken(uuid, expDate); + expect(serverApi.post).toHaveBeenCalledWith( + '/api_client_authorizations', { + scopes: [ + `GET /arvados/v1/collections/${uuid}`, + `GET /arvados/v1/collections/${uuid}/`, + `GET /arvados/v1/keep_services/accessible`, + ], + expires_at: expDate.toUTCString() + } + ); + }); }); describe('listCollectionSharingToken', () => { diff --git a/src/services/api-client-authorization-service/api-client-authorization-service.ts b/src/services/api-client-authorization-service/api-client-authorization-service.ts index 7c985dbb..dbda0a42 100644 --- a/src/services/api-client-authorization-service/api-client-authorization-service.ts +++ b/src/services/api-client-authorization-service/api-client-authorization-service.ts @@ -14,17 +14,20 @@ export class ApiClientAuthorizationService extends CommonService { + createCollectionSharingToken(uuid: string, expDate: Date | undefined): Promise { if (extractUuidObjectType(uuid) !== ResourceObjectType.COLLECTION) { throw new Error(`UUID ${uuid} is not a collection`); } - return this.create({ + const data = { scopes: [ `GET /arvados/v1/collections/${uuid}`, `GET /arvados/v1/collections/${uuid}/`, `GET /arvados/v1/keep_services/accessible`, ] - }); + } + return expDate !== undefined + ? this.create({...data, expiresAt: expDate.toUTCString()}) + : this.create(data); } listCollectionSharingTokens(uuid: string): Promise> { diff --git a/src/store/sharing-dialog/sharing-dialog-actions.ts b/src/store/sharing-dialog/sharing-dialog-actions.ts index 3eec0b59..ffd81fb7 100644 --- a/src/store/sharing-dialog/sharing-dialog-actions.ts +++ b/src/store/sharing-dialog/sharing-dialog-actions.ts @@ -61,14 +61,14 @@ export interface SharingDialogData { refresh: () => void; } -export const createSharingToken = async (dispatch: Dispatch, getState: () => RootState, { apiClientAuthorizationService }: ServiceRepository) => { +export const createSharingToken = (expDate: Date | undefined) => async (dispatch: Dispatch, getState: () => RootState, { apiClientAuthorizationService }: ServiceRepository) => { const dialog = getDialog(getState().dialog, SHARING_DIALOG_NAME); if (dialog) { const resourceUuid = dialog.data.resourceUuid; if (extractUuidObjectType(resourceUuid) === ResourceObjectType.COLLECTION) { dispatch(progressIndicatorActions.START_WORKING(SHARING_DIALOG_NAME)); try { - const sharingToken = await apiClientAuthorizationService.createCollectionSharingToken(resourceUuid); + const sharingToken = await apiClientAuthorizationService.createCollectionSharingToken(resourceUuid, expDate); dispatch(resourcesActions.SET_RESOURCES([sharingToken])); dispatch(snackbarActions.OPEN_SNACKBAR({ message: 'Sharing URL created',