feat(系统设置): 用户组相关接口设计
This commit is contained in:
parent
2d7bbc53f9
commit
4f0efcd411
|
@ -44,5 +44,9 @@ public class UserRole implements Serializable {
|
|||
@Size(min = 1, max = 50, message = "{user_role.scope_id.length_range}", groups = {Created.class, Updated.class})
|
||||
private String scopeId;
|
||||
|
||||
@Schema(title = "自定义排序,间隔5000", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotNull(message = "{user_role.pos.not_blank}", groups = {Created.class})
|
||||
private Long pos;
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
}
|
|
@ -703,6 +703,66 @@ public class UserRoleExample {
|
|||
addCriterion("scope_id not between", value1, value2, "scopeId");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andPosIsNull() {
|
||||
addCriterion("pos is null");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andPosIsNotNull() {
|
||||
addCriterion("pos is not null");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andPosEqualTo(Long value) {
|
||||
addCriterion("pos =", value, "pos");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andPosNotEqualTo(Long value) {
|
||||
addCriterion("pos <>", value, "pos");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andPosGreaterThan(Long value) {
|
||||
addCriterion("pos >", value, "pos");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andPosGreaterThanOrEqualTo(Long value) {
|
||||
addCriterion("pos >=", value, "pos");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andPosLessThan(Long value) {
|
||||
addCriterion("pos <", value, "pos");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andPosLessThanOrEqualTo(Long value) {
|
||||
addCriterion("pos <=", value, "pos");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andPosIn(List<Long> values) {
|
||||
addCriterion("pos in", values, "pos");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andPosNotIn(List<Long> values) {
|
||||
addCriterion("pos not in", values, "pos");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andPosBetween(Long value1, Long value2) {
|
||||
addCriterion("pos between", value1, value2, "pos");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andPosNotBetween(Long value1, Long value2) {
|
||||
addCriterion("pos not between", value1, value2, "pos");
|
||||
return (Criteria) this;
|
||||
}
|
||||
}
|
||||
|
||||
public static class Criteria extends GeneratedCriteria {
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
<result column="update_time" jdbcType="BIGINT" property="updateTime" />
|
||||
<result column="create_user" jdbcType="VARCHAR" property="createUser" />
|
||||
<result column="scope_id" jdbcType="VARCHAR" property="scopeId" />
|
||||
<result column="pos" jdbcType="BIGINT" property="pos" />
|
||||
</resultMap>
|
||||
<sql id="Example_Where_Clause">
|
||||
<where>
|
||||
|
@ -72,7 +73,7 @@
|
|||
</sql>
|
||||
<sql id="Base_Column_List">
|
||||
id, `name`, description, internal, `type`, create_time, update_time, create_user,
|
||||
scope_id
|
||||
scope_id, pos
|
||||
</sql>
|
||||
<select id="selectByExample" parameterType="io.metersphere.system.domain.UserRoleExample" resultMap="BaseResultMap">
|
||||
select
|
||||
|
@ -107,12 +108,12 @@
|
|||
<insert id="insert" parameterType="io.metersphere.system.domain.UserRole">
|
||||
insert into user_role (id, `name`, description,
|
||||
internal, `type`, create_time,
|
||||
update_time, create_user, scope_id
|
||||
)
|
||||
update_time, create_user, scope_id,
|
||||
pos)
|
||||
values (#{id,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR}, #{description,jdbcType=VARCHAR},
|
||||
#{internal,jdbcType=BIT}, #{type,jdbcType=VARCHAR}, #{createTime,jdbcType=BIGINT},
|
||||
#{updateTime,jdbcType=BIGINT}, #{createUser,jdbcType=VARCHAR}, #{scopeId,jdbcType=VARCHAR}
|
||||
)
|
||||
#{updateTime,jdbcType=BIGINT}, #{createUser,jdbcType=VARCHAR}, #{scopeId,jdbcType=VARCHAR},
|
||||
#{pos,jdbcType=BIGINT})
|
||||
</insert>
|
||||
<insert id="insertSelective" parameterType="io.metersphere.system.domain.UserRole">
|
||||
insert into user_role
|
||||
|
@ -144,6 +145,9 @@
|
|||
<if test="scopeId != null">
|
||||
scope_id,
|
||||
</if>
|
||||
<if test="pos != null">
|
||||
pos,
|
||||
</if>
|
||||
</trim>
|
||||
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||
<if test="id != null">
|
||||
|
@ -173,6 +177,9 @@
|
|||
<if test="scopeId != null">
|
||||
#{scopeId,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="pos != null">
|
||||
#{pos,jdbcType=BIGINT},
|
||||
</if>
|
||||
</trim>
|
||||
</insert>
|
||||
<select id="countByExample" parameterType="io.metersphere.system.domain.UserRoleExample" resultType="java.lang.Long">
|
||||
|
@ -211,6 +218,9 @@
|
|||
<if test="record.scopeId != null">
|
||||
scope_id = #{record.scopeId,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="record.pos != null">
|
||||
pos = #{record.pos,jdbcType=BIGINT},
|
||||
</if>
|
||||
</set>
|
||||
<if test="_parameter != null">
|
||||
<include refid="Update_By_Example_Where_Clause" />
|
||||
|
@ -226,7 +236,8 @@
|
|||
create_time = #{record.createTime,jdbcType=BIGINT},
|
||||
update_time = #{record.updateTime,jdbcType=BIGINT},
|
||||
create_user = #{record.createUser,jdbcType=VARCHAR},
|
||||
scope_id = #{record.scopeId,jdbcType=VARCHAR}
|
||||
scope_id = #{record.scopeId,jdbcType=VARCHAR},
|
||||
pos = #{record.pos,jdbcType=BIGINT}
|
||||
<if test="_parameter != null">
|
||||
<include refid="Update_By_Example_Where_Clause" />
|
||||
</if>
|
||||
|
@ -258,6 +269,9 @@
|
|||
<if test="scopeId != null">
|
||||
scope_id = #{scopeId,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="pos != null">
|
||||
pos = #{pos,jdbcType=BIGINT},
|
||||
</if>
|
||||
</set>
|
||||
where id = #{id,jdbcType=VARCHAR}
|
||||
</update>
|
||||
|
@ -270,7 +284,8 @@
|
|||
create_time = #{createTime,jdbcType=BIGINT},
|
||||
update_time = #{updateTime,jdbcType=BIGINT},
|
||||
create_user = #{createUser,jdbcType=VARCHAR},
|
||||
scope_id = #{scopeId,jdbcType=VARCHAR}
|
||||
scope_id = #{scopeId,jdbcType=VARCHAR},
|
||||
pos = #{pos,jdbcType=BIGINT}
|
||||
where id = #{id,jdbcType=VARCHAR}
|
||||
</update>
|
||||
</mapper>
|
|
@ -34,6 +34,7 @@ CREATE TABLE user_role
|
|||
`update_time` BIGINT NOT NULL COMMENT '更新时间',
|
||||
`create_user` VARCHAR(50) NOT NULL COMMENT '创建人(操作人)',
|
||||
`scope_id` VARCHAR(50) NOT NULL COMMENT '应用范围',
|
||||
`pos` BIGINT NOT NULL DEFAULT 0 COMMENT '自定义排序,间隔5000' ,
|
||||
PRIMARY KEY (id)
|
||||
) ENGINE = InnoDB
|
||||
DEFAULT CHARSET = utf8mb4
|
||||
|
@ -456,4 +457,4 @@ CREATE TABLE plugin_blob
|
|||
|
||||
|
||||
-- set innodb lock wait timeout to default
|
||||
SET SESSION innodb_lock_wait_timeout = DEFAULT;
|
||||
SET SESSION innodb_lock_wait_timeout = DEFAULT;
|
||||
|
|
|
@ -1,7 +1,24 @@
|
|||
package io.metersphere.sdk.constants;
|
||||
|
||||
/**
|
||||
* @author jianxing
|
||||
*/
|
||||
public class PermissionConstants {
|
||||
|
||||
/*------ start: SYSTEM_USER_ROLE ------*/
|
||||
public static final String SYSTEM_USER_ROLE_READ = "SYSTEM_USER_ROLE:READ";
|
||||
public static final String SYSTEM_USER_ROLE_ADD = "SYSTEM_USER_ROLE:READ+ADD";
|
||||
public static final String SYSTEM_USER_ROLE_UPDATE = "SYSTEM_USER_ROLE:READ+UPDATE";
|
||||
public static final String SYSTEM_USER_ROLE_DELETE = "SYSTEM_USER_ROLE:READ+DELETE";
|
||||
/*------ end: SYSTEM_USER_ROLE ------*/
|
||||
|
||||
/*------ start: SYSTEM_USER_ROLE_RELATION ------*/
|
||||
public static final String SYSTEM_USER_ROLE_RELATION_READ = "SYSTEM_USER_ROLE_RELATION_READ:READ";
|
||||
public static final String SYSTEM_USER_ROLE_RELATION_ADD = "SYSTEM_USER_ROLE_RELATION_READ:READ+ADD";
|
||||
public static final String SYSTEM_USER_ROLE_RELATION_UPDATE = "SYSTEM_USER_ROLE_RELATION_READ:READ+UPDATE";
|
||||
public static final String SYSTEM_USER_ROLE_RELATION_DELETE = "SYSTEM_USER_ROLE_RELATION_READ:READ+DELETE";
|
||||
/*------ end: SYSTEM_USER_ROLE_RELATION ------*/
|
||||
|
||||
public static final String SYSTEM_USER_READ = "SYSTEM_USER:READ";
|
||||
public static final String SYSTEM_USER_READ_ADD = "SYSTEM_USER:READ+ADD";
|
||||
public static final String SYSTEM_USER_READ_IMPORT = "SYSTEM_USER:READ+IMPORT";
|
||||
|
@ -13,7 +30,7 @@ public class PermissionConstants {
|
|||
public static final String SYSTEM_ORGANIZATION_READ_ADD = "SYSTEM_ORGANIZATION:READ+ADD";
|
||||
public static final String SYSTEM_ORGANIZATION_READ_UPDATE = "SYSTEM_ORGANIZATION:READ+UPDATE";
|
||||
public static final String SYSTEM_ORGANIZATION_READ_DELETE = "SYSTEM_ORGANIZATION:READ+DELETE";
|
||||
|
||||
|
||||
public static final String SYSTEM_TEST_POOL_READ = "SYSTEM_TEST_POOL:READ";
|
||||
public static final String SYSTEM_TEST_POOL_READ_ADD = "SYSTEM_TEST_POOL:READ+ADD";
|
||||
public static final String SYSTEM_TEST_POOL_READ_UPDATE = "SYSTEM_TEST_POOL:READ+UPDATE";
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
package io.metersphere.sdk.dto;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 权限信息
|
||||
* @author jianxing
|
||||
*/
|
||||
@Data
|
||||
@Schema(title = "权限信息")
|
||||
public class PermissionDTO {
|
||||
@Schema(title = "权限ID")
|
||||
private String id;
|
||||
@Schema(title = "权限名称")
|
||||
private String name;
|
||||
@Schema(title = "权限所属菜单ID")
|
||||
private String resourceId;
|
||||
@Schema(title = "是否启用该权限")
|
||||
private Boolean enable = false;
|
||||
@Schema(title = "是否是企业权限")
|
||||
private Boolean license = false;
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
package io.metersphere.sdk.dto;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author jianxing
|
||||
*/
|
||||
@Data
|
||||
@Schema(title = "权限设置菜单项")
|
||||
public class PermissionSettingDTO {
|
||||
@Schema(title = "菜单项ID")
|
||||
private String id;
|
||||
@Schema(title = "菜单项名称")
|
||||
private String name;
|
||||
@Schema(title = "是否是企业版菜单")
|
||||
private Boolean license = false;
|
||||
@Schema(title = "菜单下的权限列表")
|
||||
private List<PermissionDTO> permissions;
|
||||
@Schema(title = "子菜单")
|
||||
private List<PermissionSettingDTO> children;
|
||||
}
|
|
@ -0,0 +1,78 @@
|
|||
package io.metersphere.system.controller;
|
||||
|
||||
import io.metersphere.sdk.constants.PermissionConstants;
|
||||
import io.metersphere.sdk.dto.PermissionSettingDTO;
|
||||
import io.metersphere.system.domain.UserRole;
|
||||
import io.metersphere.system.dto.request.PermissionSettingUpdateRequest;
|
||||
import io.metersphere.system.service.GlobalUserRoleService;
|
||||
import io.metersphere.validation.groups.Created;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author : jianxing
|
||||
* @date : 2023-6-9
|
||||
*/
|
||||
@Tag(name = "全局用户组")
|
||||
@RestController
|
||||
@RequestMapping("/user/role/global")
|
||||
public class GlobalUserRoleController {
|
||||
|
||||
@Resource
|
||||
private GlobalUserRoleService globalUserRoleService;
|
||||
|
||||
@GetMapping("/list")
|
||||
@Operation(summary = "获取全局用户组列表")
|
||||
@RequiresPermissions(PermissionConstants.SYSTEM_USER_ROLE_READ)
|
||||
public List<UserRole> list() {
|
||||
return globalUserRoleService.list();
|
||||
}
|
||||
|
||||
@GetMapping("/permission/setting/{id}")
|
||||
@Operation(summary = "获取全局用户组对应的权限配置")
|
||||
@RequiresPermissions(PermissionConstants.SYSTEM_USER_ROLE_READ)
|
||||
public List<PermissionSettingDTO> getPermissionSetting(@PathVariable String id) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
@PostMapping("/permission/update")
|
||||
@Operation(summary = "编辑全局用户组对应的权限配置")
|
||||
@RequiresPermissions(PermissionConstants.SYSTEM_USER_ROLE_UPDATE)
|
||||
public void updatePermissionSetting(@RequestBody PermissionSettingUpdateRequest request) {
|
||||
}
|
||||
|
||||
@GetMapping("/get/{id}")
|
||||
@Operation(summary = "获取单个全局用户组信息")
|
||||
@RequiresPermissions(PermissionConstants.SYSTEM_USER_ROLE_READ)
|
||||
public UserRole get(@PathVariable String id) {
|
||||
return globalUserRoleService.get(id);
|
||||
}
|
||||
|
||||
@PostMapping("/add")
|
||||
@Operation(summary = "添加自定义全局用户组")
|
||||
@RequiresPermissions(PermissionConstants.SYSTEM_USER_ROLE_ADD)
|
||||
public UserRole add(@Validated({Created.class}) @RequestBody UserRole userRole) {
|
||||
return globalUserRoleService.add(userRole);
|
||||
}
|
||||
|
||||
@PostMapping("/update")
|
||||
@Operation(summary = "更新自定义全局用户组")
|
||||
@RequiresPermissions(PermissionConstants.SYSTEM_USER_ROLE_UPDATE)
|
||||
public UserRole update(@Validated({Created.class}) @RequestBody UserRole userRole) {
|
||||
return globalUserRoleService.update(userRole);
|
||||
}
|
||||
|
||||
@GetMapping("/delete/{id}")
|
||||
@Operation(summary = "删除自定义全局用户组")
|
||||
@RequiresPermissions(PermissionConstants.SYSTEM_USER_ROLE_DELETE)
|
||||
public String delete(@PathVariable String id) {
|
||||
return globalUserRoleService.delete(id);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,55 @@
|
|||
package io.metersphere.system.controller;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import io.metersphere.system.dto.GlobalUserRoleUserDTO;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import io.metersphere.validation.groups.*;
|
||||
import io.metersphere.sdk.util.PageUtils;
|
||||
import com.github.pagehelper.Page;
|
||||
import io.metersphere.sdk.util.Pager;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import io.metersphere.sdk.constants.PermissionConstants;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
||||
import io.metersphere.system.dto.request.GlobalUserRoleRelationQueryRequest;
|
||||
import io.metersphere.system.service.GlobalUserRoleRelationService;
|
||||
import io.metersphere.system.domain.UserRoleRelation;
|
||||
|
||||
/**
|
||||
* @author : jianxing
|
||||
* @date : 2023-6-12
|
||||
*/
|
||||
@RestController
|
||||
@Tag(name = "全局用户组与用户的关联关系")
|
||||
@RequestMapping("/user/role/relation/global")
|
||||
public class GlobalUserRoleRelationController {
|
||||
|
||||
@Resource
|
||||
private GlobalUserRoleRelationService globalUserRoleRelationService;
|
||||
|
||||
@PostMapping("/list")
|
||||
@Operation(summary = "获取全局用户组对应的用户列表")
|
||||
@RequiresPermissions(PermissionConstants.SYSTEM_USER_ROLE_RELATION_READ)
|
||||
public Pager<List<GlobalUserRoleUserDTO>> list(@RequestBody GlobalUserRoleRelationQueryRequest request) {
|
||||
Page<Object> page = PageHelper.startPage(request.getCurrent(), request.getPageSize(), true);
|
||||
return PageUtils.setPageInfo(page, globalUserRoleRelationService.list(request));
|
||||
}
|
||||
|
||||
@PostMapping("/add")
|
||||
@Operation(summary = "创建全局用户组和用户的关联关系")
|
||||
@RequiresPermissions(PermissionConstants.SYSTEM_USER_ROLE_RELATION_ADD)
|
||||
public UserRoleRelation add(@Validated({Created.class}) @RequestBody UserRoleRelation userRoleRelation) {
|
||||
return globalUserRoleRelationService.add(userRoleRelation);
|
||||
}
|
||||
|
||||
@GetMapping("/delete/{id}")
|
||||
@Operation(summary = "删除全局用户组和用户的关联关系")
|
||||
@RequiresPermissions(PermissionConstants.SYSTEM_USER_ROLE_RELATION_DELETE)
|
||||
public String delete(@PathVariable String id) {
|
||||
return globalUserRoleRelationService.delete(id);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
package io.metersphere.system.dto;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @author jianxing
|
||||
*/
|
||||
@Data
|
||||
@Schema(title = "用户基础信息")
|
||||
public class GlobalUserRoleUserDTO {
|
||||
|
||||
@Schema(title = "用户名")
|
||||
private String name;
|
||||
|
||||
@Schema(title = "用户邮箱")
|
||||
private String email;
|
||||
|
||||
@Schema(title = "手机号")
|
||||
private String phone;
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
package io.metersphere.system.dto.request;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import io.metersphere.sdk.dto.BasePageRequest;
|
||||
/**
|
||||
* @author : jianxing
|
||||
* @date : 2023-6-12
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
public class GlobalUserRoleRelationQueryRequest extends BasePageRequest {
|
||||
@Schema(title = "用户组ID", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
private String userRoleId;
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
package io.metersphere.system.dto.request;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author jianxing
|
||||
*/
|
||||
@Data
|
||||
public class PermissionSettingUpdateRequest {
|
||||
@Schema(title = "用户组ID", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
private String userRoleId;
|
||||
@Schema(title = "菜单下的权限列表", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
private List<PermissionUpdateDTO> permissions;
|
||||
|
||||
@Data
|
||||
class PermissionUpdateDTO {
|
||||
@Schema(title = "权限ID", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
private String id;
|
||||
@Schema(title = "是否启用该权限", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
private Boolean enable = false;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
package io.metersphere.system.service;
|
||||
|
||||
import io.metersphere.system.domain.UserRoleRelation;
|
||||
import io.metersphere.system.dto.GlobalUserRoleUserDTO;
|
||||
import io.metersphere.system.mapper.UserRoleRelationMapper;
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.stereotype.Service;
|
||||
import io.metersphere.system.dto.request.GlobalUserRoleRelationQueryRequest;
|
||||
/**
|
||||
* @author jianxing
|
||||
* @date : 2023-6-12
|
||||
*/
|
||||
@Service
|
||||
public class GlobalUserRoleRelationService {
|
||||
|
||||
@Resource
|
||||
private UserRoleRelationMapper userRoleRelationMapper;
|
||||
|
||||
public List<GlobalUserRoleUserDTO> list(GlobalUserRoleRelationQueryRequest request) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
public UserRoleRelation add(UserRoleRelation userRoleRelation) {
|
||||
userRoleRelationMapper.insert(userRoleRelation);
|
||||
return userRoleRelation;
|
||||
}
|
||||
|
||||
public String delete(String id) {
|
||||
userRoleRelationMapper.deleteByPrimaryKey(id);
|
||||
return id;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,52 @@
|
|||
package io.metersphere.system.service;
|
||||
|
||||
import io.metersphere.system.domain.UserRole;
|
||||
import io.metersphere.system.domain.UserRoleExample;
|
||||
import io.metersphere.system.mapper.UserRoleMapper;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 系统设置的接口增删改查都是针对全局用户组
|
||||
* @author jianxing
|
||||
* @date : 2023-6-8
|
||||
*/
|
||||
@Service
|
||||
public class GlobalUserRoleService {
|
||||
|
||||
public static String GLOBAL_SCOPE = "GLOBAL";
|
||||
|
||||
@Resource
|
||||
private UserRoleMapper userRoleMapper;
|
||||
|
||||
public List<UserRole> list() {
|
||||
UserRoleExample example = new UserRoleExample();
|
||||
example.createCriteria().andScopeIdEqualTo(GLOBAL_SCOPE);
|
||||
return userRoleMapper.selectByExample(example);
|
||||
}
|
||||
|
||||
public UserRole get(String id) {
|
||||
// todo 只能获取全局
|
||||
return userRoleMapper.selectByPrimaryKey(id);
|
||||
}
|
||||
|
||||
public UserRole add(UserRole userRole) {
|
||||
// todo 只能添加自定义全局
|
||||
userRoleMapper.insert(userRole);
|
||||
return userRole;
|
||||
}
|
||||
|
||||
public UserRole update(UserRole userRole) {
|
||||
// todo 只能修改自定义全局
|
||||
userRoleMapper.updateByPrimaryKeySelective(userRole);
|
||||
return userRole;
|
||||
}
|
||||
|
||||
public String delete(String id) {
|
||||
// todo 只能删除自定义全局
|
||||
userRoleMapper.deleteByPrimaryKey(id);
|
||||
return id;
|
||||
}
|
||||
}
|
|
@ -1,382 +1,30 @@
|
|||
{
|
||||
"permissions": [
|
||||
{
|
||||
"id": "SYSTEM_USER:READ",
|
||||
"name": "permission.system_user.read",
|
||||
"resourceId": "SYSTEM_USER"
|
||||
"id": "SYSTEM_USER_ROLE:READ",
|
||||
"name": "permission.system_user_role.read",
|
||||
"resourceId": "SYSTEM_USER_ROLE"
|
||||
},
|
||||
{
|
||||
"id": "SYSTEM_USER:READ+ADD",
|
||||
"name": "permission.system_user.add",
|
||||
"resourceId": "SYSTEM_USER"
|
||||
"id": "SYSTEM_USER_ROLE:READ+ADD",
|
||||
"name": "permission.system_user_role.add",
|
||||
"resourceId": "SYSTEM_USER_ROLE"
|
||||
},
|
||||
{
|
||||
"id": "SYSTEM_USER:READ+IMPORT",
|
||||
"name": "permission.system_user.import",
|
||||
"resourceId": "SYSTEM_USER"
|
||||
"id": "SYSTEM_USER_ROLE:READ+UPDATE",
|
||||
"name": "permission.system_user_role.edit",
|
||||
"resourceId": "SYSTEM_USER_ROLE"
|
||||
},
|
||||
{
|
||||
"id": "SYSTEM_USER:READ+EDIT",
|
||||
"name": "permission.system_user.edit",
|
||||
"resourceId": "SYSTEM_USER"
|
||||
},
|
||||
{
|
||||
"id": "SYSTEM_USER:READ+DELETE",
|
||||
"name": "permission.system_user.delete",
|
||||
"resourceId": "SYSTEM_USER"
|
||||
},
|
||||
{
|
||||
"id": "SYSTEM_USER:READ+EDIT_PASSWORD",
|
||||
"name": "permission.system_user.edit_password",
|
||||
"resourceId": "SYSTEM_USER"
|
||||
},
|
||||
{
|
||||
"id": "SYSTEM_ORGANIZATION:READ",
|
||||
"name": "permission.system_organization.read",
|
||||
"resourceId": "SYSTEM_ORGANIZATION"
|
||||
},
|
||||
{
|
||||
"id": "SYSTEM_ORGANIZATION:READ+ADD",
|
||||
"name": "permission.system_organization.add",
|
||||
"resourceId": "SYSTEM_ORGANIZATION"
|
||||
},
|
||||
{
|
||||
"id": "SYSTEM_ORGANIZATION:READ+EDIT",
|
||||
"name": "permission.system_organization.edit",
|
||||
"resourceId": "SYSTEM_ORGANIZATION"
|
||||
},
|
||||
{
|
||||
"id": "SYSTEM_ORGANIZATION:READ+DELETE",
|
||||
"name": "permission.system_organization.delete",
|
||||
"resourceId": "SYSTEM_ORGANIZATION"
|
||||
},
|
||||
{
|
||||
"id": "SYSTEM_ROLE:READ",
|
||||
"name": "permission.system_role.read",
|
||||
"resourceId": "SYSTEM_ROLE"
|
||||
},
|
||||
{
|
||||
"id": "SYSTEM_ROLE:READ+ADD",
|
||||
"name": "permission.system_role.add",
|
||||
"resourceId": "SYSTEM_ROLE"
|
||||
},
|
||||
{
|
||||
"id": "SYSTEM_ROLE:READ+EDIT",
|
||||
"name": "permission.system_role.edit",
|
||||
"resourceId": "SYSTEM_ROLE"
|
||||
},
|
||||
{
|
||||
"id": "SYSTEM_ROLE:READ+SETTING_PERMISSION",
|
||||
"name": "permission.system_role.setting_permission",
|
||||
"resourceId": "SYSTEM_ROLE"
|
||||
},
|
||||
{
|
||||
"id": "SYSTEM_ROLE:READ+DELETE",
|
||||
"name": "permission.system_role.delete",
|
||||
"resourceId": "SYSTEM_ROLE"
|
||||
},
|
||||
{
|
||||
"id": "SYSTEM_TEST_POOL:READ",
|
||||
"name": "permission.system_test_pool.read",
|
||||
"resourceId": "SYSTEM_TEST_POOL"
|
||||
},
|
||||
{
|
||||
"id": "SYSTEM_TEST_POOL:READ+ADD",
|
||||
"name": "permission.system_test_pool.add",
|
||||
"resourceId": "SYSTEM_TEST_POOL"
|
||||
},
|
||||
{
|
||||
"id": "SYSTEM_TEST_POOL:READ+EDIT",
|
||||
"name": "permission.system_test_pool.edit",
|
||||
"resourceId": "SYSTEM_TEST_POOL"
|
||||
},
|
||||
{
|
||||
"id": "SYSTEM_TEST_POOL:READ+DELETE",
|
||||
"name": "permission.system_test_pool.delete",
|
||||
"resourceId": "SYSTEM_TEST_POOL"
|
||||
},
|
||||
{
|
||||
"id": "SYSTEM_SETTING:READ",
|
||||
"name": "permission.system_setting.read",
|
||||
"resourceId": "SYSTEM_SETTING"
|
||||
},
|
||||
{
|
||||
"id": "SYSTEM_SETTING:READ+EDIT",
|
||||
"name": "permission.system_setting.edit",
|
||||
"resourceId": "SYSTEM_SETTING"
|
||||
},
|
||||
{
|
||||
"id": "SYSTEM_QUOTA:READ",
|
||||
"name": "permission.system_quota.read",
|
||||
"resourceId": "SYSTEM_QUOTA"
|
||||
},
|
||||
{
|
||||
"id": "SYSTEM_QUOTA:READ+EDIT",
|
||||
"name": "permission.system_quota.edit",
|
||||
"resourceId": "SYSTEM_QUOTA"
|
||||
},
|
||||
{
|
||||
"id": "SYSTEM_AUTH:READ",
|
||||
"name": "permission.system_auth.read",
|
||||
"resourceId": "SYSTEM_AUTH"
|
||||
},
|
||||
{
|
||||
"id": "SYSTEM_AUTH:READ+EDIT",
|
||||
"name": "permission.system_auth.edit",
|
||||
"resourceId": "SYSTEM_AUTH"
|
||||
},
|
||||
{
|
||||
"id": "SYSTEM_OPERATING_LOG:READ",
|
||||
"name": "permission.system_operation_log.read",
|
||||
"resourceId": "SYSTEM_OPERATING_LOG"
|
||||
},
|
||||
{
|
||||
"id": "ORGANIZATION_SERVICE:READ",
|
||||
"name": "permission.organization_service.read",
|
||||
"resourceId": "ORGANIZATION_SERVICE"
|
||||
},
|
||||
{
|
||||
"id": "ORGANIZATION_SERVICE:READ+EDIT",
|
||||
"name": "permission.organization_service.edit",
|
||||
"resourceId": "ORGANIZATION_SERVICE"
|
||||
},
|
||||
{
|
||||
"id": "ORGANIZATION_USER:READ",
|
||||
"name": "permission.organization_user.read",
|
||||
"resourceId": "ORGANIZATION_USER"
|
||||
},
|
||||
{
|
||||
"id": "ORGANIZATION_USER:READ+ADD",
|
||||
"name": "permission.organization_user.add",
|
||||
"resourceId": "ORGANIZATION_USER"
|
||||
},
|
||||
{
|
||||
"id": "ORGANIZATION_USER:READ+EDIT",
|
||||
"name": "permission.organization_user.edit",
|
||||
"resourceId": "ORGANIZATION_USER"
|
||||
},
|
||||
{
|
||||
"id": "ORGANIZATION_USER:READ+DELETE",
|
||||
"name": "permission.organization_user.delete",
|
||||
"resourceId": "ORGANIZATION_USER"
|
||||
},
|
||||
{
|
||||
"id": "ORGANIZATION_PROJECT_MANAGER:READ",
|
||||
"name": "permission.organization_project_manager.read",
|
||||
"resourceId": "ORGANIZATION_PROJECT_MANAGER"
|
||||
},
|
||||
{
|
||||
"id": "ORGANIZATION_PROJECT_MANAGER:READ+ADD",
|
||||
"name": "permission.organization_project_manager.add",
|
||||
"resourceId": "ORGANIZATION_PROJECT_MANAGER"
|
||||
},
|
||||
{
|
||||
"id": "ORGANIZATION_PROJECT_MANAGER:READ+EDIT",
|
||||
"name": "permission.organization_project_manager.edit",
|
||||
"resourceId": "ORGANIZATION_PROJECT_MANAGER"
|
||||
},
|
||||
{
|
||||
"id": "ORGANIZATION_PROJECT_MANAGER:READ+DELETE",
|
||||
"name": "permission.organization_project_manager.delete",
|
||||
"resourceId": "ORGANIZATION_PROJECT_MANAGER"
|
||||
},
|
||||
{
|
||||
"id": "ORGANIZATION_PROJECT_MANAGER:READ+ENVIRONMENT_CONFIG",
|
||||
"name": "permission.organization_project_manager.environment_config",
|
||||
"resourceId": "ORGANIZATION_PROJECT_MANAGER"
|
||||
},
|
||||
{
|
||||
"id": "ORGANIZATION_PROJECT_MANAGER:READ+ADD_USER",
|
||||
"name": "permission.organization_user.add",
|
||||
"resourceId": "ORGANIZATION_PROJECT_MANAGER"
|
||||
},
|
||||
{
|
||||
"id": "ORGANIZATION_PROJECT_MANAGER:READ+EDIT_USER",
|
||||
"name": "permission.organization_user.edit",
|
||||
"resourceId": "ORGANIZATION_PROJECT_MANAGER"
|
||||
},
|
||||
{
|
||||
"id": "ORGANIZATION_PROJECT_MANAGER:READ+DELETE_USER",
|
||||
"name": "permission.organization_user.delete",
|
||||
"resourceId": "ORGANIZATION_PROJECT_MANAGER"
|
||||
},
|
||||
{
|
||||
"id": "ORGANIZATION_PROJECT_ENVIRONMENT:READ",
|
||||
"name": "permission.organization_project_environment.read",
|
||||
"resourceId": "ORGANIZATION_PROJECT_ENVIRONMENT"
|
||||
},
|
||||
{
|
||||
"id": "ORGANIZATION_PROJECT_ENVIRONMENT:READ+ADD",
|
||||
"name": "permission.organization_project_environment.add",
|
||||
"resourceId": "ORGANIZATION_PROJECT_ENVIRONMENT"
|
||||
},
|
||||
{
|
||||
"id": "ORGANIZATION_PROJECT_ENVIRONMENT:READ+EDIT",
|
||||
"name": "permission.organization_project_environment.edit",
|
||||
"resourceId": "ORGANIZATION_PROJECT_ENVIRONMENT"
|
||||
},
|
||||
{
|
||||
"id": "ORGANIZATION_PROJECT_ENVIRONMENT:READ+DELETE",
|
||||
"name": "permission.organization_project_environment.delete",
|
||||
"resourceId": "ORGANIZATION_PROJECT_ENVIRONMENT"
|
||||
},
|
||||
{
|
||||
"id": "ORGANIZATION_PROJECT_ENVIRONMENT:READ+COPY",
|
||||
"name": "permission.organization_project_environment.copy",
|
||||
"resourceId": "ORGANIZATION_PROJECT_ENVIRONMENT"
|
||||
},
|
||||
{
|
||||
"id": "ORGANIZATION_PROJECT_ENVIRONMENT:READ+IMPORT",
|
||||
"name": "permission.organization_project_environment.import",
|
||||
"resourceId": "ORGANIZATION_PROJECT_ENVIRONMENT"
|
||||
},
|
||||
{
|
||||
"id": "ORGANIZATION_PROJECT_ENVIRONMENT:READ+EXPORT",
|
||||
"name": "permission.organization_project_environment.export",
|
||||
"resourceId": "ORGANIZATION_PROJECT_ENVIRONMENT"
|
||||
},
|
||||
{
|
||||
"id": "ORGANIZATION_PROJECT_ENVIRONMENT:READ+ADD_GROUP",
|
||||
"name": "permission.organization_project_environment.add_group",
|
||||
"resourceId": "ORGANIZATION_PROJECT_ENVIRONMENT"
|
||||
},
|
||||
{
|
||||
"id": "ORGANIZATION_PROJECT_ENVIRONMENT:READ+EDIT_GROUP",
|
||||
"name": "permission.organization_project_environment.edit_group",
|
||||
"resourceId": "ORGANIZATION_PROJECT_ENVIRONMENT"
|
||||
},
|
||||
{
|
||||
"id": "ORGANIZATION_PROJECT_ENVIRONMENT:READ+COPY_GROUP",
|
||||
"name": "permission.organization_project_environment.copy_group",
|
||||
"resourceId": "ORGANIZATION_PROJECT_ENVIRONMENT"
|
||||
},
|
||||
{
|
||||
"id": "ORGANIZATION_PROJECT_ENVIRONMENT:READ+DELETE_GROUP",
|
||||
"name": "permission.organization_project_environment.delete_group",
|
||||
"resourceId": "ORGANIZATION_PROJECT_ENVIRONMENT"
|
||||
},
|
||||
{
|
||||
"id": "ORGANIZATION_QUOTA:READ",
|
||||
"name": "permission.organization_quota.read",
|
||||
"resourceId": "ORGANIZATION_QUOTA"
|
||||
},
|
||||
{
|
||||
"id": "ORGANIZATION_QUOTA:READ+EDIT",
|
||||
"name": "permission.organization_quota.edit",
|
||||
"resourceId": "ORGANIZATION_QUOTA"
|
||||
},
|
||||
{
|
||||
"id": "ORGANIZATION_OPERATING_LOG:READ",
|
||||
"name": "permission.organization_operation_log.read",
|
||||
"resourceId": "ORGANIZATION_OPERATING_LOG"
|
||||
},
|
||||
{
|
||||
"id": "SYSTEM_PLUGIN:UPLOAD",
|
||||
"name": "permission.system_plugin.upload",
|
||||
"resourceId": "SYSTEM_PLUGIN"
|
||||
},
|
||||
{
|
||||
"id": "SYSTEM_PLUGIN:DEL",
|
||||
"name": "permission.system_plugin.delete",
|
||||
"resourceId": "SYSTEM_PLUGIN"
|
||||
},
|
||||
{
|
||||
"id": "SYSTEM_PLUGIN:READ",
|
||||
"name": "permission.system_plugin.read",
|
||||
"resourceId": "SYSTEM_PLUGIN"
|
||||
},
|
||||
{
|
||||
"id": "PERSONAL_INFORMATION:READ+EDIT",
|
||||
"name": "permission.personal_information.personal_setting",
|
||||
"resourceId": "PERSONAL_INFORMATION"
|
||||
},
|
||||
{
|
||||
"id": "PERSONAL_INFORMATION:READ+API_KEYS",
|
||||
"name": "permission.personal_information.api_keys",
|
||||
"resourceId": "PERSONAL_INFORMATION"
|
||||
},
|
||||
{
|
||||
"id": "PERSONAL_INFORMATION:READ+EDIT_PASSWORD",
|
||||
"name": "permission.personal_information.edit_password",
|
||||
"resourceId": "PERSONAL_INFORMATION"
|
||||
},
|
||||
{
|
||||
"id": "PERSONAL_INFORMATION:READ+THIRD_ACCOUNT",
|
||||
"name": "permission.personal_information.third_account",
|
||||
"resourceId": "PERSONAL_INFORMATION"
|
||||
},
|
||||
{
|
||||
"id": "PERSONAL_INFORMATION:READ+UI_SETTING",
|
||||
"name": "permission.personal_information.ui_setting",
|
||||
"resourceId": "PERSONAL_INFORMATION",
|
||||
"license": true
|
||||
"id": "SYSTEM_USER_ROLE:READ+DELETE",
|
||||
"name": "permission.system_user_role.delete",
|
||||
"resourceId": "SYSTEM_USER_ROLE"
|
||||
}
|
||||
],
|
||||
"resource": [
|
||||
{
|
||||
"id": "SYSTEM_USER",
|
||||
"name": "permission.system_user.name"
|
||||
},
|
||||
{
|
||||
"id": "SYSTEM_ORGANIZATION",
|
||||
"name": "permission.system_organization.name"
|
||||
},
|
||||
{
|
||||
"id": "SYSTEM_ROLE",
|
||||
"id": "SYSTEM_USER_ROLE",
|
||||
"name": "permission.system_role.name"
|
||||
},
|
||||
{
|
||||
"id": "SYSTEM_TEST_POOL",
|
||||
"name": "permission.system_test_pool.name"
|
||||
},
|
||||
{
|
||||
"id": "SYSTEM_SETTING",
|
||||
"name": "permission.system_setting.name"
|
||||
},
|
||||
{
|
||||
"id": "SYSTEM_QUOTA",
|
||||
"name": "permission.system_quota.name"
|
||||
},
|
||||
{
|
||||
"id": "SYSTEM_AUTH",
|
||||
"name": "permission.system_auth.name"
|
||||
},
|
||||
{
|
||||
"id": "SYSTEM_OPERATING_LOG",
|
||||
"name": "permission.system_operation_log.name"
|
||||
},
|
||||
{
|
||||
"id": "SYSTEM_PLUGIN",
|
||||
"name": "permission.system_plugin.name"
|
||||
},
|
||||
{
|
||||
"id": "ORGANIZATION_USER",
|
||||
"name": "permission.organization_user.name"
|
||||
},
|
||||
{
|
||||
"id": "ORGANIZATION_SERVICE",
|
||||
"name": "permission.organization_service.name"
|
||||
},
|
||||
{
|
||||
"id": "ORGANIZATION_PROJECT_MANAGER",
|
||||
"name": "permission.organization_project_manager.name"
|
||||
},
|
||||
{
|
||||
"id": "ORGANIZATION_PROJECT_ENVIRONMENT",
|
||||
"name": "permission.organization_project_environment.name"
|
||||
},
|
||||
{
|
||||
"id": "ORGANIZATION_QUOTA",
|
||||
"name": "permission.organization_quota.name"
|
||||
},
|
||||
{
|
||||
"id": "ORGANIZATION_OPERATING_LOG",
|
||||
"name": "permission.organization_operation_log.name"
|
||||
},
|
||||
{
|
||||
"id": "PERSONAL_INFORMATION",
|
||||
"name": "permission.personal_information.name",
|
||||
"global": true
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,100 @@
|
|||
package io.metersphere.system.controller;
|
||||
|
||||
import com.jayway.jsonpath.JsonPath;
|
||||
import io.metersphere.sdk.constants.SessionConstants;
|
||||
import io.metersphere.sdk.util.JSON;
|
||||
import io.metersphere.system.domain.UserRole;
|
||||
import io.metersphere.system.dto.request.GlobalUserRoleRelationQueryRequest;
|
||||
import io.metersphere.system.dto.request.PermissionSettingUpdateRequest;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.MethodOrderer;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestMethodOrder;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
import org.springframework.test.web.servlet.MvcResult;
|
||||
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
|
||||
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
|
||||
@SpringBootTest
|
||||
@AutoConfigureMockMvc
|
||||
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
|
||||
class GlobalUserRoleControllerTest {
|
||||
|
||||
@Resource
|
||||
private MockMvc mockMvc;
|
||||
private static String sessionId;
|
||||
private static String csrfToken;
|
||||
|
||||
private static final String BASE_URL = "/user/role/global/";
|
||||
|
||||
@BeforeEach
|
||||
public void login() throws Exception {
|
||||
if (StringUtils.isAnyBlank(sessionId, csrfToken)) {
|
||||
MvcResult mvcResult = mockMvc.perform(MockMvcRequestBuilders.post("/login")
|
||||
.content("{\"username\":\"admin\",\"password\":\"metersphere\"}")
|
||||
.contentType(MediaType.APPLICATION_JSON))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentType(MediaType.APPLICATION_JSON))
|
||||
.andReturn();
|
||||
sessionId = JsonPath.read(mvcResult.getResponse().getContentAsString(), "$.data.sessionId");
|
||||
csrfToken = JsonPath.read(mvcResult.getResponse().getContentAsString(), "$.data.csrfToken");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void list() throws Exception {
|
||||
this.requestPost("list", new GlobalUserRoleRelationQueryRequest());
|
||||
}
|
||||
|
||||
@Test
|
||||
void getPermissionSetting() throws Exception {
|
||||
this.requestGet("permission/setting/1");
|
||||
}
|
||||
|
||||
@Test
|
||||
void updatePermissionSetting() throws Exception {
|
||||
this.requestPost("list", new PermissionSettingUpdateRequest());
|
||||
}
|
||||
|
||||
@Test
|
||||
void get() throws Exception {
|
||||
this.requestGet("get/1");
|
||||
}
|
||||
|
||||
@Test
|
||||
void add() throws Exception {
|
||||
this.requestPost("add", new UserRole());
|
||||
}
|
||||
|
||||
@Test
|
||||
void update() throws Exception {
|
||||
this.requestPost("update", new UserRole());
|
||||
}
|
||||
|
||||
@Test
|
||||
void delete() throws Exception {
|
||||
this.requestGet("delete/1");
|
||||
}
|
||||
|
||||
private void requestPost(String url, Object param) throws Exception {
|
||||
mockMvc.perform(MockMvcRequestBuilders.post(BASE_URL + url)
|
||||
.header(SessionConstants.HEADER_TOKEN, sessionId)
|
||||
.header(SessionConstants.CSRF_TOKEN, csrfToken)
|
||||
.content(JSON.toJSONString(param))
|
||||
.contentType(MediaType.APPLICATION_JSON)).andReturn();
|
||||
}
|
||||
|
||||
private MvcResult requestGet(String url) throws Exception {
|
||||
return mockMvc.perform(MockMvcRequestBuilders.get(BASE_URL + url)
|
||||
.header(SessionConstants.HEADER_TOKEN, sessionId)
|
||||
.header(SessionConstants.CSRF_TOKEN, csrfToken)
|
||||
.contentType(MediaType.APPLICATION_JSON)).andReturn();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,79 @@
|
|||
package io.metersphere.system.controller;
|
||||
|
||||
import com.jayway.jsonpath.JsonPath;
|
||||
import io.metersphere.sdk.constants.SessionConstants;
|
||||
import io.metersphere.sdk.util.JSON;
|
||||
import io.metersphere.system.domain.UserRole;
|
||||
import io.metersphere.system.dto.request.GlobalUserRoleRelationQueryRequest;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.MethodOrderer;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestMethodOrder;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
import org.springframework.test.web.servlet.MvcResult;
|
||||
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
|
||||
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
|
||||
@SpringBootTest
|
||||
@AutoConfigureMockMvc
|
||||
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
|
||||
class GlobalUserRoleRelationControllerTest {
|
||||
|
||||
@Resource
|
||||
private MockMvc mockMvc;
|
||||
private static String sessionId;
|
||||
private static String csrfToken;
|
||||
|
||||
private static final String BASE_URL = "/user/role/relation/global/";
|
||||
|
||||
@BeforeEach
|
||||
public void login() throws Exception {
|
||||
if (StringUtils.isAnyBlank(sessionId, csrfToken)) {
|
||||
MvcResult mvcResult = mockMvc.perform(MockMvcRequestBuilders.post("/login")
|
||||
.content("{\"username\":\"admin\",\"password\":\"metersphere\"}")
|
||||
.contentType(MediaType.APPLICATION_JSON))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentType(MediaType.APPLICATION_JSON))
|
||||
.andReturn();
|
||||
sessionId = JsonPath.read(mvcResult.getResponse().getContentAsString(), "$.data.sessionId");
|
||||
csrfToken = JsonPath.read(mvcResult.getResponse().getContentAsString(), "$.data.csrfToken");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void list() throws Exception {
|
||||
this.requestPost("list", new GlobalUserRoleRelationQueryRequest());
|
||||
}
|
||||
|
||||
@Test
|
||||
void add() throws Exception {
|
||||
this.requestPost("add", new UserRole());
|
||||
}
|
||||
|
||||
@Test
|
||||
void delete() throws Exception {
|
||||
this.requestGet("delete/1");
|
||||
}
|
||||
|
||||
private void requestPost(String url, Object param) throws Exception {
|
||||
mockMvc.perform(MockMvcRequestBuilders.post(BASE_URL + url)
|
||||
.header(SessionConstants.HEADER_TOKEN, sessionId)
|
||||
.header(SessionConstants.CSRF_TOKEN, csrfToken)
|
||||
.content(JSON.toJSONString(param))
|
||||
.contentType(MediaType.APPLICATION_JSON)).andReturn();
|
||||
}
|
||||
|
||||
private MvcResult requestGet(String url) throws Exception {
|
||||
return mockMvc.perform(MockMvcRequestBuilders.get(BASE_URL + url)
|
||||
.header(SessionConstants.HEADER_TOKEN, sessionId)
|
||||
.header(SessionConstants.CSRF_TOKEN, csrfToken)
|
||||
.contentType(MediaType.APPLICATION_JSON)).andReturn();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue