fix(系统设置): 用户编辑问题

This commit is contained in:
shiziyuan9527 2021-05-21 16:19:34 +08:00 committed by 刘瑞斌
parent 0e1ffbf873
commit f6c566f77a
5 changed files with 30 additions and 18 deletions

View File

@ -197,7 +197,7 @@ public class GroupService {
UserGroupExample userGroupExample = new UserGroupExample(); UserGroupExample userGroupExample = new UserGroupExample();
userGroupExample.createCriteria().andUserIdEqualTo(userId); userGroupExample.createCriteria().andUserIdEqualTo(userId);
List<UserGroup> userGroups = userGroupMapper.selectByExample(userGroupExample); List<UserGroup> userGroups = userGroupMapper.selectByExample(userGroupExample);
List<String> groupsIds = userGroups.stream().map(UserGroup::getGroupId).collect(Collectors.toList()); List<String> groupsIds = userGroups.stream().map(UserGroup::getGroupId).distinct().collect(Collectors.toList());
for (int i = 0; i < groupsIds.size(); i++) { for (int i = 0; i < groupsIds.size(); i++) {
String id = groupsIds.get(i); String id = groupsIds.get(i);
Group group = groupMapper.selectByPrimaryKey(id); Group group = groupMapper.selectByPrimaryKey(id);

View File

@ -208,7 +208,7 @@ public class OrganizationService {
public OrganizationResource listResource(String groupId, String type) { public OrganizationResource listResource(String groupId, String type) {
Group group = groupMapper.selectByPrimaryKey(groupId); Group group = groupMapper.selectByPrimaryKey(groupId);
final String orgId = group.getScopeId(); String orgId = group.getScopeId();
OrganizationResource resource = new OrganizationResource(); OrganizationResource resource = new OrganizationResource();
if (!StringUtils.equals("global", orgId)) { if (!StringUtils.equals("global", orgId)) {
Organization organization = organizationMapper.selectByPrimaryKey(orgId); Organization organization = organizationMapper.selectByPrimaryKey(orgId);

View File

@ -402,7 +402,13 @@ public class UserService {
UserRoleExample userRoleExample = new UserRoleExample(); UserRoleExample userRoleExample = new UserRoleExample();
userRoleExample.createCriteria().andUserIdEqualTo(userId); userRoleExample.createCriteria().andUserIdEqualTo(userId);
List<UserRole> userRoles = userRoleMapper.selectByExample(userRoleExample); List<UserRole> userRoles = userRoleMapper.selectByExample(userRoleExample);
List<String> list = userRoles.stream().map(UserRole::getSourceId).collect(Collectors.toList());
UserGroupExample userGroupExample = new UserGroupExample();
userGroupExample.createCriteria().andUserIdEqualTo(userId);
List<UserGroup> userGroups = userGroupMapper.selectByExample(userGroupExample);
List<String> list = userGroups.stream().map(UserGroup::getSourceId).collect(Collectors.toList());
// List<String> list = userRoles.stream().map(UserRole::getSourceId).collect(Collectors.toList());
if (!CollectionUtils.isEmpty(list)) { if (!CollectionUtils.isEmpty(list)) {
if (list.contains(user.getLastWorkspaceId()) || list.contains(user.getLastOrganizationId())) { if (list.contains(user.getLastWorkspaceId()) || list.contains(user.getLastOrganizationId())) {
user.setLastOrganizationId(""); user.setLastOrganizationId("");
@ -411,10 +417,13 @@ public class UserService {
} }
} }
userRoleMapper.deleteByExample(userRoleExample); userGroupMapper.deleteByExample(userGroupExample);
List<Map<String, Object>> roles = user.getRoles(); // userRoleMapper.deleteByExample(userRoleExample);
if (!roles.isEmpty()) { // List<Map<String, Object>> roles = user.getRoles();
insertUserRole(roles, user.getId()); List<Map<String, Object>> groups = user.getGroups();
if (!groups.isEmpty()) {
insertUserGroup(groups, user.getId());
// insertUserRole(roles, user.getId());
} }
UserExample example = new UserExample(); UserExample example = new UserExample();

View File

@ -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) INSERT INTO `group` (id, name, description, `system`, type, create_time, update_time, creator, scope_id)
VALUES ('admin', '系统管理员', '默认用户组', 1, 'SYSTEM', 1621224000000, 1621224000000, 'admin', 'global'); VALUES ('admin', '系统管理员', '默认用户组', 1, 'SYSTEM', 1621224000000, 1621224000000, 'admin', 'global');
INSERT INTO `group` (id, name, description, `system`, type, create_time, update_time, creator, scope_id) 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) 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) 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) 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) 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) 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) 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) 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 SELECT UUID(), user_id, 'read_only', project.id, w.create_time, w.update_time
FROM user_role FROM project
JOIN workspace w ON project.workspace_id = w.id
JOIN user_role ON source_id = workspace_id
WHERE role_id = 'test_viewer'; WHERE role_id = 'test_viewer';

View File

@ -199,7 +199,7 @@ export default {
this.title = title ? title : this.title; this.title = title ? title : this.title;
if (type === 'Edit') { 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; let data = response.data;
this.$set(this.form, "groups", data); this.$set(this.form, "groups", data);
}); });
@ -262,7 +262,8 @@ export default {
createUser(createUserForm) { createUser(createUserForm) {
this.$refs[createUserForm].validate(valid => { this.$refs[createUserForm].validate(valid => {
if (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.$success(this.$t('commons.save_success'));
this.$emit("refresh"); this.$emit("refresh");
this.createVisible = false; this.createVisible = false;