Skip to content

Commit

Permalink
[FIX] App license error detail message removed (#22091)
Browse files Browse the repository at this point in the history
Co-authored-by: Guilherme Gazzo <guilherme@gazzo.xyz>
  • Loading branch information
d-gubert and ggazzo authored May 21, 2021
1 parent 5725c8b commit 4fa1def
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 23 deletions.
27 changes: 27 additions & 0 deletions app/apps/lib/misc/formatAppInstanceForRest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { AppStatus } from '@rocket.chat/apps-engine/definition/AppStatus';
import { IAppInfo } from '@rocket.chat/apps-engine/definition/metadata';
import { AppLicenseValidationResult } from '@rocket.chat/apps-engine/server/marketplace/license';
import { ProxiedApp } from '@rocket.chat/apps-engine/server/ProxiedApp';
import { IAppStorageItem } from '@rocket.chat/apps-engine/server/storage';

export interface IAppInfoRest extends IAppInfo {
status: AppStatus;
languages: IAppStorageItem['languageContent'];
licenseValidation?: AppLicenseValidationResult;
}

export function formatAppInstanceForRest(app: ProxiedApp): IAppInfoRest {
const appRest: IAppInfoRest = {
...app.getInfo(),
status: app.getStatus(),
languages: app.getStorageItem().languageContent,
};

const licenseValidation = app.getLatestLicenseValidationResult();

if (licenseValidation.hasErrors || licenseValidation.hasWarnings) {
appRest.licenseValidation = licenseValidation;
}

return appRest;
}
27 changes: 8 additions & 19 deletions app/apps/server/communication/rest.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { settings } from '../../../settings';
import { Info } from '../../../utils';
import { Settings, Users } from '../../../models/server';
import { Apps } from '../orchestrator';
import { formatAppInstanceForRest } from '../../lib/misc/formatAppInstanceForRest';

const appsEngineVersionForMarketplace = Info.marketplaceApiVersion.replace(/-.*/g, '');
const getDefaultHeaders = () => ({
Expand Down Expand Up @@ -155,13 +156,7 @@ export class AppsRestApi {
});
}

const apps = manager.get().map((prl) => {
const info = prl.getInfo();
info.languages = prl.getStorageItem().languageContent;
info.status = prl.getStatus();

return info;
});
const apps = manager.get().map(formatAppInstanceForRest);

return API.v1.success({ apps });
},
Expand Down Expand Up @@ -407,21 +402,15 @@ export class AppsRestApi {
return API.v1.success({ app: result.data });
}

const prl = manager.getOneById(this.urlParams.id);

if (prl) {
const info = prl.getInfo();
const app = manager.getOneById(this.urlParams.id);

return API.v1.success({
app: {
...info,
status: prl.getStatus(),
licenseValidation: prl.getLatestLicenseValidationResult(),
},
});
if (!app) {
return API.v1.notFound(`No App found by the id of: ${ this.urlParams.id }`);
}

return API.v1.notFound(`No App found by the id of: ${ this.urlParams.id }`);
return API.v1.success({
app: formatAppInstanceForRest(app),
});
},
post() {
let buff;
Expand Down
20 changes: 19 additions & 1 deletion client/views/admin/apps/AppDetailsPageContent.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Box, Chip, Divider, Margins } from '@rocket.chat/fuselage';
/* eslint-disable @typescript-eslint/no-use-before-define */
import { Box, Callout, Chip, Divider, Margins } from '@rocket.chat/fuselage';
import React, { FC } from 'react';

import ExternalLink from '../../../components/ExternalLink';
Expand Down Expand Up @@ -77,6 +78,23 @@ const AppDetailsPageContent: FC<AppDetailsPageContentProps> = ({ data }) => {
</Box>
</Box>
<Divider />

{data.licenseValidation && (
<>
{Object.entries(data.licenseValidation.warnings).map(([key, message]) => (
<Callout key={key} type='warning'>
{message}
</Callout>
))}

{Object.entries(data.licenseValidation.errors).map(([key, message]) => (
<Callout key={key} type='danger'>
{message}
</Callout>
))}
</>
)}

<Box display='flex' flexDirection='column'>
<Margins block='x12'>
<Box fontScale='s2'>{t('Categories')}</Box>
Expand Down
8 changes: 6 additions & 2 deletions client/views/admin/apps/AppsProvider.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { AppStatus } from '@rocket.chat/apps-engine/definition/AppStatus';
import React, { useEffect, useRef, useState, FC } from 'react';

import { AppEvents } from '../../../../app/apps/client/communication';
Expand Down Expand Up @@ -50,7 +51,7 @@ const AppsProvider: FC = ({ children }) => {

const handleAppAddedOrUpdated = async (appId: string): Promise<void> => {
try {
const { status, version } = await Apps.getApp(appId);
const { status, version, licenseValidation } = await Apps.getApp(appId);
const app = await Apps.getAppFromMarketplace(appId, version);
const updatedData = getDataCopy();
const index = updatedData.findIndex(({ id }: { id: string }) => id === appId);
Expand All @@ -59,6 +60,7 @@ const AppsProvider: FC = ({ children }) => {
installed: true,
status,
version,
licenseValidation,
marketplaceVersion: app.version,
};
setApps(updatedData);
Expand Down Expand Up @@ -96,7 +98,8 @@ const AppsProvider: FC = ({ children }) => {
if (!app) {
return;
}
app.status = status;

app.status = status as AppStatus;
setApps(updatedData);
invalidateData();
},
Expand Down Expand Up @@ -143,6 +146,7 @@ const AppsProvider: FC = ({ children }) => {
...(installedApp && {
status: installedApp.status,
version: installedApp.version,
licenseValidation: installedApp.licenseValidation,
}),
bundledIn: app.bundledIn,
marketplaceVersion: app.version,
Expand Down
8 changes: 7 additions & 1 deletion client/views/admin/apps/types.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { AppStatus } from '@rocket.chat/apps-engine/definition/AppStatus';

export type App = {
id: string;
iconFileData: string;
Expand All @@ -22,7 +24,11 @@ export type App = {
}[];
marketplaceVersion: string;
latest: App;
status: unknown;
status?: AppStatus;
licenseValidation?: {
errors: { [key: string]: string };
warnings: { [key: string]: string };
};
marketplace: unknown;
permissions: unknown[];
};

0 comments on commit 4fa1def

Please sign in to comment.