feat: Add roles column in projcet detail user list
Add roles column in project detail user list Change-Id: I0350d9ef021d6ac05c62e0a19cebf0fe3a289a10
This commit is contained in:
parent
63ef5d01e3
commit
ad4ef3c9fa
@ -65,17 +65,16 @@ export default class User extends Base {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
// {
|
{
|
||||||
// title: t('System Scope'),
|
title: t('Roles'),
|
||||||
// dataIndex: 'systemScope',
|
dataIndex: 'project_roles',
|
||||||
// isHideable: true,
|
isHideable: true,
|
||||||
// render: (systemScope) => {
|
render: (project_roles) => {
|
||||||
// if (systemScope === true) {
|
if (project_roles && project_roles[0]) {
|
||||||
// return 'All';
|
return project_roles.map((it) => <div>{it}</div>);
|
||||||
// }
|
}
|
||||||
// return '-';
|
},
|
||||||
// },
|
},
|
||||||
// },
|
|
||||||
{
|
{
|
||||||
title: t('True Name'),
|
title: t('True Name'),
|
||||||
dataIndex: 'full_name',
|
dataIndex: 'full_name',
|
||||||
@ -126,11 +125,14 @@ export default class User extends Base {
|
|||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
if (path.indexOf('role-admin/detail') === -1) {
|
if (!path.includes('role-admin/detail')) {
|
||||||
components.splice(1, 1);
|
components.splice(1, 1);
|
||||||
}
|
}
|
||||||
if (path.indexOf('user-admin') === -1) {
|
if (!path.includes('user-admin')) {
|
||||||
components.splice(4, 1);
|
components.splice(5, 1);
|
||||||
|
}
|
||||||
|
if (!path.includes('project-admin')) {
|
||||||
|
components.splice(2, 1);
|
||||||
}
|
}
|
||||||
return components;
|
return components;
|
||||||
};
|
};
|
||||||
@ -140,14 +142,14 @@ export default class User extends Base {
|
|||||||
match: { path },
|
match: { path },
|
||||||
} = this.props;
|
} = this.props;
|
||||||
if (
|
if (
|
||||||
path.indexOf('identity/user') >= 0 &&
|
path.includes('identity/user') &&
|
||||||
path.indexOf('identity/user-group') === -1
|
!path.includes('identity/user-group')
|
||||||
) {
|
) {
|
||||||
return this.isAdminPage
|
return this.isAdminPage
|
||||||
? actionConfigs.adminConfigs
|
? actionConfigs.adminConfigs
|
||||||
: actionConfigs.actionConfigs;
|
: actionConfigs.actionConfigs;
|
||||||
}
|
}
|
||||||
if (path.indexOf('domain-admin/detail') >= 0) {
|
if (path.includes('domain-admin/detail')) {
|
||||||
return this.isAdminPage
|
return this.isAdminPage
|
||||||
? actionConfigsInDomain.adminConfigs
|
? actionConfigsInDomain.adminConfigs
|
||||||
: actionConfigsInDomain.actionConfigs;
|
: actionConfigsInDomain.actionConfigs;
|
||||||
@ -178,19 +180,19 @@ export default class User extends Base {
|
|||||||
const { path } = match;
|
const { path } = match;
|
||||||
const newParams = { ...params };
|
const newParams = { ...params };
|
||||||
silent && (this.list.silent = true);
|
silent && (this.list.silent = true);
|
||||||
if (path.indexOf('domain-admin/detail') >= 0) {
|
if (path.includes('domain-admin/detail')) {
|
||||||
const { id } = match.params;
|
const { id } = match.params;
|
||||||
newParams.domainId = id;
|
newParams.domainId = id;
|
||||||
await this.store.fetchListInDomainDetail(newParams);
|
await this.store.fetchListInDomainDetail(newParams);
|
||||||
} else if (path.indexOf('project-admin/detail') >= 0) {
|
} else if (path.includes('project-admin/detail')) {
|
||||||
const { id } = match.params;
|
const { id } = match.params;
|
||||||
newParams.projectId = id;
|
newParams.projectId = id;
|
||||||
await this.store.fetchListInProjectDetail(newParams);
|
await this.store.fetchListInProjectDetail(newParams);
|
||||||
} else if (path.indexOf('user-group-admin/detail') >= 0) {
|
} else if (path.includes('user-group-admin/detail')) {
|
||||||
const { id } = match.params;
|
const { id } = match.params;
|
||||||
newParams.groupId = id;
|
newParams.groupId = id;
|
||||||
await this.store.fetchListInGroupDetail(newParams);
|
await this.store.fetchListInGroupDetail(newParams);
|
||||||
} else if (path.indexOf('role-admin/detail') >= 0) {
|
} else if (path.includes('role-admin/detail')) {
|
||||||
const { id } = match.params;
|
const { id } = match.params;
|
||||||
newParams.roleId = id;
|
newParams.roleId = id;
|
||||||
await this.store.fetchListInRoleDetail(newParams);
|
await this.store.fetchListInRoleDetail(newParams);
|
||||||
|
@ -76,7 +76,7 @@ export class UserStore extends Base {
|
|||||||
promiseList.push(globalGroupStore.addGroupUsers({ id, user_id }));
|
promiseList.push(globalGroupStore.addGroupUsers({ id, user_id }));
|
||||||
});
|
});
|
||||||
select_project.forEach((id) => {
|
select_project.forEach((id) => {
|
||||||
if (newProjects.indexOf(id) === -1) {
|
if (!newProjects.includes(id)) {
|
||||||
const role_id = defaultRole;
|
const role_id = defaultRole;
|
||||||
promiseList.push(
|
promiseList.push(
|
||||||
globalProjectStore.assignUserRole({ id, user_id, role_id })
|
globalProjectStore.assignUserRole({ id, user_id, role_id })
|
||||||
@ -152,8 +152,7 @@ export class UserStore extends Base {
|
|||||||
const { roles } = roleResult;
|
const { roles } = roleResult;
|
||||||
const systemRoles = roles.filter(
|
const systemRoles = roles.filter(
|
||||||
(it) =>
|
(it) =>
|
||||||
(it.name.indexOf('system_') !== -1 &&
|
(it.name.includes('system_') && !it.name.includes('_system_')) ||
|
||||||
it.name.indexOf('_system_') === -1) ||
|
|
||||||
it.name === 'admin'
|
it.name === 'admin'
|
||||||
);
|
);
|
||||||
const systemRoleId = systemRoles.map((it) => it.id);
|
const systemRoleId = systemRoles.map((it) => it.id);
|
||||||
@ -203,8 +202,7 @@ export class UserStore extends Base {
|
|||||||
const { roles } = roleResult;
|
const { roles } = roleResult;
|
||||||
const systemRoles = roles.filter(
|
const systemRoles = roles.filter(
|
||||||
(it) =>
|
(it) =>
|
||||||
(it.name.indexOf('system_') !== -1 &&
|
(it.name.includes('system_') && !it.name.includes('_system_')) ||
|
||||||
it.name.indexOf('_system_') === -1) ||
|
|
||||||
it.name === 'admin'
|
it.name === 'admin'
|
||||||
);
|
);
|
||||||
const systemRoleId = systemRoles.map((it) => it.id);
|
const systemRoleId = systemRoles.map((it) => it.id);
|
||||||
@ -232,8 +230,8 @@ export class UserStore extends Base {
|
|||||||
getUsersSystemRole = (projectMapRole, systemRoleId, projectMapSystemRole) => {
|
getUsersSystemRole = (projectMapRole, systemRoleId, projectMapSystemRole) => {
|
||||||
const systemProject = Object.keys(projectMapRole);
|
const systemProject = Object.keys(projectMapRole);
|
||||||
systemProject.forEach((project_id) => {
|
systemProject.forEach((project_id) => {
|
||||||
const roles = projectMapRole[project_id].filter(
|
const roles = projectMapRole[project_id].filter((role_id) =>
|
||||||
(role_id) => systemRoleId.indexOf(role_id) !== -1
|
systemRoleId.includes(role_id)
|
||||||
);
|
);
|
||||||
if (roles[0]) {
|
if (roles[0]) {
|
||||||
projectMapSystemRole[project_id] = roles;
|
projectMapSystemRole[project_id] = roles;
|
||||||
@ -292,8 +290,7 @@ export class UserStore extends Base {
|
|||||||
`${this.apiVersion}/projects/${project_id}/users/${id}/roles/`
|
`${this.apiVersion}/projects/${project_id}/users/${id}/roles/`
|
||||||
);
|
);
|
||||||
const systemRole = projectResult.roles.filter(
|
const systemRole = projectResult.roles.filter(
|
||||||
(it) =>
|
(it) => it.name.includes('system_') && !it.name.includes('_system_')
|
||||||
it.name.indexOf('system_') !== -1 && it.name.indexOf('_system_') === -1
|
|
||||||
);
|
);
|
||||||
this.systemRoles = systemRole;
|
this.systemRoles = systemRole;
|
||||||
}
|
}
|
||||||
@ -410,24 +407,32 @@ export class UserStore extends Base {
|
|||||||
this.list.isLoading = true;
|
this.list.isLoading = true;
|
||||||
const { projectId } = filters;
|
const { projectId } = filters;
|
||||||
const params = {};
|
const params = {};
|
||||||
const [roleAssignmentsReault, result] = await Promise.all([
|
const [roleAssignmentsReault, roleResult, result] = await Promise.all([
|
||||||
request.get(`${this.apiVersion}/role_assignments`),
|
request.get(`${this.apiVersion}/role_assignments`),
|
||||||
|
request.get(`${this.apiVersion}/roles`),
|
||||||
request.get(this.getListUrl(), params),
|
request.get(this.getListUrl(), params),
|
||||||
]);
|
]);
|
||||||
const projectUserIds = [];
|
const projectUserIds = [];
|
||||||
|
const userMapRole = {};
|
||||||
roleAssignmentsReault.role_assignments.forEach((roleAssignment) => {
|
roleAssignmentsReault.role_assignments.forEach((roleAssignment) => {
|
||||||
if (roleAssignment.user) {
|
if (roleAssignment.user) {
|
||||||
const {
|
const {
|
||||||
user: { id: user_id },
|
user: { id: user_id },
|
||||||
|
role: { id: role_id },
|
||||||
scope: { project: { id } = {} } = {},
|
scope: { project: { id } = {} } = {},
|
||||||
} = roleAssignment;
|
} = roleAssignment;
|
||||||
if (id && id === projectId) {
|
if (id && id === projectId) {
|
||||||
projectUserIds.push(user_id);
|
projectUserIds.push(user_id);
|
||||||
|
if (userMapRole[user_id]) {
|
||||||
|
userMapRole[user_id].push(role_id);
|
||||||
|
} else {
|
||||||
|
userMapRole[user_id] = [role_id];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
let data = get(result, this.listResponseKey, []);
|
let data = get(result, this.listResponseKey, []);
|
||||||
data = data.filter((it) => projectUserIds.indexOf(it.id) >= 0);
|
data = data.filter((it) => projectUserIds.includes(it.id));
|
||||||
const items = data.map(this.mapper);
|
const items = data.map(this.mapper);
|
||||||
const newData = await this.listDidFetch(items);
|
const newData = await this.listDidFetch(items);
|
||||||
Promise.all(
|
Promise.all(
|
||||||
@ -439,6 +444,9 @@ export class UserStore extends Base {
|
|||||||
const { projects } = projectResult[index];
|
const { projects } = projectResult[index];
|
||||||
it.projects = projects;
|
it.projects = projects;
|
||||||
it.project_num = projects.length;
|
it.project_num = projects.length;
|
||||||
|
it.project_roles = userMapRole[it.id].map(
|
||||||
|
(r) => roleResult.roles.filter((role) => role.id === r)[0].name
|
||||||
|
);
|
||||||
return it;
|
return it;
|
||||||
});
|
});
|
||||||
this.list.update({
|
this.list.update({
|
||||||
|
Loading…
Reference in New Issue
Block a user