Skip to content

Commit

Permalink
fix: add ENABLE_ERDA_LICENSE (#4051)
Browse files Browse the repository at this point in the history
  • Loading branch information
laojun authored Jul 4, 2024
1 parent 036b4f4 commit d7b5e84
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 57 deletions.
3 changes: 2 additions & 1 deletion scheduler/src/filters/not-found.filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ const {
ENABLE_BIGDATA = '',
ENABLE_EDGE = '',
ENABLE_GALLERY = true,
ENABLE_ERDA_LICENSE = false,
ENABLE_APPLY_ORG = '',
TERMINUS_KEY = '',
TERMINUS_TA_ENABLE = false,
Expand All @@ -53,7 +54,7 @@ const {

let newContent = indexHtmlContent.replace(
'<!-- $ -->',
`<script>window.erdaEnv={UC_PUBLIC_URL:"${UC_PUBLIC_URL}",ENABLE_BIGDATA:"${ENABLE_BIGDATA}",ENABLE_EDGE:"${ENABLE_EDGE}",ENABLE_GALLERY:"${ENABLE_GALLERY}",GA_ID:"${GA_ID}",LINKS_AK:"${LINKS_AK}",LINKS_SK:"${LINKS_SK}",UI_PUBLIC_ADDR:"${UI_PUBLIC_ADDR}",ENABLE_APPLY_ORG:"${ENABLE_APPLY_ORG}",I18N_ACCESS_ENV:"${I18N_ACCESS_ENV}",AI_BACKEND_URL:"${AI_BACKEND_URL}",AI_PROXY_CLIENT_AK:"${AI_PROXY_CLIENT_AK}",ERDA_AI_BACKEND_URL:"${ERDA_AI_BACKEND_URL}",DICE_CLUSTER_NAME:"${DICE_CLUSTER_NAME}"}</script>`,
`<script>window.erdaEnv={UC_PUBLIC_URL:"${UC_PUBLIC_URL}",ENABLE_BIGDATA:"${ENABLE_BIGDATA}",ENABLE_EDGE:"${ENABLE_EDGE}",ENABLE_ERDA_LICENSE:"${ENABLE_ERDA_LICENSE}",ENABLE_GALLERY:"${ENABLE_GALLERY}",GA_ID:"${GA_ID}",LINKS_AK:"${LINKS_AK}",LINKS_SK:"${LINKS_SK}",UI_PUBLIC_ADDR:"${UI_PUBLIC_ADDR}",ENABLE_APPLY_ORG:"${ENABLE_APPLY_ORG}",I18N_ACCESS_ENV:"${I18N_ACCESS_ENV}",AI_BACKEND_URL:"${AI_BACKEND_URL}",AI_PROXY_CLIENT_AK:"${AI_PROXY_CLIENT_AK}",ERDA_AI_BACKEND_URL:"${ERDA_AI_BACKEND_URL}",DICE_CLUSTER_NAME:"${DICE_CLUSTER_NAME}"}</script>`,
);
if (TERMINUS_TA_ENABLE) {
const taContent = `
Expand Down
116 changes: 60 additions & 56 deletions shell/app/layout/stores/layout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { createStore } from 'core/cube';
import { inviteToOrg, getLicenses } from 'layout/services';
import * as DiceWebSocket from 'core/utils/ws';
import { enableIconfont, setApiWithOrg, goTo } from 'common/utils';
import { erdaEnv } from 'common/constants';
import routeInfoStore from 'core/stores/route';
import { find, merge } from 'lodash';
import JSEncrypt from 'jsencrypt';
Expand Down Expand Up @@ -155,77 +156,80 @@ const layout = createStore({
}
});

// Gets the authorized path
let features: string[] | null = null;
const enableLicense = `${erdaEnv.ENABLE_ERDA_LICENSE}` === 'true';
if (enableLicense) {
// Gets the authorized path
let features: string[] | null = null;

// if (currentOrg.id) {
// const res = await getLicenses({ scope: 'PLATFORM' });
// }
// if (currentOrg.id) {
// const res = await getLicenses({ scope: 'PLATFORM' });
// }

listenRoute(async ({ params }) => {
const { orgName } = params;
listenRoute(async ({ params }) => {
const { orgName } = params;

if (orgName && orgName !== '-' && !features) {
const res = await getLicenses({ scope: 'PLATFORM' });
if (orgName && orgName !== '-' && !features) {
const res = await getLicenses({ scope: 'PLATFORM' });

if (res.success) {
if (res.data) {
const jse = new JSEncrypt();
if (res.success) {
if (res.data) {
const jse = new JSEncrypt();

jse.setPrivateKey(PRIVATE_KEY);
const data = jse.decrypt(res.data);
if (data) {
const parseData = JSON.parse(data);
features = parseData.features;
}
} else {
const orgRes = await getLicenses({ scope: 'ORG' });
const jse = new JSEncrypt();
jse.setPrivateKey(PRIVATE_KEY);
const data = jse.decrypt(orgRes.data);
if (data) {
const parseData = JSON.parse(data);
features = parseData.features;
jse.setPrivateKey(PRIVATE_KEY);
const data = jse.decrypt(res.data);
if (data) {
const parseData = JSON.parse(data);
features = parseData.features;
}
} else {
features = [];
const orgRes = await getLicenses({ scope: 'ORG' });
const jse = new JSEncrypt();
jse.setPrivateKey(PRIVATE_KEY);
const data = jse.decrypt(orgRes.data);
if (data) {
const parseData = JSON.parse(data);
features = parseData.features;
} else {
features = [];
}
}
}
}
}
});
});

// Check whether the current path has permission
listenRoute(async ({ currentRoute, params }) => {
const { path } = currentRoute;
const { orgName } = params;
if (!features) {
return;
}
// Check whether the current path has permission
listenRoute(async ({ currentRoute, params }) => {
const { path } = currentRoute;
const { orgName } = params;
if (!features) {
return;
}

if (features.length) {
if (/\/:orgName\//.test(path)) {
const isMatch = features.some((feature) => {
const regexStr = feature.replace(/\*/g, '.+');
const regex = new RegExp('^' + regexStr + '$');
let remainingStr = path.replace(/^\/:orgName\//, '');
if (!remainingStr.includes('/')) {
remainingStr = `${remainingStr}/*`;
if (features.length) {
if (/\/:orgName\//.test(path)) {
const isMatch = features.some((feature) => {
const regexStr = feature.replace(/\*/g, '.+');
const regex = new RegExp('^' + regexStr + '$');
let remainingStr = path.replace(/^\/:orgName\//, '');
if (!remainingStr.includes('/')) {
remainingStr = `${remainingStr}/*`;
}
if (feature) {
return regex.test(remainingStr);
}
return false;
});
if (!isMatch) {
goTo(goTo.pages.noAuth);
}
if (feature) {
return regex.test(remainingStr);
}
return false;
});
if (!isMatch) {
}
} else {
if (/^\/:orgName\//.test(path) && orgName !== '-') {
goTo(goTo.pages.noAuth);
}
}
} else {
if (/^\/:orgName\//.test(path) && orgName !== '-') {
goTo(goTo.pages.noAuth);
}
}
});
});
}
},
effects: {
async notifyWs(_, payload: { ws: any; command: '__detach' | '__attach' }) {
Expand Down

0 comments on commit d7b5e84

Please sign in to comment.