Merge branch '15921-trailing-slash-fix'
authorLucas Di Pentima <lucas@di-pentima.com.ar>
Wed, 11 Dec 2019 22:05:02 +0000 (19:05 -0300)
committerLucas Di Pentima <lucas@di-pentima.com.ar>
Wed, 11 Dec 2019 22:05:02 +0000 (19:05 -0300)
Closes #15921

Arvados-DCO-1.1-Signed-off-by: Lucas Di Pentima <lucas@di-pentima.com.ar>

src/services/common-service/common-resource-service.test.ts
src/services/common-service/common-service.ts
src/services/common-service/trashable-resource-service.ts
src/services/groups-service/groups-service.ts
src/services/link-account-service/link-account-service.ts
src/services/project-service/project-service.test.ts
src/services/user-service/user-service.ts
src/store/collections/collection-create-actions.ts
src/views-components/dialog-forms/create-collection-dialog.ts

index a6a8b9d069f223aba86703924489885010d457b5..41a584fd78582056a279b2cd977b4731109e9bd8 100644 (file)
@@ -32,7 +32,7 @@ describe("CommonResourceService", () => {
 
     it("#create", async () => {
         axiosMock
-            .onPost("/resource/")
+            .onPost("/resource")
             .reply(200, { owner_uuid: "ownerUuidValue" });
 
         const commonResourceService = new CommonResourceService(axiosInstance, "resource", actions);
@@ -44,7 +44,7 @@ describe("CommonResourceService", () => {
         axiosInstance.post = jest.fn(() => Promise.resolve({data: {}}));
         const commonResourceService = new CommonResourceService(axiosInstance, "resource", actions);
         await commonResourceService.create({ ownerUuid: "ownerUuidValue" });
-        expect(axiosInstance.post).toHaveBeenCalledWith("/resource/", {owner_uuid: "ownerUuidValue"});
+        expect(axiosInstance.post).toHaveBeenCalledWith("/resource", {owner_uuid: "ownerUuidValue"});
     });
 
     it("#delete", async () => {
@@ -80,7 +80,7 @@ describe("CommonResourceService", () => {
 
     it("#list", async () => {
         axiosMock
-            .onGet("/resource/")
+            .onGet("/resource")
             .reply(200, {
                 kind: "kind",
                 offset: 2,
index 212f2f4d0305fbf36a54bce6393a16506ff2d005..1c1e0a569d7e485080fa6c9f934177b188c4fc27 100644 (file)
@@ -38,7 +38,7 @@ export class CommonService<T> {
 
     constructor(serverApi: AxiosInstance, resourceType: string, actions: ApiActions) {
         this.serverApi = serverApi;
-        this.resourceType = '/' + resourceType + '/';
+        this.resourceType = '/' + resourceType;
         this.actions = actions;
     }
 
@@ -93,7 +93,7 @@ export class CommonService<T> {
     delete(uuid: string): Promise<T> {
         return CommonService.defaultResponse(
             this.serverApi
-                .delete(this.resourceType + uuid),
+                .delete(this.resourceType + '/' + uuid),
             this.actions
         );
     }
@@ -101,7 +101,7 @@ export class CommonService<T> {
     get(uuid: string) {
         return CommonService.defaultResponse(
             this.serverApi
-                .get<T>(this.resourceType + uuid),
+                .get<T>(this.resourceType + '/' + uuid),
             this.actions
         );
     }
@@ -125,7 +125,7 @@ export class CommonService<T> {
     update(uuid: string, data: Partial<T>) {
         return CommonService.defaultResponse(
             this.serverApi
-                .put<T>(this.resourceType + uuid, data && CommonService.mapKeys(_.snakeCase)(data)),
+                .put<T>(this.resourceType + '/' + uuid, data && CommonService.mapKeys(_.snakeCase)(data)),
             this.actions
         );
     }
index 633b2fbd89cdf09041e4c93ee001916599763d62..5746bffb83136a6a80723d7da58b28ae0fe69301 100644 (file)
@@ -17,7 +17,7 @@ export class TrashableResourceService<T extends TrashableResource> extends Commo
     trash(uuid: string): Promise<T> {
         return CommonResourceService.defaultResponse(
             this.serverApi
-                .post(this.resourceType + `${uuid}/trash`),
+                .post(this.resourceType + `/${uuid}/trash`),
             this.actions
         );
     }
@@ -28,7 +28,7 @@ export class TrashableResourceService<T extends TrashableResource> extends Commo
         };
         return CommonResourceService.defaultResponse(
             this.serverApi
-                .post(this.resourceType + `${uuid}/untrash`, {
+                .post(this.resourceType + `/${uuid}/untrash`, {
                     params: CommonResourceService.mapKeys(_.snakeCase)(params)
                 }),
             this.actions
index 691ab8f7ccdb670affa90374cead8f4a783ca25a..281aa92152abaaa07f46b169b90ffef27308edaf 100644 (file)
@@ -46,8 +46,7 @@ export class GroupsService<T extends GroupResource = GroupResource> extends Tras
             filters: filters ? `[${filters}]` : undefined,
             order: order ? order : undefined
         };
-
-        const pathUrl = uuid ? `${uuid}/contents` : 'contents';
+        const pathUrl = uuid ? `/${uuid}/contents` : '/contents';
 
         const cfg: AxiosRequestConfig = { params: CommonResourceService.mapKeys(_.snakeCase)(params) };
         if (session) {
@@ -65,7 +64,7 @@ export class GroupsService<T extends GroupResource = GroupResource> extends Tras
     shared(params: SharedArguments = {}): Promise<ListResults<GroupContentsResource>> {
         return CommonResourceService.defaultResponse(
             this.serverApi
-                .get(this.resourceType + 'shared', { params }),
+                .get(this.resourceType + '/shared', { params }),
             this.actions
         );
     }
index 42fae3654a224f74f58fe8e86bbf3e95fd7ad7c4..b7298a8533d8b8e6e67f2abd3711f5c897463f22 100644 (file)
@@ -49,9 +49,9 @@ export class LinkAccountService {
             redirect_to_new_user: true
         };
         return CommonService.defaultResponse(
-            this.serverApi.post('/users/merge/', params),
+            this.serverApi.post('/users/merge', params),
             this.actions,
             false
         );
     }
-}
\ No newline at end of file
+}
index 9052360627c6f68ff0d95253efa6b0f4ae88bc55..aac04d96359dffb382e710bcd09a4b3e5cc5de98 100644 (file)
@@ -18,7 +18,7 @@ describe("CommonResourceService", () => {
         axiosInstance.post = jest.fn(() => Promise.resolve({ data: {} }));
         const projectService = new ProjectService(axiosInstance, actions);
         const resource = await projectService.create({ name: "nameValue" });
-        expect(axiosInstance.post).toHaveBeenCalledWith("/groups/", {
+        expect(axiosInstance.post).toHaveBeenCalledWith("/groups", {
             name: "nameValue",
             group_class: "project"
         });
@@ -28,7 +28,7 @@ describe("CommonResourceService", () => {
         axiosInstance.get = jest.fn(() => Promise.resolve({ data: {} }));
         const projectService = new ProjectService(axiosInstance, actions);
         const resource = await projectService.list();
-        expect(axiosInstance.get).toHaveBeenCalledWith("/groups/", {
+        expect(axiosInstance.get).toHaveBeenCalledWith("/groups", {
             params: {
                 filters: "[" + new FilterBuilder()
                     .addEqual("groupClass", "project")
index ddb9a3646b33e11717e89b0380e17d37711e9b04..d8c7fe3d94f24d6a9f276947dc58a56ef11c9c81 100644 (file)
@@ -15,7 +15,7 @@ export class UserService extends CommonResourceService<UserResource> {
     activate(uuid: string) {
         return CommonResourceService.defaultResponse(
             this.serverApi
-                .post(this.resourceType + `${uuid}/activate`),
+                .post(this.resourceType + `/${uuid}/activate`),
             this.actions
         );
     }
@@ -23,7 +23,7 @@ export class UserService extends CommonResourceService<UserResource> {
     unsetup(uuid: string) {
         return CommonResourceService.defaultResponse(
             this.serverApi
-                .post(this.resourceType + uuid + '/unsetup'),
+                .post(this.resourceType + `/${uuid}/unsetup`),
             this.actions
         );
     }
index e077b2a5b33c47b717630baf51c2f83b7bb600a7..83b3e89c2b162e3f718f14005ea556c19eaf973c 100644 (file)
@@ -49,7 +49,6 @@ export const createCollection = (data: CollectionCreateFormDialogData) =>
             await dispatch<any>(uploadCollectionFiles(newCollection.uuid));
             dispatch(dialogActions.CLOSE_DIALOG({ id: COLLECTION_CREATE_FORM_NAME }));
             dispatch(reset(COLLECTION_CREATE_FORM_NAME));
-            dispatch(progressIndicatorActions.STOP_WORKING(COLLECTION_CREATE_FORM_NAME));
             return newCollection;
         } catch (e) {
             const error = getCommonResourceServiceError(e);
@@ -65,7 +64,8 @@ export const createCollection = (data: CollectionCreateFormDialogData) =>
                 }));
                 await services.collectionService.delete(newCollection!.uuid);
             }
-            dispatch(progressIndicatorActions.STOP_WORKING(COLLECTION_CREATE_FORM_NAME));
             return;
+        } finally {
+            dispatch(progressIndicatorActions.STOP_WORKING(COLLECTION_CREATE_FORM_NAME));
         }
     };
index 785be787f92952daaa606a77a1d51bda436f9d27..374b070b22e914f6c9865ab0ca4a770b4b327716 100644 (file)
@@ -14,7 +14,9 @@ export const CreateCollectionDialog = compose(
     reduxForm<CollectionCreateFormDialogData>({
         form: COLLECTION_CREATE_FORM_NAME,
         onSubmit: (data, dispatch) => {
-            dispatch(createCollection(data));
+            // Somehow an extra field called 'files' gets added, copy
+            // the data object to get rid of it.
+            dispatch(createCollection({ ownerUuid: data.ownerUuid, name: data.name, description: data.description }));
         }
     })
 )(DialogCollectionCreate);