Explorar o código

fix(apps.service): updating an app config was throwing an error if domain was unchanged

Nicolas Meienberger %!s(int64=2) %!d(string=hai) anos
pai
achega
bbdee4a42b

+ 2 - 0
packages/dashboard/src/modules/Apps/containers/AppDetails.tsx

@@ -110,6 +110,7 @@ const AppDetails: React.FC<IProps> = ({ app, info }) => {
         description: 'App config updated successfully. Restart the app to apply the changes.',
         position: 'top',
         status: 'success',
+        isClosable: true,
       });
       updateSettingsDisclosure.onClose();
     } catch (error) {
@@ -126,6 +127,7 @@ const AppDetails: React.FC<IProps> = ({ app, info }) => {
         description: 'App updated successfully',
         position: 'top',
         status: 'success',
+        isClosable: true,
       });
     } catch (error) {
       handleError(error);

+ 9 - 0
packages/system-api/src/modules/apps/__tests__/apps.service.test.ts

@@ -383,6 +383,15 @@ describe('Update app config', () => {
     await AppsService.updateAppConfig(app2.appInfo.id, { TEST_FIELD: 'test' }, true, 'test.com');
     await expect(AppsService.updateAppConfig(app3.appInfo.id, { TEST_FIELD: 'test' }, true, 'test.com')).rejects.toThrowError(`Domain test.com already in use by app ${app2.appInfo.id}`);
   });
+
+  it('Should not throw if updating with same domain', async () => {
+    const app2 = await createApp({ exposable: true, installed: true });
+    // @ts-ignore
+    fs.__createMockFiles(Object.assign(app2.MockFiles));
+
+    await AppsService.updateAppConfig(app2.appInfo.id, { TEST_FIELD: 'test' }, true, 'test.com');
+    await AppsService.updateAppConfig(app2.appInfo.id, { TEST_FIELD: 'test' }, true, 'test.com');
+  });
 });
 
 describe('Get app config', () => {

+ 2 - 1
packages/system-api/src/modules/apps/apps.service.ts

@@ -5,6 +5,7 @@ import { AppInfo, AppStatusEnum, ListAppsResonse } from './apps.types';
 import App from './app.entity';
 import logger from '../../config/logger/logger';
 import config from '../../config';
+import { Not } from 'typeorm';
 
 const sortApps = (a: AppInfo, b: AppInfo) => a.name.localeCompare(b.name);
 
@@ -153,7 +154,7 @@ const updateAppConfig = async (id: string, form: Record<string, string>, exposed
   }
 
   if (exposed) {
-    const appsWithSameDomain = await App.find({ where: { domain, exposed: true } });
+    const appsWithSameDomain = await App.find({ where: { domain, exposed: true, id: Not(id) } });
     if (appsWithSameDomain.length > 0) {
       throw new Error(`Domain ${domain} already in use by app ${appsWithSameDomain[0].id}`);
     }