diff --git a/backend/src/main/java/io/metersphere/service/GroupService.java b/backend/src/main/java/io/metersphere/service/GroupService.java index b83f64c3f6..06b1bbb529 100644 --- a/backend/src/main/java/io/metersphere/service/GroupService.java +++ b/backend/src/main/java/io/metersphere/service/GroupService.java @@ -197,7 +197,7 @@ public class GroupService { UserGroupExample userGroupExample = new UserGroupExample(); userGroupExample.createCriteria().andUserIdEqualTo(userId); List userGroups = userGroupMapper.selectByExample(userGroupExample); - List groupsIds = userGroups.stream().map(UserGroup::getGroupId).collect(Collectors.toList()); + List groupsIds = userGroups.stream().map(UserGroup::getGroupId).distinct().collect(Collectors.toList()); for (int i = 0; i < groupsIds.size(); i++) { String id = groupsIds.get(i); Group group = groupMapper.selectByPrimaryKey(id); diff --git a/backend/src/main/java/io/metersphere/service/OrganizationService.java b/backend/src/main/java/io/metersphere/service/OrganizationService.java index dcc3353734..04a3c009d0 100644 --- a/backend/src/main/java/io/metersphere/service/OrganizationService.java +++ b/backend/src/main/java/io/metersphere/service/OrganizationService.java @@ -208,7 +208,7 @@ public class OrganizationService { public OrganizationResource listResource(String groupId, String type) { Group group = groupMapper.selectByPrimaryKey(groupId); - final String orgId = group.getScopeId(); + String orgId = group.getScopeId(); OrganizationResource resource = new OrganizationResource(); if (!StringUtils.equals("global", orgId)) { Organization organization = organizationMapper.selectByPrimaryKey(orgId); diff --git a/backend/src/main/java/io/metersphere/service/UserService.java b/backend/src/main/java/io/metersphere/service/UserService.java index 1f11949e7f..79756816bf 100644 --- a/backend/src/main/java/io/metersphere/service/UserService.java +++ b/backend/src/main/java/io/metersphere/service/UserService.java @@ -402,7 +402,13 @@ public class UserService { UserRoleExample userRoleExample = new UserRoleExample(); userRoleExample.createCriteria().andUserIdEqualTo(userId); List userRoles = userRoleMapper.selectByExample(userRoleExample); - List list = userRoles.stream().map(UserRole::getSourceId).collect(Collectors.toList()); + + UserGroupExample userGroupExample = new UserGroupExample(); + userGroupExample.createCriteria().andUserIdEqualTo(userId); + List userGroups = userGroupMapper.selectByExample(userGroupExample); + List list = userGroups.stream().map(UserGroup::getSourceId).collect(Collectors.toList()); + +// List list = userRoles.stream().map(UserRole::getSourceId).collect(Collectors.toList()); if (!CollectionUtils.isEmpty(list)) { if (list.contains(user.getLastWorkspaceId()) || list.contains(user.getLastOrganizationId())) { user.setLastOrganizationId(""); @@ -411,10 +417,13 @@ public class UserService { } } - userRoleMapper.deleteByExample(userRoleExample); - List> roles = user.getRoles(); - if (!roles.isEmpty()) { - insertUserRole(roles, user.getId()); + userGroupMapper.deleteByExample(userGroupExample); +// userRoleMapper.deleteByExample(userRoleExample); +// List> roles = user.getRoles(); + List> groups = user.getGroups(); + if (!groups.isEmpty()) { + insertUserGroup(groups, user.getId()); +// insertUserRole(roles, user.getId()); } UserExample example = new UserExample(); diff --git a/backend/src/main/resources/db/migration/V85__v1.10_permission_refactor.sql b/backend/src/main/resources/db/migration/V85__v1.10_permission_refactor.sql index 55398910dd..4d7985ae93 100644 --- a/backend/src/main/resources/db/migration/V85__v1.10_permission_refactor.sql +++ b/backend/src/main/resources/db/migration/V85__v1.10_permission_refactor.sql @@ -45,19 +45,19 @@ CREATE TABLE IF NOT EXISTS `user_group_permission` INSERT INTO `group` (id, name, description, `system`, type, create_time, update_time, creator, scope_id) VALUES ('admin', '系统管理员', '默认用户组', 1, 'SYSTEM', 1621224000000, 1621224000000, 'admin', 'global'); INSERT INTO `group` (id, name, description, `system`, type, create_time, update_time, creator, scope_id) -VALUES ('org_admin', '组织管理员', '组织管理员', 1, 'ORGANIZATION', 1620674220001, 1620674220000, 'system', 'global'); +VALUES ('org_admin', '组织管理员', '组织管理员', 1, 'ORGANIZATION', 1620674220001, 1620674220000, 'admin', 'global'); INSERT INTO `group` (id, name, description, `system`, type, create_time, update_time, creator, scope_id) -VALUES ('org_member', '组织成员', '组织成员', 1, 'ORGANIZATION', 1620674220002, 1620674220000, 'system', 'global'); +VALUES ('org_member', '组织成员', '组织成员', 1, 'ORGANIZATION', 1620674220002, 1620674220000, 'admin', 'global'); INSERT INTO `group` (id, name, description, `system`, type, create_time, update_time, creator, scope_id) -VALUES ('project_admin', '项目管理员', '项目管理员', 1, 'PROJECT', 1620674220004, 1620674220000, 'system', 'global'); +VALUES ('project_admin', '项目管理员', '项目管理员', 1, 'PROJECT', 1620674220004, 1620674220000, 'admin', 'global'); INSERT INTO `group` (id, name, description, `system`, type, create_time, update_time, creator, scope_id) -VALUES ('project_member', '项目成员', '项目成员', 1, 'PROJECT', 1620674220005, 1620674220000, 'system', 'global'); +VALUES ('project_member', '项目成员', '项目成员', 1, 'PROJECT', 1620674220005, 1620674220000, 'admin', 'global'); INSERT INTO `group` (id, name, description, `system`, type, create_time, update_time, creator, scope_id) -VALUES ('read_only', '只读用户', '只读用户', 1, 'PROJECT', 1620674220006, 1620674220000, 'system', 'global'); +VALUES ('read_only', '只读用户', '只读用户', 1, 'PROJECT', 1620674220006, 1620674220000, 'admin', 'global'); INSERT INTO `group` (id, name, description, `system`, type, create_time, update_time, creator, scope_id) -VALUES ('ws_admin', '工作空间管理员', '工作空间管理员', 1, 'WORKSPACE', 1620674220007, 1620674220000, 'system', 'global'); +VALUES ('ws_admin', '工作空间管理员', '工作空间管理员', 1, 'WORKSPACE', 1620674220007, 1620674220000, 'admin', 'global'); INSERT INTO `group` (id, name, description, `system`, type, create_time, update_time, creator, scope_id) -VALUES ('ws_member', '工作空间成员', '工作空间成员', 1, 'WORKSPACE', 1620674220008, 1620674220000, 'system', 'global'); +VALUES ('ws_member', '工作空间成员', '工作空间成员', 1, 'WORKSPACE', 1620674220008, 1620674220000, 'admin', 'global'); -- 系统管理员 组织管理员 组织成员 @@ -94,8 +94,10 @@ WHERE role_id = 'test_user'; -- 只读用户 INSERT INTO user_group(id, user_id, group_id, source_id, create_time, update_time) -SELECT UUID(), user_id, 'read_only', source_id, create_time, update_time -FROM user_role +SELECT UUID(), user_id, 'read_only', project.id, w.create_time, w.update_time +FROM project + JOIN workspace w ON project.workspace_id = w.id + JOIN user_role ON source_id = workspace_id WHERE role_id = 'test_viewer'; diff --git a/frontend/src/business/components/settings/system/EditUser.vue b/frontend/src/business/components/settings/system/EditUser.vue index 019bb6daf7..30176b33db 100644 --- a/frontend/src/business/components/settings/system/EditUser.vue +++ b/frontend/src/business/components/settings/system/EditUser.vue @@ -199,7 +199,7 @@ export default { this.title = title ? title : this.title; if (type === 'Edit') { - this.$get('/user/group/all/' + encodeURIComponent(row.id), response => { + this.result = this.$get('/user/group/all/' + encodeURIComponent(row.id), response => { let data = response.data; this.$set(this.form, "groups", data); }); @@ -262,7 +262,8 @@ export default { createUser(createUserForm) { this.$refs[createUserForm].validate(valid => { if (valid) { - this.result = this.$post('/user/special/add', this.form, () => { + let url = this.type === 'Add' ? '/user/special/add' : '/user/special/update'; + this.result = this.$post(url, this.form, () => { this.$success(this.$t('commons.save_success')); this.$emit("refresh"); this.createVisible = false;