16115: Adds expiration date param to sharing url service method.
authorLucas Di Pentima <lucas.dipentima@curii.com>
Thu, 19 May 2022 16:22:00 +0000 (13:22 -0300)
committerLucas Di Pentima <lucas.dipentima@curii.com>
Thu, 19 May 2022 16:22:00 +0000 (13:22 -0300)
Arvados-DCO-1.1-Signed-off-by: Lucas Di Pentima <lucas.dipentima@curii.com>

src/services/api-client-authorization-service/api-client-authorization-service.test.ts
src/services/api-client-authorization-service/api-client-authorization-service.ts
src/store/sharing-dialog/sharing-dialog-actions.ts

index 3a271f5396e8f9e516ee1257c6e9c91fda6a1d1c..4dd01b8737e57e76d463abe72fcba4f14d780081 100644 (file)
@@ -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', () => {
index 7c985dbba80c00bde82c697c5728409e97e682ae..dbda0a42c79951de4431f796e1b73cc7a612a75c 100644 (file)
@@ -14,17 +14,20 @@ export class ApiClientAuthorizationService extends CommonService<ApiClientAuthor
         super(serverApi, "api_client_authorizations", actions);
     }
 
-    createCollectionSharingToken(uuid: string): Promise<ApiClientAuthorization> {
+    createCollectionSharingToken(uuid: string, expDate: Date | undefined): Promise<ApiClientAuthorization> {
         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<ListResults<ApiClientAuthorization>> {
index 3eec0b59b802a3527ae98b9f3f7c0a8defea6be5..ffd81fb7fd88b60fc208b247c48baa325ce5736c 100644 (file)
@@ -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<SharingDialogData>(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',