forked from github/dataease
Merge pull request #1472 from dataease/pr@dev@panlelink
feat: 公共链接支持行权限
This commit is contained in:
commit
b8c47998a1
@ -9,8 +9,6 @@ import io.dataease.auth.util.LinkUtil;
|
||||
import io.dataease.base.domain.PanelLink;
|
||||
import io.dataease.commons.utils.LogUtil;
|
||||
import org.apache.shiro.web.filter.authc.AnonymousFilter;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.servlet.ServletRequest;
|
||||
import javax.servlet.ServletResponse;
|
||||
@ -26,9 +24,9 @@ public class F2CLinkFilter extends AnonymousFilter {
|
||||
HttpServletRequest req = (HttpServletRequest) request;
|
||||
String linkToken = req.getHeader(LINK_TOKEN_KEY);
|
||||
DecodedJWT jwt = JWT.decode(linkToken);
|
||||
Claim resourceId = jwt.getClaim("resourceId");
|
||||
String id = resourceId.asString();
|
||||
PanelLink panelLink = LinkUtil.queryLink(id);
|
||||
String resourceId = jwt.getClaim("resourceId").asString();
|
||||
Long userId = jwt.getClaim("userId").asLong();
|
||||
PanelLink panelLink = LinkUtil.queryLink(resourceId, userId);
|
||||
if (ObjectUtil.isEmpty(panelLink)) return false;
|
||||
String pwd;
|
||||
if (!panelLink.getEnablePwd()) {
|
||||
@ -37,7 +35,7 @@ public class F2CLinkFilter extends AnonymousFilter {
|
||||
} else {
|
||||
pwd = panelLink.getPwd();
|
||||
}
|
||||
return JWTUtils.verifyLink(linkToken, id, pwd);
|
||||
return JWTUtils.verifyLink(linkToken, resourceId, userId, pwd);
|
||||
} catch (Exception e) {
|
||||
LogUtil.error(e);
|
||||
}
|
||||
|
@ -126,16 +126,24 @@ public class JWTUtils {
|
||||
}
|
||||
}
|
||||
|
||||
public static String signLink(String resourceId, String secret) {
|
||||
public static String signLink(String resourceId, Long userId, String secret) {
|
||||
Algorithm algorithm = Algorithm.HMAC256(secret);
|
||||
return JWT.create().withClaim("resourceId", resourceId).sign(algorithm);
|
||||
if(userId == null){
|
||||
return JWT.create().withClaim("resourceId", resourceId).sign(algorithm);
|
||||
}else {
|
||||
return JWT.create().withClaim("resourceId", resourceId).withClaim("userId", userId).sign(algorithm);
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean verifyLink(String token, String resourceId, String secret) {
|
||||
public static boolean verifyLink(String token, String resourceId, Long userId, String secret) {
|
||||
Algorithm algorithm = Algorithm.HMAC256(secret);
|
||||
JWTVerifier verifier = JWT.require(algorithm)
|
||||
.withClaim("resourceId", resourceId)
|
||||
.build();
|
||||
JWTVerifier verifier;
|
||||
if(userId == null){
|
||||
verifier = JWT.require(algorithm).withClaim("resourceId", resourceId).build();
|
||||
}else {
|
||||
verifier = JWT.require(algorithm).withClaim("resourceId", resourceId).withClaim("userId", userId).build();
|
||||
}
|
||||
|
||||
try {
|
||||
verifier.verify(token);
|
||||
return true;
|
||||
|
@ -16,7 +16,7 @@ public class LinkUtil {
|
||||
LinkUtil.panelLinkService = panelLinkService;
|
||||
}
|
||||
|
||||
public static PanelLink queryLink(String resourceId) {
|
||||
return panelLinkService.findOne(resourceId);
|
||||
public static PanelLink queryLink(String resourceId, Long user) {
|
||||
return panelLinkService.findOne(resourceId, user);
|
||||
}
|
||||
}
|
||||
|
@ -15,5 +15,7 @@ public class PanelLink implements Serializable {
|
||||
|
||||
private Long overTime;
|
||||
|
||||
private Long userId;
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
}
|
@ -423,6 +423,66 @@ public class PanelLinkExample {
|
||||
addCriterion("over_time not between", value1, value2, "overTime");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andUserIdIsNull() {
|
||||
addCriterion("user_id is null");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andUserIdIsNotNull() {
|
||||
addCriterion("user_id is not null");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andUserIdEqualTo(Long value) {
|
||||
addCriterion("user_id =", value, "userId");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andUserIdNotEqualTo(Long value) {
|
||||
addCriterion("user_id <>", value, "userId");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andUserIdGreaterThan(Long value) {
|
||||
addCriterion("user_id >", value, "userId");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andUserIdGreaterThanOrEqualTo(Long value) {
|
||||
addCriterion("user_id >=", value, "userId");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andUserIdLessThan(Long value) {
|
||||
addCriterion("user_id <", value, "userId");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andUserIdLessThanOrEqualTo(Long value) {
|
||||
addCriterion("user_id <=", value, "userId");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andUserIdIn(List<Long> values) {
|
||||
addCriterion("user_id in", values, "userId");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andUserIdNotIn(List<Long> values) {
|
||||
addCriterion("user_id not in", values, "userId");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andUserIdBetween(Long value1, Long value2) {
|
||||
addCriterion("user_id between", value1, value2, "userId");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andUserIdNotBetween(Long value1, Long value2) {
|
||||
addCriterion("user_id not between", value1, value2, "userId");
|
||||
return (Criteria) this;
|
||||
}
|
||||
}
|
||||
|
||||
public static class Criteria extends GeneratedCriteria {
|
||||
|
@ -9,5 +9,7 @@ public class PanelLinkMapping implements Serializable {
|
||||
|
||||
private String resourceId;
|
||||
|
||||
private Long userId;
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
}
|
@ -233,6 +233,66 @@ public class PanelLinkMappingExample {
|
||||
addCriterion("resource_id not between", value1, value2, "resourceId");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andUserIdIsNull() {
|
||||
addCriterion("user_id is null");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andUserIdIsNotNull() {
|
||||
addCriterion("user_id is not null");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andUserIdEqualTo(Long value) {
|
||||
addCriterion("user_id =", value, "userId");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andUserIdNotEqualTo(Long value) {
|
||||
addCriterion("user_id <>", value, "userId");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andUserIdGreaterThan(Long value) {
|
||||
addCriterion("user_id >", value, "userId");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andUserIdGreaterThanOrEqualTo(Long value) {
|
||||
addCriterion("user_id >=", value, "userId");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andUserIdLessThan(Long value) {
|
||||
addCriterion("user_id <", value, "userId");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andUserIdLessThanOrEqualTo(Long value) {
|
||||
addCriterion("user_id <=", value, "userId");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andUserIdIn(List<Long> values) {
|
||||
addCriterion("user_id in", values, "userId");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andUserIdNotIn(List<Long> values) {
|
||||
addCriterion("user_id not in", values, "userId");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andUserIdBetween(Long value1, Long value2) {
|
||||
addCriterion("user_id between", value1, value2, "userId");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andUserIdNotBetween(Long value1, Long value2) {
|
||||
addCriterion("user_id not between", value1, value2, "userId");
|
||||
return (Criteria) this;
|
||||
}
|
||||
}
|
||||
|
||||
public static class Criteria extends GeneratedCriteria {
|
||||
|
@ -10,21 +10,13 @@ public interface PanelLinkMapper {
|
||||
|
||||
int deleteByExample(PanelLinkExample example);
|
||||
|
||||
int deleteByPrimaryKey(String resourceId);
|
||||
|
||||
int insert(PanelLink record);
|
||||
|
||||
int insertSelective(PanelLink record);
|
||||
|
||||
List<PanelLink> selectByExample(PanelLinkExample example);
|
||||
|
||||
PanelLink selectByPrimaryKey(String resourceId);
|
||||
|
||||
int updateByExampleSelective(@Param("record") PanelLink record, @Param("example") PanelLinkExample example);
|
||||
|
||||
int updateByExample(@Param("record") PanelLink record, @Param("example") PanelLinkExample example);
|
||||
|
||||
int updateByPrimaryKeySelective(PanelLink record);
|
||||
|
||||
int updateByPrimaryKey(PanelLink record);
|
||||
}
|
@ -2,11 +2,12 @@
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="io.dataease.base.mapper.PanelLinkMapper">
|
||||
<resultMap id="BaseResultMap" type="io.dataease.base.domain.PanelLink">
|
||||
<id column="resource_id" jdbcType="VARCHAR" property="resourceId" />
|
||||
<result column="resource_id" jdbcType="VARCHAR" property="resourceId" />
|
||||
<result column="valid" jdbcType="BIT" property="valid" />
|
||||
<result column="enable_pwd" jdbcType="BIT" property="enablePwd" />
|
||||
<result column="pwd" jdbcType="VARCHAR" property="pwd" />
|
||||
<result column="over_time" jdbcType="BIGINT" property="overTime" />
|
||||
<result column="user_id" jdbcType="BIGINT" property="userId" />
|
||||
</resultMap>
|
||||
<sql id="Example_Where_Clause">
|
||||
<where>
|
||||
@ -67,7 +68,7 @@
|
||||
</where>
|
||||
</sql>
|
||||
<sql id="Base_Column_List">
|
||||
resource_id, `valid`, enable_pwd, pwd, over_time
|
||||
resource_id, `valid`, enable_pwd, pwd, over_time, user_id
|
||||
</sql>
|
||||
<select id="selectByExample" parameterType="io.dataease.base.domain.PanelLinkExample" resultMap="BaseResultMap">
|
||||
select
|
||||
@ -83,16 +84,6 @@
|
||||
order by ${orderByClause}
|
||||
</if>
|
||||
</select>
|
||||
<select id="selectByPrimaryKey" parameterType="java.lang.String" resultMap="BaseResultMap">
|
||||
select
|
||||
<include refid="Base_Column_List" />
|
||||
from panel_link
|
||||
where resource_id = #{resourceId,jdbcType=VARCHAR}
|
||||
</select>
|
||||
<delete id="deleteByPrimaryKey" parameterType="java.lang.String">
|
||||
delete from panel_link
|
||||
where resource_id = #{resourceId,jdbcType=VARCHAR}
|
||||
</delete>
|
||||
<delete id="deleteByExample" parameterType="io.dataease.base.domain.PanelLinkExample">
|
||||
delete from panel_link
|
||||
<if test="_parameter != null">
|
||||
@ -101,9 +92,11 @@
|
||||
</delete>
|
||||
<insert id="insert" parameterType="io.dataease.base.domain.PanelLink">
|
||||
insert into panel_link (resource_id, `valid`, enable_pwd,
|
||||
pwd, over_time)
|
||||
pwd, over_time, user_id
|
||||
)
|
||||
values (#{resourceId,jdbcType=VARCHAR}, #{valid,jdbcType=BIT}, #{enablePwd,jdbcType=BIT},
|
||||
#{pwd,jdbcType=VARCHAR}, #{overTime,jdbcType=BIGINT})
|
||||
#{pwd,jdbcType=VARCHAR}, #{overTime,jdbcType=BIGINT}, #{userId,jdbcType=BIGINT}
|
||||
)
|
||||
</insert>
|
||||
<insert id="insertSelective" parameterType="io.dataease.base.domain.PanelLink">
|
||||
insert into panel_link
|
||||
@ -123,6 +116,9 @@
|
||||
<if test="overTime != null">
|
||||
over_time,
|
||||
</if>
|
||||
<if test="userId != null">
|
||||
user_id,
|
||||
</if>
|
||||
</trim>
|
||||
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||
<if test="resourceId != null">
|
||||
@ -140,6 +136,9 @@
|
||||
<if test="overTime != null">
|
||||
#{overTime,jdbcType=BIGINT},
|
||||
</if>
|
||||
<if test="userId != null">
|
||||
#{userId,jdbcType=BIGINT},
|
||||
</if>
|
||||
</trim>
|
||||
</insert>
|
||||
<select id="countByExample" parameterType="io.dataease.base.domain.PanelLinkExample" resultType="java.lang.Long">
|
||||
@ -166,6 +165,9 @@
|
||||
<if test="record.overTime != null">
|
||||
over_time = #{record.overTime,jdbcType=BIGINT},
|
||||
</if>
|
||||
<if test="record.userId != null">
|
||||
user_id = #{record.userId,jdbcType=BIGINT},
|
||||
</if>
|
||||
</set>
|
||||
<if test="_parameter != null">
|
||||
<include refid="Update_By_Example_Where_Clause" />
|
||||
@ -177,35 +179,10 @@
|
||||
`valid` = #{record.valid,jdbcType=BIT},
|
||||
enable_pwd = #{record.enablePwd,jdbcType=BIT},
|
||||
pwd = #{record.pwd,jdbcType=VARCHAR},
|
||||
over_time = #{record.overTime,jdbcType=BIGINT}
|
||||
over_time = #{record.overTime,jdbcType=BIGINT},
|
||||
user_id = #{record.userId,jdbcType=BIGINT}
|
||||
<if test="_parameter != null">
|
||||
<include refid="Update_By_Example_Where_Clause" />
|
||||
</if>
|
||||
</update>
|
||||
<update id="updateByPrimaryKeySelective" parameterType="io.dataease.base.domain.PanelLink">
|
||||
update panel_link
|
||||
<set>
|
||||
<if test="valid != null">
|
||||
`valid` = #{valid,jdbcType=BIT},
|
||||
</if>
|
||||
<if test="enablePwd != null">
|
||||
enable_pwd = #{enablePwd,jdbcType=BIT},
|
||||
</if>
|
||||
<if test="pwd != null">
|
||||
pwd = #{pwd,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="overTime != null">
|
||||
over_time = #{overTime,jdbcType=BIGINT},
|
||||
</if>
|
||||
</set>
|
||||
where resource_id = #{resourceId,jdbcType=VARCHAR}
|
||||
</update>
|
||||
<update id="updateByPrimaryKey" parameterType="io.dataease.base.domain.PanelLink">
|
||||
update panel_link
|
||||
set `valid` = #{valid,jdbcType=BIT},
|
||||
enable_pwd = #{enablePwd,jdbcType=BIT},
|
||||
pwd = #{pwd,jdbcType=VARCHAR},
|
||||
over_time = #{overTime,jdbcType=BIGINT}
|
||||
where resource_id = #{resourceId,jdbcType=VARCHAR}
|
||||
</update>
|
||||
</mapper>
|
@ -4,6 +4,7 @@
|
||||
<resultMap id="BaseResultMap" type="io.dataease.base.domain.PanelLinkMapping">
|
||||
<id column="id" jdbcType="BIGINT" property="id" />
|
||||
<result column="resource_id" jdbcType="VARCHAR" property="resourceId" />
|
||||
<result column="user_id" jdbcType="BIGINT" property="userId" />
|
||||
</resultMap>
|
||||
<sql id="Example_Where_Clause">
|
||||
<where>
|
||||
@ -64,7 +65,7 @@
|
||||
</where>
|
||||
</sql>
|
||||
<sql id="Base_Column_List">
|
||||
id, resource_id
|
||||
id, resource_id, user_id
|
||||
</sql>
|
||||
<select id="selectByExample" parameterType="io.dataease.base.domain.PanelLinkMappingExample" resultMap="BaseResultMap">
|
||||
select
|
||||
@ -97,8 +98,10 @@
|
||||
</if>
|
||||
</delete>
|
||||
<insert id="insert" parameterType="io.dataease.base.domain.PanelLinkMapping">
|
||||
insert into panel_link_mapping (id, resource_id)
|
||||
values (#{id,jdbcType=BIGINT}, #{resourceId,jdbcType=VARCHAR})
|
||||
insert into panel_link_mapping (id, resource_id, user_id
|
||||
)
|
||||
values (#{id,jdbcType=BIGINT}, #{resourceId,jdbcType=VARCHAR}, #{userId,jdbcType=BIGINT}
|
||||
)
|
||||
</insert>
|
||||
<insert id="insertSelective" parameterType="io.dataease.base.domain.PanelLinkMapping">
|
||||
insert into panel_link_mapping
|
||||
@ -109,6 +112,9 @@
|
||||
<if test="resourceId != null">
|
||||
resource_id,
|
||||
</if>
|
||||
<if test="userId != null">
|
||||
user_id,
|
||||
</if>
|
||||
</trim>
|
||||
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||
<if test="id != null">
|
||||
@ -117,6 +123,9 @@
|
||||
<if test="resourceId != null">
|
||||
#{resourceId,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="userId != null">
|
||||
#{userId,jdbcType=BIGINT},
|
||||
</if>
|
||||
</trim>
|
||||
</insert>
|
||||
<select id="countByExample" parameterType="io.dataease.base.domain.PanelLinkMappingExample" resultType="java.lang.Long">
|
||||
@ -134,6 +143,9 @@
|
||||
<if test="record.resourceId != null">
|
||||
resource_id = #{record.resourceId,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="record.userId != null">
|
||||
user_id = #{record.userId,jdbcType=BIGINT},
|
||||
</if>
|
||||
</set>
|
||||
<if test="_parameter != null">
|
||||
<include refid="Update_By_Example_Where_Clause" />
|
||||
@ -142,7 +154,8 @@
|
||||
<update id="updateByExample" parameterType="map">
|
||||
update panel_link_mapping
|
||||
set id = #{record.id,jdbcType=BIGINT},
|
||||
resource_id = #{record.resourceId,jdbcType=VARCHAR}
|
||||
resource_id = #{record.resourceId,jdbcType=VARCHAR},
|
||||
user_id = #{record.userId,jdbcType=BIGINT}
|
||||
<if test="_parameter != null">
|
||||
<include refid="Update_By_Example_Where_Clause" />
|
||||
</if>
|
||||
@ -153,12 +166,16 @@
|
||||
<if test="resourceId != null">
|
||||
resource_id = #{resourceId,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="userId != null">
|
||||
user_id = #{userId,jdbcType=BIGINT},
|
||||
</if>
|
||||
</set>
|
||||
where id = #{id,jdbcType=BIGINT}
|
||||
</update>
|
||||
<update id="updateByPrimaryKey" parameterType="io.dataease.base.domain.PanelLinkMapping">
|
||||
update panel_link_mapping
|
||||
set resource_id = #{resourceId,jdbcType=VARCHAR}
|
||||
set resource_id = #{resourceId,jdbcType=VARCHAR},
|
||||
user_id = #{userId,jdbcType=BIGINT}
|
||||
where id = #{id,jdbcType=BIGINT}
|
||||
</update>
|
||||
</mapper>
|
@ -8,7 +8,7 @@
|
||||
|
||||
|
||||
<update id="updateOverTime" >
|
||||
update panel_link set over_time = #{request.overTime} where resource_id = #{request.resourceId}
|
||||
update panel_link set over_time = #{request.overTime} where resource_id = #{request.resourceId} and user_id = #{request.userId}
|
||||
</update>
|
||||
|
||||
|
||||
|
@ -2,7 +2,6 @@ package io.dataease.controller.panel.api;
|
||||
|
||||
|
||||
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
|
||||
import io.dataease.controller.ResultHolder;
|
||||
import io.dataease.controller.request.chart.ChartExtRequest;
|
||||
import io.dataease.controller.request.panel.link.*;
|
||||
import io.dataease.dto.panel.link.GenerateDto;
|
||||
@ -48,7 +47,7 @@ public interface LinkApi {
|
||||
boolean validatePwd(PasswordRequest request) throws Exception;
|
||||
|
||||
@ApiOperation("资源详息")
|
||||
@PostMapping("/resourceDetail/{resourceId}")
|
||||
@GetMapping("/resourceDetail/{resourceId}")
|
||||
Object resourceDetail(@PathVariable String resourceId);
|
||||
|
||||
@ApiOperation("视图详息")
|
||||
|
@ -66,7 +66,7 @@ public class LinkServer implements LinkApi {
|
||||
|
||||
ValidateDto dto = new ValidateDto();
|
||||
String resourceId = json;
|
||||
PanelLink one = panelLinkService.findOne(resourceId);
|
||||
PanelLink one = panelLinkService.findOne(resourceId, request.getUser());
|
||||
dto.setResourceId(resourceId);
|
||||
if (ObjectUtils.isEmpty(one)) {
|
||||
dto.setValid(false);
|
||||
|
@ -34,4 +34,7 @@ public class ChartExtRequest {
|
||||
|
||||
@ApiModelProperty("使用缓存:默认使用")
|
||||
private boolean cache = true;
|
||||
|
||||
@ApiModelProperty("用户ID")
|
||||
private Long user = null;
|
||||
}
|
||||
|
@ -8,4 +8,5 @@ import java.io.Serializable;
|
||||
public class LinkValidateRequest implements Serializable {
|
||||
|
||||
private String link;
|
||||
private Long user;
|
||||
}
|
||||
|
@ -13,6 +13,9 @@ public class OverTimeRequest {
|
||||
@ApiModelProperty("资源ID")
|
||||
private String resourceId;
|
||||
|
||||
@ApiModelProperty("用户ID")
|
||||
private Long userId;
|
||||
|
||||
@ApiModelProperty("过期时间")
|
||||
private Long overTime;
|
||||
|
||||
|
@ -8,6 +8,8 @@ public class PasswordRequest {
|
||||
|
||||
@ApiModelProperty("资源ID")
|
||||
private String resourceId;
|
||||
@ApiModelProperty("用户ID")
|
||||
private Long user = null;
|
||||
@ApiModelProperty("密码")
|
||||
private String password;
|
||||
|
||||
|
@ -212,7 +212,7 @@ public class ChartViewService {
|
||||
DatasetTableField datasetTableFieldObj = DatasetTableField.builder().tableId(view.getTableId()).checked(Boolean.TRUE).build();
|
||||
List<DatasetTableField> fields = dataSetTableFieldsService.list(datasetTableFieldObj);
|
||||
DatasetTable datasetTable = dataSetTableService.get(view.getTableId());
|
||||
List<ChartFieldCustomFilterDTO> permissionFields = dataSetTableService.getCustomFilters(fields, datasetTable);
|
||||
List<ChartFieldCustomFilterDTO> permissionFields = dataSetTableService.getCustomFilters(fields, datasetTable, requestList.getUser());
|
||||
fieldCustomFilter.addAll(permissionFields);
|
||||
|
||||
for (ChartFieldCustomFilterDTO ele : fieldCustomFilter) {
|
||||
|
@ -442,7 +442,7 @@ public class DataSetTableService {
|
||||
return map;
|
||||
}
|
||||
|
||||
private List<DatasetRowPermissions> rowPermissions(String datasetId) {
|
||||
private List<DatasetRowPermissions> rowPermissions(String datasetId, Long userId) {
|
||||
List<DatasetRowPermissions> datasetRowPermissions = new ArrayList<>();
|
||||
Map<String, RowPermissionService> beansOfType = SpringContextUtil.getApplicationContext().getBeansOfType((RowPermissionService.class));
|
||||
if (beansOfType.keySet().size() == 0) {
|
||||
@ -450,11 +450,10 @@ public class DataSetTableService {
|
||||
}
|
||||
RowPermissionService rowPermissionService = SpringContextUtil.getBean(RowPermissionService.class);
|
||||
CurrentUserDto user = AuthUtils.getUser();
|
||||
if (user != null) {
|
||||
datasetRowPermissions.addAll(rowPermissionService.listDatasetRowPermissions(datasetId, Collections.singletonList(user.getUserId()), "user"));
|
||||
datasetRowPermissions.addAll(rowPermissionService.listDatasetRowPermissions(datasetId, user.getRoles().stream().map(CurrentRoleDto::getId).collect(Collectors.toList()), "role"));
|
||||
datasetRowPermissions.addAll(rowPermissionService.listDatasetRowPermissions(datasetId, Collections.singletonList(user.getDeptId()), "dept"));
|
||||
}
|
||||
userId = user != null? user.getUserId() : userId;
|
||||
datasetRowPermissions.addAll(rowPermissionService.listDatasetRowPermissions(datasetId, Collections.singletonList(user.getUserId()), "user"));
|
||||
datasetRowPermissions.addAll(rowPermissionService.listDatasetRowPermissions(datasetId, user.getRoles().stream().map(CurrentRoleDto::getId).collect(Collectors.toList()), "role"));
|
||||
datasetRowPermissions.addAll(rowPermissionService.listDatasetRowPermissions(datasetId, Collections.singletonList(user.getDeptId()), "dept"));
|
||||
return datasetRowPermissions;
|
||||
}
|
||||
|
||||
@ -468,9 +467,9 @@ public class DataSetTableService {
|
||||
return field;
|
||||
}
|
||||
|
||||
public List<ChartFieldCustomFilterDTO> getCustomFilters(List<DatasetTableField> fields, DatasetTable datasetTable) {
|
||||
public List<ChartFieldCustomFilterDTO> getCustomFilters(List<DatasetTableField> fields, DatasetTable datasetTable, Long user) {
|
||||
List<ChartFieldCustomFilterDTO> customFilter = new ArrayList<>();
|
||||
rowPermissions(datasetTable.getId()).forEach(datasetRowPermissions -> {
|
||||
rowPermissions(datasetTable.getId(), user).forEach(datasetRowPermissions -> {
|
||||
List<ChartCustomFilterItemDTO> lists = JSONObject.parseArray(datasetRowPermissions.getFilter(), ChartCustomFilterItemDTO.class);
|
||||
ChartFieldCustomFilterDTO dto = new ChartFieldCustomFilterDTO();
|
||||
DatasetTableField field = getFieldById(fields, datasetRowPermissions.getDatasetFieldId());
|
||||
@ -499,7 +498,7 @@ public class DataSetTableService {
|
||||
return map;
|
||||
}
|
||||
DatasetTable datasetTable = datasetTableMapper.selectByPrimaryKey(dataSetTableRequest.getId());
|
||||
List<ChartFieldCustomFilterDTO> customFilter = getCustomFilters(fields, datasetTable);
|
||||
List<ChartFieldCustomFilterDTO> customFilter = getCustomFilters(fields, datasetTable, null);
|
||||
String[] fieldArray = fields.stream().map(DatasetTableField::getDataeaseName).toArray(String[]::new);
|
||||
|
||||
DataTableInfoDTO dataTableInfoDTO = new Gson().fromJson(dataSetTableRequest.getInfo(), DataTableInfoDTO.class);
|
||||
|
@ -58,7 +58,7 @@ public class DirectFieldService implements DataSetFieldService {
|
||||
|
||||
DatasetTableField datasetTableField = DatasetTableField.builder().tableId(tableId).checked(Boolean.TRUE).build();
|
||||
List<DatasetTableField> fields = dataSetTableFieldsService.list(datasetTableField);
|
||||
List<ChartFieldCustomFilterDTO> customFilter = dataSetTableService.getCustomFilters(fields, datasetTable);
|
||||
List<ChartFieldCustomFilterDTO> customFilter = dataSetTableService.getCustomFilters(fields, datasetTable, null);
|
||||
|
||||
DatasourceRequest datasourceRequest = new DatasourceRequest();
|
||||
DatasourceProvider datasourceProvider = null;
|
||||
|
@ -3,14 +3,12 @@ package io.dataease.service.panel;
|
||||
import io.dataease.auth.config.RsaProperties;
|
||||
import io.dataease.auth.util.JWTUtils;
|
||||
import io.dataease.auth.util.RsaUtil;
|
||||
import io.dataease.base.domain.PanelGroupWithBLOBs;
|
||||
import io.dataease.base.domain.PanelLink;
|
||||
import io.dataease.base.domain.PanelLinkMapping;
|
||||
import io.dataease.base.domain.PanelLinkMappingExample;
|
||||
import io.dataease.base.domain.*;
|
||||
import io.dataease.base.mapper.PanelGroupMapper;
|
||||
import io.dataease.base.mapper.PanelLinkMapper;
|
||||
import io.dataease.base.mapper.PanelLinkMappingMapper;
|
||||
import io.dataease.base.mapper.ext.ExtPanelLinkMapper;
|
||||
import io.dataease.commons.utils.AuthUtils;
|
||||
import io.dataease.commons.utils.ServletUtils;
|
||||
import io.dataease.controller.request.panel.link.EnablePwdRequest;
|
||||
import io.dataease.controller.request.panel.link.LinkRequest;
|
||||
@ -27,11 +25,13 @@ import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@Service
|
||||
public class PanelLinkService {
|
||||
|
||||
private static final String BASEURL = "/link.html?link=";
|
||||
private static final String USERPARAM = "&user=";
|
||||
private static final String SHORT_URL_PREFIX = "/link/";
|
||||
|
||||
@Resource
|
||||
@ -47,63 +47,89 @@ public class PanelLinkService {
|
||||
PanelLink po = new PanelLink();
|
||||
po.setResourceId(request.getResourceId());
|
||||
po.setValid(request.isValid());
|
||||
mapper.updateByPrimaryKeySelective(po);
|
||||
mapper.updateByExampleSelective(po, example(request.getResourceId(), AuthUtils.getUser().getUserId()));
|
||||
}
|
||||
|
||||
private PanelLinkExample example(String panelLinkId, Long userId){
|
||||
PanelLinkExample example = new PanelLinkExample();
|
||||
example.createCriteria().andResourceIdEqualTo(panelLinkId).andUserIdEqualTo(userId);
|
||||
return example;
|
||||
}
|
||||
|
||||
public void changeEnablePwd(EnablePwdRequest request) {
|
||||
PanelLink po = new PanelLink();
|
||||
po.setResourceId(request.getResourceId());
|
||||
po.setEnablePwd(request.isEnablePwd());
|
||||
mapper.updateByPrimaryKeySelective(po);
|
||||
mapper.updateByExampleSelective(po, example(request.getResourceId(), AuthUtils.getUser().getUserId()));
|
||||
}
|
||||
|
||||
public void password(PasswordRequest request) {
|
||||
PanelLink po = new PanelLink();
|
||||
po.setResourceId(request.getResourceId());
|
||||
po.setPwd(request.getPassword());
|
||||
mapper.updateByPrimaryKeySelective(po);
|
||||
mapper.updateByExampleSelective(po, example(request.getResourceId(), AuthUtils.getUser().getUserId()));
|
||||
}
|
||||
|
||||
public void overTime(OverTimeRequest request) {
|
||||
request.setUserId(AuthUtils.getUser().getUserId());
|
||||
extPanelLinkMapper.updateOverTime(request);
|
||||
}
|
||||
|
||||
public PanelLink findOne(String resourceId) {
|
||||
return mapper.selectByPrimaryKey(resourceId);
|
||||
private PanelLink findOne(String resourceId) {
|
||||
PanelLinkExample example = new PanelLinkExample();
|
||||
example.createCriteria().andResourceIdEqualTo(resourceId).andUserIdIsNull();
|
||||
List<PanelLink> list = mapper.selectByExample(example);
|
||||
return CollectionUtils.isNotEmpty(list) ? list.get(0) : null;
|
||||
}
|
||||
|
||||
public PanelLink findOne(String resourceId, Long userId) {
|
||||
if(userId == null){
|
||||
return findOne(resourceId);
|
||||
}
|
||||
List<PanelLink> panelLinks = mapper.selectByExample(example(resourceId, userId));
|
||||
if(CollectionUtils.isNotEmpty(panelLinks)){
|
||||
return panelLinks.get(0);
|
||||
}else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public GenerateDto currentGenerate(String resourceId) {
|
||||
PanelLink one = findOne(resourceId);
|
||||
PanelLink one = findOne(resourceId, AuthUtils.getUser().getUserId());
|
||||
if (ObjectUtils.isEmpty(one)) {
|
||||
one = new PanelLink();
|
||||
one.setPwd(null);
|
||||
one.setResourceId(resourceId);
|
||||
one.setValid(false);
|
||||
one.setUserId(AuthUtils.getUser().getUserId());
|
||||
one.setEnablePwd(false);
|
||||
mapper.insert(one);
|
||||
}
|
||||
|
||||
PanelLinkMappingExample example = new PanelLinkMappingExample();
|
||||
example.createCriteria().andResourceIdEqualTo(resourceId);
|
||||
example.createCriteria().andResourceIdEqualTo(resourceId).andUserIdEqualTo(AuthUtils.getUser().getUserId());
|
||||
List<PanelLinkMapping> mappings = panelLinkMappingMapper.selectByExample(example);
|
||||
if (CollectionUtils.isEmpty(mappings)) {
|
||||
PanelLinkMapping mapping = new PanelLinkMapping();
|
||||
mapping.setResourceId(resourceId);
|
||||
mapping.setUserId(AuthUtils.getUser().getUserId());
|
||||
panelLinkMappingMapper.insert(mapping);
|
||||
}
|
||||
return convertDto(one);
|
||||
}
|
||||
|
||||
public void deleteByResourceId(String resourceId) {
|
||||
mapper.deleteByPrimaryKey(resourceId);
|
||||
PanelLinkExample example = new PanelLinkExample();
|
||||
example.createCriteria().andResourceIdEqualTo(resourceId);
|
||||
mapper.deleteByExample(example);
|
||||
}
|
||||
|
||||
public String decryptParam(String text) throws Exception {
|
||||
return RsaUtil.decryptByPrivateKey(RsaProperties.privateKey, text);
|
||||
}
|
||||
|
||||
// 使用共钥加密
|
||||
// 使用公钥加密
|
||||
private String encrypt(String sourceValue) {
|
||||
try {
|
||||
return RsaUtil.encryptByPublicKey(RsaProperties.publicKey, sourceValue);
|
||||
@ -113,8 +139,12 @@ public class PanelLinkService {
|
||||
return null;
|
||||
}
|
||||
|
||||
private String buildLinkParam(String resourceId) {
|
||||
return encrypt(resourceId);
|
||||
private String buildLinkParam(PanelLink link) {
|
||||
String linkParam = encrypt(link.getResourceId());
|
||||
if(link.getUserId() != null){
|
||||
linkParam = linkParam+ USERPARAM + link.getUserId().toString();
|
||||
}
|
||||
return linkParam;
|
||||
}
|
||||
|
||||
private GenerateDto convertDto(PanelLink link) {
|
||||
@ -122,7 +152,7 @@ public class PanelLinkService {
|
||||
result.setValid(link.getValid());
|
||||
result.setEnablePwd(link.getEnablePwd());
|
||||
result.setPwd(link.getPwd());
|
||||
result.setUri(BASEURL + buildLinkParam(link.getResourceId()));
|
||||
result.setUri(BASEURL + buildLinkParam(link));
|
||||
result.setOverTime(link.getOverTime());
|
||||
return result;
|
||||
}
|
||||
@ -134,14 +164,14 @@ public class PanelLinkService {
|
||||
if (!panelLink.getEnablePwd() || StringUtils.isEmpty(token) || StringUtils.equals("undefined", token) || StringUtils.equals("null", token)) {
|
||||
String resourceId = panelLink.getResourceId();
|
||||
String pwd = "dataease";
|
||||
String tk = JWTUtils.signLink(resourceId, pwd);
|
||||
String tk = JWTUtils.signLink(resourceId, panelLink.getUserId(), pwd);
|
||||
HttpServletResponse httpServletResponse = ServletUtils.response();
|
||||
httpServletResponse.addHeader("Access-Control-Expose-Headers", "LINK-PWD-TOKEN");
|
||||
httpServletResponse.setHeader("LINK-PWD-TOKEN", tk);
|
||||
return false;
|
||||
}
|
||||
if (StringUtils.isEmpty(panelLink.getPwd())) return false;
|
||||
return JWTUtils.verifyLink(token, panelLink.getResourceId(), panelLink.getPwd());
|
||||
return JWTUtils.verifyLink(token, panelLink.getResourceId(), panelLink.getUserId(), panelLink.getPwd());
|
||||
}
|
||||
|
||||
// 验证链接是否过期
|
||||
@ -155,11 +185,11 @@ public class PanelLinkService {
|
||||
public boolean validatePwd(PasswordRequest request) throws Exception {
|
||||
String password = request.getPassword();
|
||||
String resourceId = request.getResourceId();
|
||||
PanelLink one = findOne(resourceId);
|
||||
PanelLink one = findOne(resourceId, request.getUser());
|
||||
String pwd = one.getPwd();
|
||||
boolean pass = StringUtils.equals(pwd, password);
|
||||
if (pass) {
|
||||
String token = JWTUtils.signLink(resourceId, password);
|
||||
String token = JWTUtils.signLink(resourceId, request.getUser(), password);
|
||||
HttpServletResponse httpServletResponse = ServletUtils.response();
|
||||
httpServletResponse.addHeader("Access-Control-Expose-Headers", "LINK-PWD-TOKEN");
|
||||
httpServletResponse.setHeader("LINK-PWD-TOKEN", token);
|
||||
@ -173,7 +203,7 @@ public class PanelLinkService {
|
||||
|
||||
public String getShortUrl(String resourceId) {
|
||||
PanelLinkMappingExample example = new PanelLinkMappingExample();
|
||||
example.createCriteria().andResourceIdEqualTo(resourceId);
|
||||
example.createCriteria().andResourceIdEqualTo(resourceId).andUserIdEqualTo(AuthUtils.getUser().getUserId());
|
||||
List<PanelLinkMapping> mappings = panelLinkMappingMapper.selectByExample(example);
|
||||
PanelLinkMapping mapping = mappings.get(0);
|
||||
return SHORT_URL_PREFIX + mapping.getId();
|
||||
@ -182,7 +212,8 @@ public class PanelLinkService {
|
||||
public String getUrlByIndex(Long index) {
|
||||
PanelLinkMapping mapping = panelLinkMappingMapper.selectByPrimaryKey(index);
|
||||
String resourceId = mapping.getResourceId();
|
||||
PanelLink one = findOne(resourceId);
|
||||
Long userId = mapping.getUserId();
|
||||
PanelLink one = findOne(resourceId, userId);
|
||||
return convertDto(one).getUri();
|
||||
}
|
||||
}
|
||||
|
@ -10,5 +10,13 @@ CREATE TABLE `dataset_row_permissions` (
|
||||
PRIMARY KEY (`id`)
|
||||
)ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE utf8mb4_general_ci;
|
||||
|
||||
|
||||
ALTER TABLE `panel_link` ADD COLUMN `user_id` BIGINT(20) NULL DEFAULT NULL ;
|
||||
|
||||
ALTER TABLE `panel_link_mapping` ADD COLUMN `user_id` BIGINT(20) NULL DEFAULT NULL ;
|
||||
|
||||
ALTER TABLE `panel_link`CHANGE COLUMN `user_id` `user_id` BIGINT(20) NOT NULL ,DROP PRIMARY KEY;
|
||||
|
||||
ALTER TABLE `panel_group`
|
||||
ADD COLUMN `mobile_layout` tinyint(1) NULL DEFAULT 0 COMMENT '启用移动端布局' AFTER `remark`;
|
||||
|
||||
|
@ -60,13 +60,8 @@
|
||||
</javaClientGenerator>
|
||||
|
||||
<!--要生成的数据库表 -->
|
||||
<!-- <table tableName="dataset_row_permissions">-->
|
||||
<!-- <columnOverride column="filter" javaType="java.lang.String" jdbcType="VARCHAR" />-->
|
||||
<!-- </table>-->
|
||||
|
||||
<table tableName="panel_link_mapping">
|
||||
</table>
|
||||
<table tableName="panel_group"/>
|
||||
|
||||
|
||||
|
||||
</context>
|
||||
</generatorConfiguration>
|
||||
|
@ -30,13 +30,16 @@
|
||||
return (false)
|
||||
}
|
||||
const link = getQueryVariable('link')
|
||||
const user = getQueryVariable('user')
|
||||
const terminal = getQueryVariable('terminal')
|
||||
let url = "/#/delink?link=" + encodeURIComponent(link)
|
||||
if (terminal) {
|
||||
url += '&terminal=' + terminal
|
||||
}
|
||||
if (user) {
|
||||
url += '&user=' + user
|
||||
}
|
||||
window.location.href = url
|
||||
|
||||
</script>
|
||||
|
||||
</html>
|
||||
|
@ -60,7 +60,7 @@ export function loadGenerate(resourceId) {
|
||||
export function loadResource(resourceId) {
|
||||
return request({
|
||||
url: 'api/link/resourceDetail/' + resourceId,
|
||||
method: 'post'
|
||||
method: 'get'
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -175,6 +175,7 @@ export default {
|
||||
filter.drill = this.drillClickDimensionList
|
||||
filter.resultCount = this.resultCount
|
||||
filter.resultMode = this.resultMode
|
||||
filter.user = this.element.user
|
||||
filter.queryFrom = 'panel'
|
||||
return filter
|
||||
},
|
||||
|
@ -269,15 +269,16 @@ export function formatQuickCondition(param, quickField) {
|
||||
}
|
||||
|
||||
export function getQueryVariable(variable) {
|
||||
debugger
|
||||
let query = window.location.search.substring(1)
|
||||
if (!query) {
|
||||
query = Cookies.get(variable)
|
||||
}
|
||||
const vars = query.split('&')
|
||||
for (var i = 0; i < vars.length; i++) {
|
||||
const pair = vars[i].split('=')
|
||||
if (pair[0] === variable) { return pair[1] }
|
||||
if (query !== undefined){
|
||||
const vars = query.split('&')
|
||||
for (var i = 0; i < vars.length; i++) {
|
||||
const pair = vars[i].split('=')
|
||||
if (pair[0] === variable) { return pair[1] }
|
||||
}
|
||||
}
|
||||
return (false)
|
||||
}
|
||||
|
@ -1,9 +1,9 @@
|
||||
<template>
|
||||
<div style="height: 100%;">
|
||||
<link-error v-if="showIndex===0" :resource-id="resourceId" />
|
||||
<link-pwd v-if="showIndex===1" :resource-id="resourceId" @fresh-token="refreshToken" />
|
||||
<link-view v-if="showIndex===2" :resource-id="resourceId" />
|
||||
<link-expire v-if="showIndex===3" :resource-id="resourceId" />
|
||||
<link-pwd v-if="showIndex===1" :resource-id="resourceId" :user="user" @fresh-token="refreshToken" />
|
||||
<link-view v-if="showIndex===2" :resource-id="resourceId" :user="user"/>
|
||||
<link-expire v-if="showIndex===3" :resource-id="resourceId" :user="user"/>
|
||||
</div>
|
||||
</template>
|
||||
<script>
|
||||
@ -23,6 +23,7 @@ export default {
|
||||
resourceId: null,
|
||||
PARAMKEY: 'link',
|
||||
link: null,
|
||||
user: null,
|
||||
showIndex: -1
|
||||
}
|
||||
},
|
||||
@ -33,17 +34,20 @@ export default {
|
||||
|
||||
loadInit() {
|
||||
this.$store.commit('setPublicLinkStatus', true)
|
||||
debugger
|
||||
// this.link = getQueryVariable(this.PARAMKEY)
|
||||
this.link = this.$route.query.link
|
||||
this.user = this.$route.query.user
|
||||
if (!this.link) {
|
||||
this.link = getQueryVariable(this.PARAMKEY)
|
||||
}
|
||||
if (!this.user) {
|
||||
this.user = getQueryVariable('user')
|
||||
}
|
||||
if (!this.link) {
|
||||
this.showError()
|
||||
return
|
||||
}
|
||||
validate({ link: encodeURIComponent(this.link) }).then(res => {
|
||||
let params = this.user ? { link: encodeURIComponent(this.link), user: this.user} : { link: encodeURIComponent(this.link)};
|
||||
validate(params).then(res => {
|
||||
const { resourceId, valid, enablePwd, passPwd, expire } = res.data
|
||||
this.resourceId = resourceId
|
||||
// 如果链接无效 直接显示无效页面
|
||||
|
@ -45,6 +45,10 @@ export default {
|
||||
resourceId: {
|
||||
type: String,
|
||||
default: null
|
||||
},
|
||||
user: {
|
||||
type: String,
|
||||
default: null
|
||||
}
|
||||
},
|
||||
data() {
|
||||
@ -88,10 +92,7 @@ export default {
|
||||
this.msg = null
|
||||
this.$refs.pwdForm.validate(valid => {
|
||||
if (!valid) return false
|
||||
const param = {
|
||||
password: this.form.password,
|
||||
resourceId: this.resourceId
|
||||
}
|
||||
const param = this.user ? {password: this.form.password, resourceId: this.resourceId, user: this.user} : {password: this.form.password, resourceId: this.resourceId}
|
||||
validatePwd(param).then(res => {
|
||||
if (!res.data) {
|
||||
this.msg = this.$t('pblink.pwd_error')
|
||||
|
@ -18,6 +18,10 @@ export default {
|
||||
resourceId: {
|
||||
type: String,
|
||||
default: null
|
||||
},
|
||||
user: {
|
||||
type: String,
|
||||
default: null
|
||||
}
|
||||
},
|
||||
data() {
|
||||
|
Loading…
Reference in New Issue
Block a user