Skip to content

Commit

Permalink
adjust msp router & add member manage & add notify-group manage (#1046)
Browse files Browse the repository at this point in the history
* feat(msp): add member manage

* feat(msp): adjust msp router

feat(msp): remove service analysis

* feat(msp): notify group

fix(msp): mamber manage

fix(msp): remove mock

fix(msp): remove cconsole

* fix(msp): add locales
  • Loading branch information
Zero-Rock authored Sep 6, 2021
1 parent 4bb99ad commit 9c7eaee
Show file tree
Hide file tree
Showing 102 changed files with 588 additions and 158 deletions.
4 changes: 4 additions & 0 deletions cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"captcha",
"Cascader",
"cerr",
"chaxunfenxi",
"chenweitao",
"chunkhash",
"CIDR",
Expand Down Expand Up @@ -92,7 +93,9 @@
"fangfa",
"filemanager",
"filetree",
"fuwuguancesvg",
"fwsl",
"gaojingguanli",
"getrule",
"gittar",
"Glusterfs",
Expand All @@ -109,6 +112,7 @@
"Hiragino",
"holderjs",
"hoverable",
"huanjinggailan",
"huidaodingbu",
"iconfont",
"iconpark",
Expand Down
2 changes: 2 additions & 0 deletions shell/app/common/components/add-member-modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { insertWhen } from '../utils';
import { getApps } from 'common/services';
import { useMount } from 'react-use';
import { Alert, message } from 'core/nusi';
import mspProjectMember from 'common/stores/msp-project-member';

interface IProps {
visible: boolean;
Expand All @@ -41,6 +42,7 @@ const storeMap = {
[MemberScope.ORG]: orgMemberStore,
[MemberScope.APP]: appMemberStore,
[MemberScope.SYS]: sysMemberStore,
[MemberScope.MSP]: mspProjectMember,
};

export const AddMemberModal = ({
Expand Down
2 changes: 2 additions & 0 deletions shell/app/common/components/authorize-member-modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import sysMemberStore from 'common/stores/sys-member';
import React from 'react';
import { useTempPaging } from './use-hooks';
import { useEffectOnce } from 'react-use';
import mspProjectMember from 'common/stores/msp-project-member';

const { Option } = Select;

Expand All @@ -37,6 +38,7 @@ const storeMap = {
[MemberScope.PROJECT]: projectMemberStore,
[MemberScope.ORG]: orgMemberStore,
[MemberScope.APP]: appMemberStore,
[MemberScope.MSP]: mspProjectMember,
[MemberScope.SYS]: sysMemberStore,
};

Expand Down
7 changes: 7 additions & 0 deletions shell/app/common/components/member-selector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,13 @@ import orgStore from 'app/org-home/stores/org';
import userStore from 'app/user/stores';
import sysMemberStore from 'common/stores/sys-member';
import { useUserMap } from 'core/stores/userMap';
import mspProjectMember from 'common/stores/msp-project-member';

const storeMap = {
[MemberScope.PROJECT]: projectMemberStore,
[MemberScope.ORG]: orgMemberStore,
[MemberScope.APP]: appMemberStore,
[MemberScope.MSP]: mspProjectMember,
[MemberScope.SYS]: sysMemberStore,
};

Expand Down Expand Up @@ -387,6 +389,11 @@ export const AddMemberSelector = (props: IAddProps) => {
scopeType: MemberScope.ORG,
scopeId: orgId,
},
[MemberScope.MSP]: {
// 添加项目成员:从org成员中选择
scopeType: MemberScope.ORG,
scopeId: orgId,
},
[MemberScope.APP]: {
// 添加项目成员:从project中选择
scopeType: MemberScope.PROJECT,
Expand Down
16 changes: 15 additions & 1 deletion shell/app/common/components/members-table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,13 @@ import memberLabelStore from 'common/stores/member-label';
import orgStore from 'app/org-home/stores/org';
import './members-table.scss';
import { FULL_ROOT_DOMAIN } from '../constants';
import mspProjectMember from 'common/stores/msp-project-member';

const storeMap = {
[MemberScope.ORG]: orgMemberStore,
[MemberScope.PROJECT]: projectMemberStore,
[MemberScope.APP]: appMemberStore,
[MemberScope.MSP]: mspProjectMember,
[MemberScope.SYS]: sysMemberStore,
};

Expand Down Expand Up @@ -82,7 +84,11 @@ export const MembersTable = ({
const currentOrg = orgStore.useStore((s) => s.currentOrg);
const { id: orgId, name: orgName, displayName: orgDisplayName } = currentOrg;

const [projectMemberPerm, appMemberPerm] = usePerm((s) => [s.project.member, s.app.member]);
const [projectMemberPerm, appMemberPerm, mspProjectMemberPerm] = usePerm((s) => [
s.project.member,
s.app.member,
s.project.microService.member,
]);
const { id: currentUserId } = loginUser;
const { params } = routeInfoStore.getState((s) => s);
const isAdminManager = scopeKey === MemberScope.SYS && loginUser.adminRoles.includes('Manager');
Expand Down Expand Up @@ -116,6 +122,7 @@ export const MembersTable = ({
[MemberScope.ORG]: String(orgId),
[MemberScope.PROJECT]: `${params.projectId || ''}`,
[MemberScope.APP]: `${params.appId || ''}`,
[MemberScope.MSP]: `${params.projectId || ''}`,
};

const scopeId = scopeIdMap[scopeKey];
Expand All @@ -140,6 +147,13 @@ export const MembersTable = ({
showAuthorize: false, // 应用级别无授权
invite: false,
},
[MemberScope.MSP]: {
add: mspProjectMemberPerm.addProjectMember.pass,
edit: mspProjectMemberPerm.editProjectMember.pass,
delete: mspProjectMemberPerm.removeProjectMember.pass,
showAuthorize: false,
invite: false,
},
};
const memberAuth = { ...memberAuthMap[scopeKey], ...overwriteAuth };

Expand Down
44 changes: 36 additions & 8 deletions shell/app/common/services/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
// along with this program. If not, see <http://www.gnu.org/licenses/>.

import agent from 'agent';
import { MemberScope } from 'common/stores/member-scope';

interface IPlatformUser {
avatar: string;
Expand All @@ -38,10 +39,28 @@ export const fetchLog = ({
.then((response: any) => response.body);
};

const convert = (payload: MEMBER.UpdateMemberBody) => {
if (payload.scope.type === MemberScope.MSP) {
return {
...payload,
scope: {
...payload.scope,
type: MemberScope.PROJECT,
},
};
}
return payload;
};

export function getMembers(payload: MEMBER.GetListServiceQuery) {
const url = payload.scopeType === MemberScope.MSP ? '/api/msp/members' : '/api/members';
const newPayload = { ...payload };
if (newPayload.scopeType === MemberScope.MSP) {
newPayload.scopeType = MemberScope.PROJECT;
}
return agent
.get('/api/members')
.query(payload)
.get(url)
.query(newPayload)
.then((response: any) => response.body);
}

Expand All @@ -64,23 +83,31 @@ export const searchPlatformUserList = (
};

export function getRoleMap(payload: MEMBER.GetRoleTypeQuery): IPagingResp<MEMBER.IRoleType> {
const url =
payload.scopeType === MemberScope.MSP ? '/api/msp/members/action/list-roles' : '/api/members/actions/list-roles';
const newPayload = { ...payload };
if (newPayload.scopeType === MemberScope.MSP) {
newPayload.scopeType = MemberScope.PROJECT;
}
return agent
.get('/api/members/actions/list-roles')
.query(payload)
.get(url)
.query(newPayload)
.then((response: any) => response.body);
}

export function updateMembers(payload: MEMBER.UpdateMemberBody) {
const url = payload.scope.type === MemberScope.MSP ? '/api/msp/members' : '/api/members';
return agent
.post('/api/members')
.send({ ...payload, options: { rewrite: true } }) // 接口上写死options.rewrite=true,避免新增用户(已有的用户)设置角色无用
.post(url)
.send({ ...convert(payload), options: { rewrite: true } }) // 接口上写死options.rewrite=true,避免新增用户(已有的用户)设置角色无用
.then((response: any) => response.body);
}

export function removeMember(payload: MEMBER.RemoveMemberBody) {
const url = payload.scope.type === MemberScope.MSP ? '/api/msp/members/action/remove' : '/api/members/actions/remove';
return agent
.post('/api/members/actions/remove')
.send(payload)
.post(url)
.send(convert(payload))
.then((response: any) => response.body);
}

Expand Down Expand Up @@ -137,3 +164,4 @@ export const getRenderPageLayout = (payload: CONFIG_PAGE.RenderConfig) => {
.send(payload)
.then((response: any) => response.body);
};
// can ignore the default pageSize
1 change: 1 addition & 0 deletions shell/app/common/stores/member-scope.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@ export enum MemberScope {
ORG = 'org',
PROJECT = 'project',
APP = 'app',
MSP = 'msp',
SYS = 'sys',
}
19 changes: 19 additions & 0 deletions shell/app/common/stores/msp-project-member.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright (c) 2021 Terminus, Inc.
//
// This program is free software: you can use, redistribute, and/or modify
// it under the terms of the GNU Affero General Public License, version 3
// or later ("AGPL"), as published by the Free Software Foundation.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.

import { createMemberStore } from 'common/stores/_member';
import { MemberScope } from 'app/common/stores/member-scope';

const mspProjectMember = createMemberStore(MemberScope.MSP);

export default mspProjectMember;
6 changes: 4 additions & 2 deletions shell/app/common/types/member.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
// along with this program. If not, see <http://www.gnu.org/licenses/>.

declare namespace MEMBER {
type ScopeType = import('common/stores/member-scope').MemberScope;
interface GetListQuery extends Partial<ScopeObj> {
pageNo: number;
scope: MemberScope;
Expand All @@ -28,7 +29,7 @@ declare namespace MEMBER {
interface GetListServiceQuery {
pageNo: number;
pageSize: number;
scopeType: string;
scopeType: ScopeType;
scopeId: string;
role?: string[];
q?: string;
Expand All @@ -46,7 +47,7 @@ declare namespace MEMBER {

interface MemberScope {
id: string;
type: string;
type: ScopeType;
}

interface UpdateMemberBody {
Expand All @@ -59,6 +60,7 @@ declare namespace MEMBER {
}

interface RemoveMemberBody {
scopeType: ScopeType;
scope: MemberScope;
userIds: string[];
}
Expand Down
3 changes: 2 additions & 1 deletion shell/app/common/utils/go-to.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ export enum pages {
mspOverviewRoot = '/{orgName}/msp/{projectId}/{env}/{tenantGroup}',
mspOverview = '/{orgName}/msp/{projectId}/{env}/{tenantGroup}?appId={appId}&runtimeId={runtimeId}',
mspApiStrategy = '/{orgName}/msp/{projectId}/{env}/{tenantGroup}/gateway/api-package/{packageId}/detail/api-policies/safety-policy',
mspProjectNotifyGroup = '/{orgName}/msp/{projectId}/{env}/{tenantGroup}/alarm-management/{terminusKey}/notify-group',
mspTopology = '/{orgName}/msp/{projectId}/{env}/{tenantGroup}/topology/{terminusKey}?appId={appId}',
monitorAPIOverview = '/{orgName}/msp/{projectId}/{env}/{tenantGroup}/gateway/apis/api-monitor?appId={appId}&runtimeId={runtimeId}',
microTraceSearch = '/{orgName}/msp/{projectId}/{env}/{tenantGroup}/monitor/{terminusKey}/trace/search?appId={appId}&timeFrom={timeFrom}&timeTo={timeTo}&status={status}',
Expand Down Expand Up @@ -245,7 +246,7 @@ export enum pages {
micro_serviceCustomDashboardDetail = '/{orgName}/msp/{projectId}/{env}/{tenantGroup}/monitor/{terminusKey}/custom-dashboard/{customDashboardId}',

// 微服务-服务分析页
mspServiceAnalyze = '/{orgName}/msp/{projectId}/{env}/{tenantGroup}/monitor/{terminusKey}/service-list/{applicationId}/{serviceId}/{serviceName}',
mspServiceAnalyze = '/{orgName}/msp/{projectId}/{env}/{tenantGroup}/synopsis/{terminusKey}/service-list/{applicationId}/{serviceId}/{serviceName}',

// 企业日志分析规则
addLogAnalyzeRule = '/{orgName}/cmp/log/rule/add?source={source}',
Expand Down
1 change: 1 addition & 0 deletions shell/app/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -2168,6 +2168,7 @@
"node traffic management": "node traffic management",
"normal": "normal",
"not satisfied": "not satisfied",
"notification group management": "notification group management",
"number of connection": "number of connection",
"number of errors": "number of errors",
"number of occurrences": "number of occurrences",
Expand Down
2 changes: 2 additions & 0 deletions shell/app/locales/zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -1413,6 +1413,7 @@
"default": "默认",
"default value": "默认值",
"delete": "删除",
"delete {name}": "删除{name}",
"delete certificate": "删除证书",
"deleted": "已删除",
"deleted successfully": "删除成功",
Expand Down Expand Up @@ -2168,6 +2169,7 @@
"node traffic management": "节点流量管理",
"normal": "正常",
"not satisfied": "不满意",
"notification group management": "通知组管理",
"number of connection": "连接数",
"number of errors": "错误次数",
"number of occurrences": "发生次数",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
import React from 'react';
import moment from 'moment';
import i18n from 'i18n';
import { isEmpty, map, take, head } from 'lodash';
import { Spin, Modal, Tooltip, Select, Table, Button, message } from 'core/nusi';
import { ErdaCustomIcon, Avatar, useSwitch, FormModal, useUpdate, MemberSelector } from 'common';
import { FormInstance, ColumnProps } from 'core/common/interface';
import { head, isEmpty, map, take } from 'lodash';
import { Button, message, Modal, Select, Spin, Table, Tooltip } from 'core/nusi';
import { Avatar, ErdaCustomIcon, FormModal, MemberSelector, useSwitch, useUpdate } from 'common';
import { ColumnProps, FormInstance } from 'core/common/interface';
import { useMount, useUnmount } from 'react-use';
import { useUserMap } from 'core/stores/userMap';
import { useLoading } from 'core/stores/loading';
Expand Down Expand Up @@ -85,6 +85,7 @@ interface IProps {
commonPayload: {
scopeType: string;
scopeId: string;
projectId?: string;
};
memberStore: any;
}
Expand Down Expand Up @@ -179,9 +180,23 @@ const NotifyGroup = ({ memberStore, commonPayload }: IProps) => {
});
const isEditing = !isEmpty(activedData);

const isInMsp = commonPayload.scopeType.includes('msp');

const memberSelectProps = isInMsp
? {
scopeType: 'msp',
scopeId: commonPayload.projectId,
}
: commonPayload;

const scope = isInMsp ? 'msp' : commonPayload.scopeType;

useMount(() => {
handleGetNotifyGroups();
getRoleMap({ scopeType: commonPayload.scopeType, scopeId: commonPayload.scopeId });
getRoleMap({
scopeType: scope,
scopeId: commonPayload.scopeId,
});
});

useUnmount(() => {
Expand Down Expand Up @@ -356,7 +371,7 @@ const NotifyGroup = ({ memberStore, commonPayload }: IProps) => {
label: groupTargetMap[groupType],
required: true,
getComp: () => {
return <MemberSelector {...commonPayload} mode="multiple" type="Category" />;
return <MemberSelector {...memberSelectProps} mode="multiple" type="Category" />;
},
};
break;
Expand Down
Loading

0 comments on commit 9c7eaee

Please sign in to comment.