refactor(系统设置): 用户组与用户关联表添加组织ID字段

This commit is contained in:
AgAngle 2023-08-31 17:39:56 +08:00 committed by fit2-zhao
parent 7ec75e8f92
commit 2b01c586b4
27 changed files with 189 additions and 80 deletions

View File

@ -30,6 +30,11 @@ public class UserRoleRelation implements Serializable {
@Size(min = 1, max = 50, message = "{user_role_relation.source_id.length_range}", groups = {Created.class, Updated.class})
private String sourceId;
@Schema(description = "记录所在的组织ID", requiredMode = Schema.RequiredMode.REQUIRED)
@NotBlank(message = "{user_role_relation.organization_id.not_blank}", groups = {Created.class})
@Size(min = 1, max = 50, message = "{user_role_relation.organization_id.length_range}", groups = {Created.class, Updated.class})
private String organizationId;
@Schema(description = "创建时间")
private Long createTime;
@ -43,6 +48,7 @@ public class UserRoleRelation implements Serializable {
userId("user_id", "userId", "VARCHAR", false),
roleId("role_id", "roleId", "VARCHAR", false),
sourceId("source_id", "sourceId", "VARCHAR", false),
organizationId("organization_id", "organizationId", "VARCHAR", false),
createTime("create_time", "createTime", "BIGINT", false),
createUser("create_user", "createUser", "VARCHAR", false);

View File

@ -384,6 +384,76 @@ public class UserRoleRelationExample {
return (Criteria) this;
}
public Criteria andOrganizationIdIsNull() {
addCriterion("organization_id is null");
return (Criteria) this;
}
public Criteria andOrganizationIdIsNotNull() {
addCriterion("organization_id is not null");
return (Criteria) this;
}
public Criteria andOrganizationIdEqualTo(String value) {
addCriterion("organization_id =", value, "organizationId");
return (Criteria) this;
}
public Criteria andOrganizationIdNotEqualTo(String value) {
addCriterion("organization_id <>", value, "organizationId");
return (Criteria) this;
}
public Criteria andOrganizationIdGreaterThan(String value) {
addCriterion("organization_id >", value, "organizationId");
return (Criteria) this;
}
public Criteria andOrganizationIdGreaterThanOrEqualTo(String value) {
addCriterion("organization_id >=", value, "organizationId");
return (Criteria) this;
}
public Criteria andOrganizationIdLessThan(String value) {
addCriterion("organization_id <", value, "organizationId");
return (Criteria) this;
}
public Criteria andOrganizationIdLessThanOrEqualTo(String value) {
addCriterion("organization_id <=", value, "organizationId");
return (Criteria) this;
}
public Criteria andOrganizationIdLike(String value) {
addCriterion("organization_id like", value, "organizationId");
return (Criteria) this;
}
public Criteria andOrganizationIdNotLike(String value) {
addCriterion("organization_id not like", value, "organizationId");
return (Criteria) this;
}
public Criteria andOrganizationIdIn(List<String> values) {
addCriterion("organization_id in", values, "organizationId");
return (Criteria) this;
}
public Criteria andOrganizationIdNotIn(List<String> values) {
addCriterion("organization_id not in", values, "organizationId");
return (Criteria) this;
}
public Criteria andOrganizationIdBetween(String value1, String value2) {
addCriterion("organization_id between", value1, value2, "organizationId");
return (Criteria) this;
}
public Criteria andOrganizationIdNotBetween(String value1, String value2) {
addCriterion("organization_id not between", value1, value2, "organizationId");
return (Criteria) this;
}
public Criteria andCreateTimeIsNull() {
addCriterion("create_time is null");
return (Criteria) this;

View File

@ -6,6 +6,7 @@
<result column="user_id" jdbcType="VARCHAR" property="userId" />
<result column="role_id" jdbcType="VARCHAR" property="roleId" />
<result column="source_id" jdbcType="VARCHAR" property="sourceId" />
<result column="organization_id" jdbcType="VARCHAR" property="organizationId" />
<result column="create_time" jdbcType="BIGINT" property="createTime" />
<result column="create_user" jdbcType="VARCHAR" property="createUser" />
</resultMap>
@ -68,7 +69,7 @@
</where>
</sql>
<sql id="Base_Column_List">
id, user_id, role_id, source_id, create_time, create_user
id, user_id, role_id, source_id, organization_id, create_time, create_user
</sql>
<select id="selectByExample" parameterType="io.metersphere.system.domain.UserRoleRelationExample" resultMap="BaseResultMap">
select
@ -102,11 +103,11 @@
</delete>
<insert id="insert" parameterType="io.metersphere.system.domain.UserRoleRelation">
insert into user_role_relation (id, user_id, role_id,
source_id, create_time, create_user
)
source_id, organization_id, create_time,
create_user)
values (#{id,jdbcType=VARCHAR}, #{userId,jdbcType=VARCHAR}, #{roleId,jdbcType=VARCHAR},
#{sourceId,jdbcType=VARCHAR}, #{createTime,jdbcType=BIGINT}, #{createUser,jdbcType=VARCHAR}
)
#{sourceId,jdbcType=VARCHAR}, #{organizationId,jdbcType=VARCHAR}, #{createTime,jdbcType=BIGINT},
#{createUser,jdbcType=VARCHAR})
</insert>
<insert id="insertSelective" parameterType="io.metersphere.system.domain.UserRoleRelation">
insert into user_role_relation
@ -123,6 +124,9 @@
<if test="sourceId != null">
source_id,
</if>
<if test="organizationId != null">
organization_id,
</if>
<if test="createTime != null">
create_time,
</if>
@ -143,6 +147,9 @@
<if test="sourceId != null">
#{sourceId,jdbcType=VARCHAR},
</if>
<if test="organizationId != null">
#{organizationId,jdbcType=VARCHAR},
</if>
<if test="createTime != null">
#{createTime,jdbcType=BIGINT},
</if>
@ -172,6 +179,9 @@
<if test="record.sourceId != null">
source_id = #{record.sourceId,jdbcType=VARCHAR},
</if>
<if test="record.organizationId != null">
organization_id = #{record.organizationId,jdbcType=VARCHAR},
</if>
<if test="record.createTime != null">
create_time = #{record.createTime,jdbcType=BIGINT},
</if>
@ -189,6 +199,7 @@
user_id = #{record.userId,jdbcType=VARCHAR},
role_id = #{record.roleId,jdbcType=VARCHAR},
source_id = #{record.sourceId,jdbcType=VARCHAR},
organization_id = #{record.organizationId,jdbcType=VARCHAR},
create_time = #{record.createTime,jdbcType=BIGINT},
create_user = #{record.createUser,jdbcType=VARCHAR}
<if test="_parameter != null">
@ -207,6 +218,9 @@
<if test="sourceId != null">
source_id = #{sourceId,jdbcType=VARCHAR},
</if>
<if test="organizationId != null">
organization_id = #{organizationId,jdbcType=VARCHAR},
</if>
<if test="createTime != null">
create_time = #{createTime,jdbcType=BIGINT},
</if>
@ -221,18 +235,19 @@
set user_id = #{userId,jdbcType=VARCHAR},
role_id = #{roleId,jdbcType=VARCHAR},
source_id = #{sourceId,jdbcType=VARCHAR},
organization_id = #{organizationId,jdbcType=VARCHAR},
create_time = #{createTime,jdbcType=BIGINT},
create_user = #{createUser,jdbcType=VARCHAR}
where id = #{id,jdbcType=VARCHAR}
</update>
<insert id="batchInsert" parameterType="map">
insert into user_role_relation
(id, user_id, role_id, source_id, create_time, create_user)
(id, user_id, role_id, source_id, organization_id, create_time, create_user)
values
<foreach collection="list" item="item" separator=",">
(#{item.id,jdbcType=VARCHAR}, #{item.userId,jdbcType=VARCHAR}, #{item.roleId,jdbcType=VARCHAR},
#{item.sourceId,jdbcType=VARCHAR}, #{item.createTime,jdbcType=BIGINT}, #{item.createUser,jdbcType=VARCHAR}
)
#{item.sourceId,jdbcType=VARCHAR}, #{item.organizationId,jdbcType=VARCHAR}, #{item.createTime,jdbcType=BIGINT},
#{item.createUser,jdbcType=VARCHAR})
</foreach>
</insert>
<insert id="batchInsertSelective" parameterType="map">
@ -257,6 +272,9 @@
<if test="'source_id'.toString() == column.value">
#{item.sourceId,jdbcType=VARCHAR}
</if>
<if test="'organization_id'.toString() == column.value">
#{item.organizationId,jdbcType=VARCHAR}
</if>
<if test="'create_time'.toString() == column.value">
#{item.createTime,jdbcType=BIGINT}
</if>

View File

@ -240,6 +240,7 @@ CREATE TABLE IF NOT EXISTS user_role_relation(
`user_id` VARCHAR(50) NOT NULL COMMENT '用户ID' ,
`role_id` VARCHAR(50) NOT NULL COMMENT '组ID' ,
`source_id` VARCHAR(50) NOT NULL COMMENT '组织或项目ID' ,
`organization_id` VARCHAR(50) NOT NULL COMMENT '记录所在的组织ID' ,
`create_time` BIGINT NOT NULL COMMENT '创建时间' ,
`create_user` VARCHAR(50) NOT NULL COMMENT '创建人' ,
PRIMARY KEY (id)

View File

@ -19,7 +19,7 @@ INSERT INTO user_role (id, name, description, internal, type, create_time, updat
INSERT INTO user_role (id, name, description, internal, type, create_time, update_time, create_user, scope_id) VALUES ('project_member', '项目成员', '项目成员', 1, 'PROJECT', 1620674220005, 1620674220000, 'admin', 'global');
-- 初始化用户和组的关系
INSERT INTO user_role_relation (id, user_id, role_id, source_id, create_time, create_user) VALUES (uuid(), 'admin', 'admin', 'system', 1684747668375, 'admin');
INSERT INTO user_role_relation (id, user_id, role_id, source_id, organization_id, create_time, create_user) VALUES (uuid(), 'admin', 'admin', 'system', 'system', 1684747668375, 'admin');
-- 初始化用户组权限
-- 系统管理员拥有所有的权限,不用初始化

View File

@ -17,11 +17,11 @@ import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.UUID;
import java.util.stream.Collectors;
import static io.metersphere.sdk.constants.InternalUserRole.ADMIN;
import static io.metersphere.sdk.controller.handler.result.CommonResultCode.*;
import static io.metersphere.sdk.controller.handler.result.CommonResultCode.USER_ROLE_RELATION_EXIST;
import static io.metersphere.sdk.controller.handler.result.CommonResultCode.USER_ROLE_RELATION_REMOVE_ADMIN_USER_PERMISSION;
/**
* @author jianxing
@ -39,14 +39,6 @@ public class BaseUserRoleRelationService {
@Resource
private BaseUserService baseUserService;
protected UserRoleRelation add(UserRoleRelation userRoleRelation) {
checkExist(userRoleRelation);
userRoleRelation.setCreateTime(System.currentTimeMillis());
userRoleRelation.setId(UUID.randomUUID().toString());
userRoleRelationMapper.insert(userRoleRelation);
return userRoleRelation;
}
/**
* 校验用户是否已在当前用户组
*/

View File

@ -150,7 +150,7 @@ public class BaseUserRoleService {
*
* @param userRole
*/
public void delete(UserRole userRole, String defaultRoleId, String currentUserId) {
public void delete(UserRole userRole, String defaultRoleId, String currentUserId, String orgId) {
String id = userRole.getId();
checkInternalUserRole(userRole);
@ -161,7 +161,7 @@ public class BaseUserRoleService {
userRoleMapper.deleteByPrimaryKey(id);
// 检查是否只有一个用户组如果是则添加系统成员等默认用户组
checkOneLimitRole(id, defaultRoleId, currentUserId);
checkOneLimitRole(id, defaultRoleId, currentUserId, orgId);
// 删除用户组与用户的关联关系
baseUserRoleRelationService.deleteByRoleId(id);
@ -206,7 +206,7 @@ public class BaseUserRoleService {
* @param defaultRoleId 默认用户组id
* @param currentUserId 当前用户id
*/
public void checkOneLimitRole(String roleId, String defaultRoleId, String currentUserId) {
public void checkOneLimitRole(String roleId, String defaultRoleId, String currentUserId, String orgId) {
// 查询要删除的用户组关联的用户ID
List<String> userIds = baseUserRoleRelationService.getUserIdByRoleId(roleId);
@ -232,6 +232,7 @@ public class BaseUserRoleService {
relation.setRoleId(defaultRoleId);
relation.setCreateTime(System.currentTimeMillis());
relation.setCreateUser(currentUserId);
relation.setOrganizationId(orgId);
addRelations.add(relation);
}
});

View File

@ -146,7 +146,7 @@ public class ProjectMemberService {
// 操作记录
List<LogDTO> logs = new ArrayList<>();
// 项目不存在
checkProjectExist(request.getProjectId());
Project project = checkProjectExist(request.getProjectId());
// 移除已经存在的用户组
UserRoleRelationExample example = new UserRoleRelationExample();
example.createCriteria().andSourceIdEqualTo(request.getProjectId())
@ -168,6 +168,7 @@ public class ProjectMemberService {
relation.setSourceId(request.getProjectId());
relation.setCreateTime(System.currentTimeMillis());
relation.setCreateUser(currentUserId);
relation.setOrganizationId(project.getOrganizationId());
relations.add(relation);
});
if (!CollectionUtils.isEmpty(relations)) {
@ -230,7 +231,7 @@ public class ProjectMemberService {
// 操作记录
List<LogDTO> logs = new ArrayList<>();
// 项目不存在, 则不添加
checkProjectExist(request.getProjectId());
Project project = checkProjectExist(request.getProjectId());
// 获取已经存在的用户组
UserRoleRelationExample example = new UserRoleRelationExample();
example.createCriteria().andSourceIdEqualTo(request.getProjectId())
@ -260,6 +261,7 @@ public class ProjectMemberService {
relation.setSourceId(request.getProjectId());
relation.setCreateTime(System.currentTimeMillis());
relation.setCreateUser(currentUserId);
relation.setOrganizationId(project.getOrganizationId());
relations.add(relation);
isLog.set(true);
roleIds.add(roleId);
@ -306,11 +308,12 @@ public class ProjectMemberService {
* 查看项目是否存在
* @param projectId 项目ID
*/
private void checkProjectExist(String projectId) {
private Project checkProjectExist(String projectId) {
Project project = projectMapper.selectByPrimaryKey(projectId);
if (project == null) {
throw new MSException(Translator.get("project_not_exist"));
}
return project;
}
/**

View File

@ -10,5 +10,5 @@ INSERT INTO user_role (id, name, description, internal, type, create_time, updat
VALUES ('PROJECT', '项目级别权限校验', '', 1, 'PROJECT', 1620674220005, 1620674220000, 'admin', 'global');
-- 初始化用户和组的关系
INSERT INTO user_role_relation (id, user_id, role_id, source_id, create_time, create_user)
SELECT 'PROJECT', 'PROJECT', 'PROJECT', id, 1684747668375, 'admin' FROM project WHERE num = 100001;
INSERT INTO user_role_relation (id, user_id, role_id, source_id, organization_id, create_time, create_user)
SELECT 'PROJECT', 'PROJECT', 'PROJECT', id, organization_id, 1684747668375, 'admin' FROM project WHERE num = 100001;

View File

@ -21,10 +21,10 @@ replace INTO project (id, num, organization_id, name, description, create_user,
# 插入测试数据 给组织增加成员
replace INTO user_role_relation (id, user_id, role_id, source_id, create_time, create_user )VALUES ('user_role_relation1','admin1','org_admin','default_organization','1684747668321','admin');
replace INTO user_role_relation (id, user_id, role_id, source_id, create_time, create_user )VALUES ('user_role_relation2','delete','org_admin','default_organization','1684747668321','admin');
replace INTO user_role_relation (id, user_id, role_id, source_id, create_time, create_user )VALUES ('user_role_relation6','delete','project_member','projectId1','1684747668321','admin');
replace INTO user_role_relation (id, user_id, role_id, source_id, create_time, create_user )VALUES ('user_role_relation3','admin1','project_member','projectId1','1684747668321','admin');
replace INTO user_role_relation (id, user_id, role_id, source_id, create_time, create_user )VALUES ('user_role_relation4','admin1','project_member','projectId2','1684747668321','admin');
replace INTO user_role_relation (id, user_id, role_id, source_id, create_time, create_user )VALUES ('user_role_relation5','admin1','project_member','projectId3','1684747668321','admin');
replace INTO user_role_relation (id, user_id, role_id, source_id, organization_id, create_time, create_user )VALUES ('user_role_relation1','admin1','org_admin','default_organization','default_organization','1684747668321','admin');
replace INTO user_role_relation (id, user_id, role_id, source_id, organization_id, create_time, create_user )VALUES ('user_role_relation2','delete','org_admin','default_organization','default_organization','1684747668321','admin');
replace INTO user_role_relation (id, user_id, role_id, source_id, organization_id, create_time, create_user )VALUES ('user_role_relation6','delete','project_member','projectId1','default_organization','1684747668321','admin');
replace INTO user_role_relation (id, user_id, role_id, source_id, organization_id, create_time, create_user )VALUES ('user_role_relation3','admin1','project_member','projectId1','default_organization','1684747668321','admin');
replace INTO user_role_relation (id, user_id, role_id, source_id, organization_id, create_time, create_user )VALUES ('user_role_relation4','admin1','project_member','projectId2','default_organization','1684747668321','admin');
replace INTO user_role_relation (id, user_id, role_id, source_id, organization_id, create_time, create_user )VALUES ('user_role_relation5','admin1','project_member','projectId3','default_organization','1684747668321','admin');
replace INTO user_role_permission(id, role_id, permission_id) VALUES ('user_role_permission1','project_member','PROJECT_BASE_INFO:READ');

View File

@ -10,14 +10,14 @@ INSERT INTO user(id, name, email, password, create_time, update_time, language,
('default-project-member-user-2', 'default-project-member-user2', 'project-member2@metersphere.io', MD5('metersphere'), UNIX_TIMESTAMP() * 1000, UNIX_TIMESTAMP() * 1000, NULL, NUll, '', 'LOCAL', NULL, 'admin', 'admin', 0),
('default-project-member-user-del', 'default-project-member-userDel', 'project-member-del@metersphere.io', MD5('metersphere'), UNIX_TIMESTAMP() * 1000, UNIX_TIMESTAMP() * 1000, NULL, NUll, '', 'LOCAL', NULL, 'admin', 'admin', 1);
INSERT INTO user_role_relation (id, user_id, role_id, source_id, create_time, create_user) VALUES
(UUID(), 'default-project-member-user-1', 'org_member', 'default-organization-member-test', UNIX_TIMESTAMP() * 1000, 'admin'),
(UUID(), 'default-project-member-user-2', 'org_member', 'default-organization-member-test', UNIX_TIMESTAMP() * 1000, 'admin');
INSERT INTO user_role_relation (id, user_id, role_id, source_id, organization_id, create_time, create_user) VALUES
(UUID(), 'default-project-member-user-1', 'org_member', 'default-organization-member-test', 'default_organization', UNIX_TIMESTAMP() * 1000, 'admin'),
(UUID(), 'default-project-member-user-2', 'org_member', 'default-organization-member-test', 'default_organization', UNIX_TIMESTAMP() * 1000, 'admin');
INSERT INTO user_role_relation (id, user_id, role_id, source_id, create_time, create_user) VALUES
(UUID(), 'default-project-member-user-1', 'project_admin', 'default-project-member-test', UNIX_TIMESTAMP() * 1000, 'admin'),
(UUID(), 'default-project-member-user-2', 'project_admin', 'default-project-member-test', UNIX_TIMESTAMP() * 1000, 'admin'),
(UUID(), 'default-project-member-user-del', 'project_admin', 'default-project-member-test', UNIX_TIMESTAMP() * 1000, 'admin');
INSERT INTO user_role_relation (id, user_id, role_id, source_id, organization_id, create_time, create_user) VALUES
(UUID(), 'default-project-member-user-1', 'project_admin', 'default-project-member-test', 'default_organization', UNIX_TIMESTAMP() * 1000, 'admin'),
(UUID(), 'default-project-member-user-2', 'project_admin', 'default-project-member-test', 'default_organization', UNIX_TIMESTAMP() * 1000, 'admin'),
(UUID(), 'default-project-member-user-del', 'project_admin', 'default-project-member-test', 'default_organization', UNIX_TIMESTAMP() * 1000, 'admin');

View File

@ -143,6 +143,7 @@ public class CommonProjectService {
memberRole.setSourceId(orgId);
memberRole.setCreateTime(System.currentTimeMillis());
memberRole.setCreateUser(createUser);
memberRole.setOrganizationId(orgId);
userRoleRelation.add(memberRole);
LogDTO logDTO = new LogDTO(orgId, orgId, memberRole.getId(), createUser, OperationLogType.ADD.name(), module, Translator.get("add") + Translator.get("organization_member") + ": " + nameMap.get(id));
setLog(logDTO, path, HttpMethodConstants.POST.name(), logDTOList);
@ -312,6 +313,7 @@ public class CommonProjectService {
adminRole.setSourceId(projectId);
adminRole.setCreateTime(System.currentTimeMillis());
adminRole.setCreateUser(createUser);
adminRole.setOrganizationId(project.getOrganizationId());
userRoleRelations.add(adminRole);
LogDTO logDTO = new LogDTO(projectId, project.getOrganizationId(), adminRole.getId(), createUser, type, module, content + Translator.get("project_admin") + ": " + nameMap.get(userId));
setLog(logDTO, path, HttpMethodConstants.POST.name(), logDTOList);
@ -367,6 +369,7 @@ public class CommonProjectService {
memberRole.setSourceId(projectId);
memberRole.setCreateTime(System.currentTimeMillis());
memberRole.setCreateUser(createUser);
memberRole.setOrganizationId(project.getOrganizationId());
userRoleRelations.add(memberRole);
LogDTO logDTO = new LogDTO(projectId, project.getOrganizationId(), memberRole.getId(), createUser, type, module, content + Translator.get("project_member") + ": " + userMap.get(userId));
setLog(logDTO, path, HttpMethodConstants.POST.name(), logDTOList);

View File

@ -79,6 +79,7 @@ public class GlobalUserRoleRelationService extends BaseUserRoleRelationService {
checkExist(userRoleRelation);
userRoleRelation.setCreateTime(System.currentTimeMillis());
userRoleRelation.setId(UUID.randomUUID().toString());
userRoleRelation.setOrganizationId(UserRoleScope.SYSTEM);
userRoleRelations.add(userRoleRelation);
});
userRoleRelationMapper.batchInsert(userRoleRelations);
@ -116,6 +117,7 @@ public class GlobalUserRoleRelationService extends BaseUserRoleRelationService {
userRoleRelation.setCreateTime(createTime);
userRoleRelation.setSourceId(UserRoleScope.SYSTEM);
userRoleRelation.setId(UUID.randomUUID().toString());
userRoleRelation.setOrganizationId(UserRoleScope.SYSTEM);
saveList.add(userRoleRelation);
}
}

View File

@ -114,7 +114,7 @@ public class GlobalUserRoleService extends BaseUserRoleService {
public void delete(String id, String currentUserId) {
UserRole userRole = getWithCheck(id);
checkGlobalUserRole(userRole);
super.delete(userRole, MEMBER.getValue(), currentUserId);
super.delete(userRole, MEMBER.getValue(), currentUserId, UserRoleScope.SYSTEM);
}
public void checkRoleIsGlobalAndHaveMember(@Valid @NotEmpty List<String> roleIdList, boolean isSystem) {

View File

@ -186,6 +186,7 @@ public class OrganizationService {
userRoleRelation.setRoleId(InternalUserRole.ORG_MEMBER.getValue());
userRoleRelation.setCreateTime(System.currentTimeMillis());
userRoleRelation.setCreateUser(createUserId);
userRoleRelation.setOrganizationId(organizationId);
userRoleRelations.add(userRoleRelation);
}
});
@ -336,6 +337,7 @@ public class OrganizationService {
List<UserRoleRelation> userRoleRelations = userRoleRelationMapper.selectByExample(example);
if (CollectionUtils.isEmpty(userRoleRelations)) {
UserRoleRelation userRoleRelation = buildUserRoleRelation(createUserId, memberId, organizationId, userRoleId);
userRoleRelation.setOrganizationId(organizationId);
userRoleRelationMapper.insert(userRoleRelation);
//add Log
String path = add ? "/organization/add-member" : "/organization/role/update-member";
@ -399,6 +401,7 @@ public class OrganizationService {
List<UserRoleRelation> userRoleRelations = userRoleRelationMapper.selectByExample(example);
if (CollectionUtils.isEmpty(userRoleRelations)) {
UserRoleRelation userRoleRelation = buildUserRoleRelation(userId, memberId, projectId, InternalUserRole.PROJECT_MEMBER.getValue());
userRoleRelation.setOrganizationId(orgMemberExtendProjectRequest.getOrganizationId());
userRoleRelationMapper.insert(userRoleRelation);
//add Log
LogDTO dto = new LogDTO(
@ -563,6 +566,7 @@ public class OrganizationService {
UserRoleRelationMapper userRoleRelationMapper = sqlSession.getMapper(UserRoleRelationMapper.class);
projectInDBInOrgIds.forEach(projectId -> {
UserRoleRelation userRoleRelation = buildUserRoleRelation(createUserId, memberId, projectId, InternalUserRole.PROJECT_MEMBER.getValue());
userRoleRelation.setOrganizationId(organizationId);
userRoleRelationMapper.insert(userRoleRelation);
//add Log
String path = "/organization/update-member";
@ -601,6 +605,7 @@ public class OrganizationService {
UserRoleRelationMapper userRoleRelationMapper = sqlSession.getMapper(UserRoleRelationMapper.class);
userRoleInDBInOrgIds.forEach(userRoleId -> {
UserRoleRelation userRoleRelation = buildUserRoleRelation(createUserId, memberId, organizationId, userRoleId);
userRoleRelation.setOrganizationId(organizationId);
userRoleRelationMapper.insert(userRoleRelation);
//add Log
String path = "/organization/update-member";

View File

@ -78,7 +78,7 @@ public class OrganizationUserRoleService extends BaseUserRoleService {
UserRole userRole = get(roleId);
// 非组织用户组不允许删除, 内置用户组不允许删除
checkOrgUserRole(userRole);
super.delete(userRole, InternalUserRole.ORG_MEMBER.getValue(), currentUserId);
super.delete(userRole, InternalUserRole.ORG_MEMBER.getValue(), currentUserId, userRole.getScopeId());
}
public List<UserExtend> getMember(String organizationId, String roleId) {
@ -124,6 +124,7 @@ public class OrganizationUserRoleService extends BaseUserRoleService {
relation.setSourceId(request.getOrganizationId());
relation.setCreateTime(System.currentTimeMillis());
relation.setCreateUser(createUserId);
relation.setOrganizationId(request.getOrganizationId());
userRoleRelationMapper.insert(relation);
});
}

View File

@ -89,6 +89,7 @@ public class UserRoleRelationService {
userRoleRelation.setSourceId(UserRoleScope.SYSTEM);
userRoleRelation.setCreateTime(operationTime);
userRoleRelation.setCreateUser(user.getCreateUser());
userRoleRelation.setOrganizationId(UserRoleScope.SYSTEM);
userRoleRelationSaveList.add(userRoleRelation);
}
}
@ -170,6 +171,7 @@ public class UserRoleRelationService {
userRoleRelation.setSourceId(UserRoleScope.SYSTEM);
userRoleRelation.setCreateTime(System.currentTimeMillis());
userRoleRelation.setCreateUser(operator);
userRoleRelation.setOrganizationId(UserRoleScope.SYSTEM);
saveList.add(userRoleRelation);
}
}

View File

@ -374,6 +374,7 @@ class GlobalUserRoleControllerTests extends BaseTest {
roleRelation.setCreateUser(ADMIN.getValue());
roleRelation.setUserId(user.getId());
roleRelation.setSourceId(UserRoleScope.SYSTEM);
roleRelation.setOrganizationId(UserRoleScope.SYSTEM);
userRoleRelationMapper.insert(roleRelation);
return roleRelation;
}

View File

@ -121,6 +121,7 @@ class GlobalUserRoleRelationControllerTests extends BaseTest {
List<UserRoleRelation> userRoleRelations = getUserRoleRelationByRoleIdAndUserId(request.getRoleId(), ADMIN.getValue());
Assertions.assertTrue(CollectionUtils.isNotEmpty(userRoleRelations));
addUserRoleRelation = userRoleRelations.get(0);
Assertions.assertEquals(addUserRoleRelation.getOrganizationId(), UserRoleScope.SYSTEM);
// @@校验日志
checkLog(addUserRoleRelation.getRoleId(), OperationLogType.UPDATE);
@ -223,6 +224,7 @@ class GlobalUserRoleRelationControllerTests extends BaseTest {
userRoleRelation.setUserId(ADMIN.getValue());
userRoleRelation.setCreateTime(System.currentTimeMillis());
userRoleRelation.setSourceId(UUID.randomUUID().toString());
userRoleRelation.setOrganizationId(UserRoleScope.SYSTEM);
userRoleRelationMapper.insert(userRoleRelation);
return userRoleRelation;
}
@ -238,6 +240,7 @@ class GlobalUserRoleRelationControllerTests extends BaseTest {
userRoleRelation.setCreateUser(ADMIN.getValue());
userRoleRelation.setCreateTime(System.currentTimeMillis());
userRoleRelation.setSourceId(UUID.randomUUID().toString());
userRoleRelation.setOrganizationId(UserRoleScope.SYSTEM);
userRoleRelationMapper.insert(userRoleRelation);
return userRoleRelation;
}

View File

@ -9,7 +9,7 @@ INSERT INTO project (id, num, organization_id, name, description, create_user, u
('default-project-delete', null, 'default-organization-delete2', '默认项目', '系统默认创建的项目', 'admin', 'admin', UNIX_TIMESTAMP() * 1000, UNIX_TIMESTAMP() * 1000);
INSERT INTO user_role(id, name, description, internal, type, create_time, update_time, create_user, scope_id) VALUE
('default-org-role-delete-id', 'default-org-role-delete', 'XXX', FALSE, 'ORGANIZATION', UNIX_TIMESTAMP() * 1000, UNIX_TIMESTAMP() * 1000, 'admin', 'default-organization-delete2');
INSERT INTO user_role_relation (id, user_id, role_id, source_id, create_time, create_user) VALUE
(UUID(), 'admin', 'default-org-role-delete-id', 'default-organization-delete2', UNIX_TIMESTAMP() * 1000, 'admin');
INSERT INTO user_role_relation (id, user_id, role_id, source_id, organization_id, create_time, create_user) VALUE
(UUID(), 'admin', 'default-org-role-delete-id', 'default-organization-delete2', 'default-organization-delete2', UNIX_TIMESTAMP() * 1000, 'admin');
INSERT INTO user_role_permission (id, role_id, permission_id) VALUE
(uuid(), 'default-org-role-delete-id', 'ORGANIZATION_USER_ROLE:READ');

View File

@ -3,7 +3,7 @@ INSERT INTO `project` VALUES ('projectId1', null, '3a5b1bd3-05e5-11ee-ad96-0242a
INSERT INTO project (id, num, organization_id, name, description, create_user, update_user, create_time, update_time, delete_time,deleted) VALUES ('projectId6', null, (SELECT id FROM organization WHERE name LIKE '默认组织'), '默认项目6', '系统默认创建的项目', 'admin', 'admin', unix_timestamp() * 1000, unix_timestamp() * 1000, 1683464436000 , 1);
INSERT INTO user_role(id, name, description, internal, type, create_time, update_time, create_user, scope_id) VALUE
('default-pro-role-delete-id', 'default-pro-role-delete', 'XXX', FALSE, 'PROJECT', UNIX_TIMESTAMP() * 1000, UNIX_TIMESTAMP() * 1000, 'admin', 'projectId6');
INSERT INTO user_role_relation (id, user_id, role_id, source_id, create_time, create_user) VALUE
(UUID(), 'admin', 'default-pro-role-delete-id', 'projectId6', UNIX_TIMESTAMP() * 1000, 'admin');
INSERT INTO user_role_relation (id, user_id, role_id, source_id, organization_id, create_time, create_user) VALUE
(UUID(), 'admin', 'default-pro-role-delete-id', 'projectId6', (SELECT id FROM organization WHERE name LIKE '默认组织'), UNIX_TIMESTAMP() * 1000, 'admin');
INSERT INTO user_role_permission (id, role_id, permission_id) VALUE
(uuid(), 'default-pro-role-delete-id', 'ORGANIZATION_USER_ROLE:READ');

View File

@ -25,7 +25,7 @@ replace INTO project (id, num, organization_id, name, description, create_user,
# 插入测试数据 给组织增加成员
replace INTO user_role_relation (id, user_id, role_id, source_id, create_time, create_user )VALUES ('c3bb9b4f-46d8-4952-9681-1213333131','admin2','org_member',(SELECT id FROM organization WHERE name LIKE '默认组织'),'1684747668321','admin');
replace INTO user_role_relation (id, user_id, role_id, source_id, create_time, create_user )VALUES ('c3bb9b4f-46d8-4952-9681-3124121332','admin1','org_member',(SELECT id FROM organization WHERE name LIKE '默认组织'),'1684747668321','admin');
replace INTO user_role_relation (id, user_id, role_id, source_id, organization_id, create_time, create_user )VALUES ('c3bb9b4f-46d8-4952-9681-1213333131','admin2','org_member', (SELECT id FROM organization WHERE name LIKE '默认组织'), (SELECT id FROM organization WHERE name LIKE '默认组织'), '1684747668321','admin');
replace INTO user_role_relation (id, user_id, role_id, source_id, organization_id, create_time, create_user )VALUES ('c3bb9b4f-46d8-4952-9681-3124121332','admin1','org_member', (SELECT id FROM organization WHERE name LIKE '默认组织'), (SELECT id FROM organization WHERE name LIKE '默认组织'), '1684747668321','admin');
INSERT INTO organization(id,num, name, description, create_time, update_time, create_user, update_user, delete_user, delete_time) VALUE
('default-organization-20',null, 'default-20', 'XXX-1', UNIX_TIMESTAMP() * 1000, UNIX_TIMESTAMP() * 1000, 'admin', 'admin', null, null);

View File

@ -13,7 +13,7 @@ INSERT INTO organization(id, num, name, description, create_time, update_time, c
('default-organization-6',null, 'default-6', 'XXX-6', UNIX_TIMESTAMP() * 1000, UNIX_TIMESTAMP() * 1000, 'admin', 'admin', null, null);
INSERT INTO user(id, name, email, password, create_time, update_time, language, last_organization_id, phone, source, last_project_id, create_user, update_user) VALUE
('default-admin', 'default-Administrator', 'admin-default@metersphere.io', MD5('metersphere'), UNIX_TIMESTAMP() * 1000, UNIX_TIMESTAMP() * 1000, NULL, NUll, '', 'LOCAL', NULL, 'admin', 'admin');
INSERT INTO user_role_relation (id, user_id, role_id, source_id, create_time, create_user) VALUE
(UUID(), 'default-admin', 'org_admin', 'default-organization-2', UNIX_TIMESTAMP() * 1000, 'admin');
INSERT INTO user_role_relation (id, user_id, role_id, source_id, organization_id, create_time, create_user) VALUE
(UUID(), 'default-admin', 'org_admin', 'default-organization-2', 'default-organization-2', UNIX_TIMESTAMP() * 1000, 'admin');
INSERT INTO project (id, num, organization_id, name, description, create_user, update_user, create_time, update_time) VALUE
('default-project', null, 'default-organization-2', '默认项目', '系统默认创建的项目', 'admin', 'admin', UNIX_TIMESTAMP() * 1000, UNIX_TIMESTAMP() * 1000);

View File

@ -11,9 +11,9 @@ INSERT INTO user(id, name, email, password, create_time, update_time, language,
('default-admin-user', 'default-Administrator-1', 'admin-default-user@metersphere.io', MD5('metersphere'), UNIX_TIMESTAMP() * 1000, UNIX_TIMESTAMP() * 1000, NULL, NUll, '', 'LOCAL', NULL, 'admin', 'admin');
INSERT INTO user_role_permission (id, role_id, permission_id) VALUE
(uuid(), 'default-org-role-id-3', 'ORGANIZATION_USER_ROLE:READ');
INSERT INTO user_role_relation (id, user_id, role_id, source_id, create_time, create_user) VALUE
(UUID(), 'default-admin-user', 'default-org-role-id-3', 'default-organization-2', UNIX_TIMESTAMP() * 1000, 'admin');
INSERT INTO user_role_relation (id, user_id, role_id, source_id, create_time, create_user) VALUE
(UUID(), 'default-admin-user', 'default-org-role-id-4', 'default-organization-2', UNIX_TIMESTAMP() * 1000, 'admin');
INSERT INTO user_role_relation (id, user_id, role_id, source_id, create_time, create_user) VALUE
(UUID(), 'default-admin-user-x', 'default-org-role-id-4', 'default-organization-2', UNIX_TIMESTAMP() * 1000, 'admin');
INSERT INTO user_role_relation (id, user_id, role_id, source_id, organization_id, create_time, create_user) VALUE
(UUID(), 'default-admin-user', 'default-org-role-id-3', 'default-organization-2', 'default-organization-2', UNIX_TIMESTAMP() * 1000, 'admin');
INSERT INTO user_role_relation (id, user_id, role_id, source_id, organization_id, create_time, create_user) VALUE
(UUID(), 'default-admin-user', 'default-org-role-id-4', 'default-organization-2', 'default-organization-2', UNIX_TIMESTAMP() * 1000, 'admin');
INSERT INTO user_role_relation (id, user_id, role_id, source_id, organization_id, create_time, create_user) VALUE
(UUID(), 'default-admin-user-x', 'default-org-role-id-4', 'default-organization-2', 'default-organization-2', UNIX_TIMESTAMP() * 1000, 'admin');

View File

@ -10,8 +10,8 @@ INSERT INTO user_role (id, name, description, internal, type, create_time, updat
VALUES ('SYSTEM', '系统级别权限校验', '', 1, 'SYSTEM', 1620674220005, 1620674220000, 'admin', 'global');
-- 初始化用户和组的关系
INSERT INTO user_role_relation (id, user_id, role_id, source_id, create_time, create_user)
VALUES ('SYSTEM', 'SYSTEM', 'SYSTEM', 'system', 1684747668375, 'admin');
INSERT INTO user_role_relation (id, user_id, role_id, source_id, organization_id, create_time, create_user)
VALUES ('SYSTEM', 'SYSTEM', 'SYSTEM', 'system', 'system', 1684747668375, 'admin');
-- 初始化用于权限测试的组织用户
INSERT INTO user(id, name, email, password, create_time, update_time, language, last_organization_id, phone, source,
@ -25,6 +25,5 @@ INSERT INTO user_role (id, name, description, internal, type, create_time, updat
VALUES ('ORGANIZATION', '组织级别权限校验', '', 1, 'ORGANIZATION', 1620674220005, 1620674220000, 'admin', 'global');
-- 初始化用户和组的关系
INSERT INTO user_role_relation (id, user_id, role_id, source_id, create_time, create_user)
SELECT 'ORGANIZATION', 'ORGANIZATION', 'ORGANIZATION', id, 1684747668375, 'admin' FROM organization WHERE num = 100001;
INSERT INTO user_role_relation (id, user_id, role_id, source_id, organization_id, create_time, create_user)
SELECT 'ORGANIZATION', 'ORGANIZATION', 'ORGANIZATION', id, id, 1684747668375, 'admin' FROM organization WHERE num = 100001;

View File

@ -22,6 +22,8 @@ VALUES ('test', 'test', 'admin3@metersphere.io', MD5('admin2@metersphere.io'),
UNIX_TIMESTAMP() * 1000, UNIX_TIMESTAMP() * 1000, NULL, NUll, '', 'LOCAL', NULL, 'admin', 'admin');
replace
INTO user_role_relation VALUES ('c3bb9b4f-46d8-4952-9681-8889974487w','admin1','project_admin','projectId1','1684747668375','1684747668375');
INTO user_role_relation(id, user_id, role_id, source_id, organization_id, create_time, create_user)
VALUES ('c3bb9b4f-46d8-4952-9681-8889974487w','admin1','project_admin','projectId1', (SELECT id FROM organization WHERE name LIKE '默认组织'), '1684747668375','1684747668375');
replace
INTO user_role_relation VALUES ('c3bb9b4f-46d8-4952-9681-8889974487q','admin2','project_admin','projectId1','1684747668321','1684747668336');
INTO user_role_relation(id, user_id, role_id, source_id, organization_id, create_time, create_user)
VALUES ('c3bb9b4f-46d8-4952-9681-8889974487q','admin2','project_admin','projectId1', (SELECT id FROM organization WHERE name LIKE '默认组织'), '1684747668321','1684747668336');

View File

@ -48,6 +48,6 @@ INSERT INTO user_role(id, name, description, internal, type, create_time, update
INSERT INTO user_role(id, name, description, internal, type, create_time, update_time, create_user, scope_id) VALUE
('sys_default_org_role_id_8', 'sys_default_org_role_id_8', 'XXX', FALSE, 'ORGANIZATION', UNIX_TIMESTAMP() * 1000, UNIX_TIMESTAMP() * 1000, 'admin', 'sys_default_organization_7');
INSERT INTO user_role_relation(id, user_id, role_id, source_id, create_time, create_user) VALUE
('gyq_user_role_relation_test', 'sys_default_user4', 'sys_default_org_role_id_5', 'sys_default_organization_6', UNIX_TIMESTAMP() * 1000, 'admin');
INSERT INTO user_role_relation(id, user_id, role_id, source_id, organization_id, create_time, create_user) VALUE
('gyq_user_role_relation_test', 'sys_default_user4', 'sys_default_org_role_id_5', 'sys_default_organization_6', 'sys_default_organization_6', UNIX_TIMESTAMP() * 1000, 'admin');