Unverified 提交 9b28cf62 authored 作者: fit2cloud-chenyw's avatar fit2cloud-chenyw 提交者: GitHub

Merge pull request #1861 from dataease/pr@v1.8@refactor_panel_share

refactor: 分享列表仪表板使用代理权限查看
...@@ -8,7 +8,7 @@ import java.lang.annotation.Retention; ...@@ -8,7 +8,7 @@ import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy; import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target; import java.lang.annotation.Target;
@Target({ElementType.TYPE, ElementType.METHOD}) @Target({ ElementType.TYPE, ElementType.METHOD })
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
public @interface DePermission { public @interface DePermission {
......
package io.dataease.auth.annotation;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Target({ ElementType.TYPE, ElementType.METHOD })
@Retention(RetentionPolicy.RUNTIME)
public @interface DePermissionProxy {
String value() default "";
int paramIndex() default 0;
}
package io.dataease.auth.aop; package io.dataease.auth.aop;
import io.dataease.auth.annotation.DeCleaner; import io.dataease.auth.annotation.DeCleaner;
import io.dataease.auth.api.dto.CurrentUserDto; import io.dataease.auth.api.dto.CurrentUserDto;
import io.dataease.commons.constants.AuthConstants; import io.dataease.commons.constants.AuthConstants;
...@@ -23,7 +22,6 @@ public class DeCleanerAnnotationHandler { ...@@ -23,7 +22,6 @@ public class DeCleanerAnnotationHandler {
@Around(value = "@annotation(io.dataease.auth.annotation.DeCleaner)") @Around(value = "@annotation(io.dataease.auth.annotation.DeCleaner)")
public Object CleanerAround(ProceedingJoinPoint point) { public Object CleanerAround(ProceedingJoinPoint point) {
try { try {
CurrentUserDto user = AuthUtils.getUser();
MethodSignature ms = (MethodSignature) point.getSignature(); MethodSignature ms = (MethodSignature) point.getSignature();
Method method = ms.getMethod(); Method method = ms.getMethod();
DeCleaner deCleaner = method.getAnnotation(DeCleaner.class); DeCleaner deCleaner = method.getAnnotation(DeCleaner.class);
...@@ -41,7 +39,7 @@ public class DeCleanerAnnotationHandler { ...@@ -41,7 +39,7 @@ public class DeCleanerAnnotationHandler {
} }
return point.proceed(point.getArgs()); return point.proceed(point.getArgs());
}catch (Throwable e) { } catch (Throwable e) {
LogUtil.error(e.getMessage(), e); LogUtil.error(e.getMessage(), e);
throw new RuntimeException(e); throw new RuntimeException(e);
} }
...@@ -55,6 +53,7 @@ public class DeCleanerAnnotationHandler { ...@@ -55,6 +53,7 @@ public class DeCleanerAnnotationHandler {
CacheUtils.remove(AuthConstants.ROLE_PANEL_NAME, "role" + role.getId()); CacheUtils.remove(AuthConstants.ROLE_PANEL_NAME, "role" + role.getId());
}); });
} }
public void cleanDataSet() { public void cleanDataSet() {
CurrentUserDto user = AuthUtils.getUser(); CurrentUserDto user = AuthUtils.getUser();
CacheUtils.remove(AuthConstants.USER_DATASET_NAME, "user" + user.getUserId()); CacheUtils.remove(AuthConstants.USER_DATASET_NAME, "user" + user.getUserId());
...@@ -63,6 +62,7 @@ public class DeCleanerAnnotationHandler { ...@@ -63,6 +62,7 @@ public class DeCleanerAnnotationHandler {
CacheUtils.remove(AuthConstants.ROLE_DATASET_NAME, "role" + role.getId()); CacheUtils.remove(AuthConstants.ROLE_DATASET_NAME, "role" + role.getId());
}); });
} }
public void cleanDataSource() { public void cleanDataSource() {
CurrentUserDto user = AuthUtils.getUser(); CurrentUserDto user = AuthUtils.getUser();
CacheUtils.remove(AuthConstants.USER_LINK_NAME, "user" + user.getUserId()); CacheUtils.remove(AuthConstants.USER_LINK_NAME, "user" + user.getUserId());
......
package io.dataease.auth.aop;
import java.lang.reflect.Array;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.Collection;
import java.util.Map;
import org.apache.commons.lang3.StringUtils;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import io.dataease.auth.annotation.DePermissionProxy;
import io.dataease.commons.utils.AuthUtils;
import io.dataease.commons.utils.LogUtil;
import io.dataease.dto.PermissionProxy;
@Aspect
@Component
@Order(0)
public class DePermissionProxyHandler {
@Around(value = "@annotation(io.dataease.auth.annotation.DePermissionProxy)")
public Object proxyAround(ProceedingJoinPoint point) {
try {
MethodSignature ms = (MethodSignature) point.getSignature();
Method method = ms.getMethod();
DePermissionProxy annotation = method.getAnnotation(DePermissionProxy.class);
Object[] args = point.getArgs();
if (null == args || args.length == 0) {
return point.proceed(args);
}
Object arg = point.getArgs()[annotation.paramIndex()];
/*
* if (arg instanceof PermissionProxy) {
* PermissionProxy proxy = (PermissionProxy) arg;
* AuthUtils.setProxyUser(proxy.getUserId());
* }
*/
PermissionProxy proxy = getProxy(arg, annotation, 0);
if (null != proxy && null != proxy.getUserId()) {
AuthUtils.setProxyUser(proxy.getUserId());
}
return point.proceed(args);
} catch (Throwable throwable) {
LogUtil.error(throwable.getMessage(), throwable);
throw new RuntimeException(throwable.getMessage());
} finally {
AuthUtils.cleanProxyUser();
}
}
private PermissionProxy getProxy(Object arg, DePermissionProxy annotation, int layer) throws Exception {
PermissionProxy result = null;
String value = annotation.value();
Class<?> parameterType = arg.getClass();
if (arg instanceof PermissionProxy) {
return (PermissionProxy) arg;
} else if (isArray(parameterType)) {
/*
* for (int i = 0; i < Array.getLength(arg); i++) {
* Object o = Array.get(arg, i);
* if ((result = getProxy(o, annotation, layer)) != null) {
* return result;
* }
* }
*/
return null;
} else if (isCollection(parameterType)) {
/*
* Object[] array = ((Collection) arg).toArray();
* for (int i = 0; i < array.length; i++) {
* Object o = array[i];
* if ((result = getProxy(o, annotation, layer)) != null) {
* return result;
* }
* }
*/
return null;
} else if (isMap(parameterType)) {
Map<String, Object> argMap = (Map) arg;
String[] values = value.split(".");
Object o = argMap.get(values[layer]);
return getProxy(o, annotation, ++layer);
} else {
// 当作自定义类处理
String[] values = value.split("\\.");
String fieldName = values[layer];
Object fieldValue = getFieldValue(arg, fieldName);
return getProxy(fieldValue, annotation, ++layer);
}
}
private Object getFieldValue(Object o, String fieldName) throws Exception {
Class<?> aClass = o.getClass();
while (null != aClass.getSuperclass()) {
Field[] declaredFields = aClass.getDeclaredFields();
for (int i = 0; i < declaredFields.length; i++) {
Field field = declaredFields[i];
String name = field.getName();
if (StringUtils.equals(name, fieldName)) {
field.setAccessible(true);
return field.get(o);
}
}
aClass = aClass.getSuperclass();
}
throw new NoSuchFieldException(fieldName);
}
private final static String[] wrapClasies = {
"java.lang.Boolean",
"java.lang.Character",
"java.lang.Integer",
"java.lang.Byte",
"java.lang.Short",
"java.lang.Long",
"java.lang.Float",
"java.lang.Double",
};
private Boolean isString(Class clz) {
return StringUtils.equals("java.lang.String", clz.getName());
}
private Boolean isArray(Class clz) {
return clz.isArray();
}
private Boolean isCollection(Class clz) {
return Collection.class.isAssignableFrom(clz);
}
private Boolean isMap(Class clz) {
return Map.class.isAssignableFrom(clz);
}
private Boolean isWrapClass(Class clz) {
return Arrays.stream(wrapClasies).anyMatch(item -> StringUtils.equals(item, clz.getName()));
}
}
...@@ -21,40 +21,37 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -21,40 +21,37 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy; import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.util.Collection;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@Component @Component
public class F2CRealm extends AuthorizingRealm { public class F2CRealm extends AuthorizingRealm {
@Autowired @Autowired
@Lazy //shiro组件加载过早 让authUserService等一等再注入 否则 注入的可能不是代理对象 @Lazy // shiro组件加载过早 让authUserService等一等再注入 否则 注入的可能不是代理对象
private AuthUserService authUserService; private AuthUserService authUserService;
@Override @Override
public boolean supports(AuthenticationToken token) { public boolean supports(AuthenticationToken token) {
return token instanceof JWTToken || token instanceof ASKToken; return token instanceof JWTToken || token instanceof ASKToken;
} }
//验证资源权限 // 验证资源权限
@Override @Override
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) { protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {
CurrentUserDto userDto = (CurrentUserDto)principals.getPrimaryPrincipal(); CurrentUserDto userDto = (CurrentUserDto) principals.getPrimaryPrincipal();
SimpleAuthorizationInfo simpleAuthorizationInfo = new SimpleAuthorizationInfo(); SimpleAuthorizationInfo simpleAuthorizationInfo = new SimpleAuthorizationInfo();
Set<String> role = new HashSet<>(userDto.getRoles().stream().map(item -> ( item.getId() + "")).collect(Collectors.toSet())); Set<String> role = new HashSet<>(
userDto.getRoles().stream().map(item -> (item.getId() + "")).collect(Collectors.toSet()));
simpleAuthorizationInfo.addRoles(role); simpleAuthorizationInfo.addRoles(role);
Set<String> permission = new HashSet<>(userDto.getPermissions()); Set<String> permission = new HashSet<>(userDto.getPermissions());
simpleAuthorizationInfo.addStringPermissions(permission); simpleAuthorizationInfo.addStringPermissions(permission);
return simpleAuthorizationInfo; return simpleAuthorizationInfo;
} }
//验证登录权限 // 验证登录权限
@Override @Override
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken auth) throws AuthenticationException { protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken auth) throws AuthenticationException {
...@@ -73,11 +70,9 @@ public class F2CRealm extends AuthorizingRealm { ...@@ -73,11 +70,9 @@ public class F2CRealm extends AuthorizingRealm {
return new SimpleAuthenticationInfo(currentUserDto, signature, "f2cReam"); return new SimpleAuthenticationInfo(currentUserDto, signature, "f2cReam");
} }
try { try {
CacheUtils.get("lic_info", "lic"); CacheUtils.get("lic_info", "lic");
}catch (Exception e) { } catch (Exception e) {
LogUtil.error(e); LogUtil.error(e);
throw new AuthenticationException("license error"); throw new AuthenticationException("license error");
} }
...@@ -88,7 +83,7 @@ public class F2CRealm extends AuthorizingRealm { ...@@ -88,7 +83,7 @@ public class F2CRealm extends AuthorizingRealm {
token = (String) auth.getCredentials(); token = (String) auth.getCredentials();
// 解密获得username,用于和数据库进行对比 // 解密获得username,用于和数据库进行对比
tokenInfo = JWTUtils.tokenInfoByToken(token); tokenInfo = JWTUtils.tokenInfoByToken(token);
}catch (Exception e) { } catch (Exception e) {
throw new AuthenticationException(e); throw new AuthenticationException(e);
} }
...@@ -105,7 +100,7 @@ public class F2CRealm extends AuthorizingRealm { ...@@ -105,7 +100,7 @@ public class F2CRealm extends AuthorizingRealm {
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
if (! JWTUtils.verify(token, tokenInfo, pass)) { if (!JWTUtils.verify(token, tokenInfo, pass)) {
throw new AuthenticationException("Username or password error"); throw new AuthenticationException("Username or password error");
} }
...@@ -118,7 +113,7 @@ public class F2CRealm extends AuthorizingRealm { ...@@ -118,7 +113,7 @@ public class F2CRealm extends AuthorizingRealm {
if (user == null) { if (user == null) {
throw new AuthenticationException("User didn't existed!"); throw new AuthenticationException("User didn't existed!");
} }
if (user.getEnabled()==0) { if (user.getEnabled() == 0) {
throw new AuthenticationException("User is valid!"); throw new AuthenticationException("User is valid!");
} }
return user; return user;
......
package io.dataease.auth.service;
import java.util.List;
import org.apache.shiro.authc.AuthenticationException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import groovy.lang.Lazy;
import io.dataease.auth.api.dto.CurrentRoleDto;
import io.dataease.auth.api.dto.CurrentUserDto;
import io.dataease.auth.entity.SysUserEntity;
import io.dataease.commons.utils.BeanUtils;
@Service
public class ProxyAuthService {
@Autowired
@Lazy
private AuthUserService authUserService;
public CurrentUserDto queryCacheUserDto(Long userId) {
SysUserEntity user = authUserService.getUserById(userId);
if (user == null) {
throw new AuthenticationException("User didn't existed!");
}
if (user.getEnabled() == 0) {
throw new AuthenticationException("User is valid!");
}
// 使用缓存
List<CurrentRoleDto> currentRoleDtos = authUserService.roleInfos(user.getUserId());
// 使用缓存
List<String> permissions = authUserService.permissions(user.getUserId());
CurrentUserDto currentUserDto = BeanUtils.copyBean(new CurrentUserDto(), user);
currentUserDto.setRoles(currentRoleDtos);
currentUserDto.setPermissions(permissions);
return currentUserDto;
}
}
package io.dataease.base.mapper.ext; package io.dataease.base.mapper.ext;
import io.dataease.base.domain.PanelShare; import io.dataease.base.domain.PanelShare;
import io.dataease.base.mapper.ext.query.GridExample;
import io.dataease.controller.request.panel.PanelShareRemoveRequest; import io.dataease.controller.request.panel.PanelShareRemoveRequest;
import io.dataease.controller.request.panel.PanelShareSearchRequest;
import io.dataease.dto.panel.PanelShareOutDTO; import io.dataease.dto.panel.PanelShareOutDTO;
import io.dataease.dto.panel.PanelSharePo; import io.dataease.dto.panel.PanelSharePo;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
...@@ -20,9 +20,9 @@ public interface ExtPanelShareMapper { ...@@ -20,9 +20,9 @@ public interface ExtPanelShareMapper {
List<PanelSharePo> queryOut(String userName); List<PanelSharePo> queryOut(String userName);
List<PanelShare> queryWithResource(GridExample example); List<PanelShare> queryWithResource(PanelShareSearchRequest request);
List<PanelShareOutDTO> queryTargets(String panelId); List<PanelShareOutDTO> queryTargets(@Param("panelId") String panelId, @Param("userName") String userName);
void removeShares(@Param("request") PanelShareRemoveRequest request); void removeShares(@Param("request") PanelShareRemoveRequest request);
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
<id column="id" property="id" /> <id column="id" property="id" />
<result column="name" property="name" /> <result column="name" property="name" />
<result column="creator" property="creator" /> <result column="creator" property="creator" />
<result column="user_id" jdbcType="BIGINT" property="userId" />
</resultMap> </resultMap>
<resultMap id="targetMap" type="io.dataease.dto.panel.PanelShareOutDTO"> <resultMap id="targetMap" type="io.dataease.dto.panel.PanelShareOutDTO">
...@@ -34,7 +35,7 @@ ...@@ -34,7 +35,7 @@
</delete> </delete>
<select id="query" resultMap="treeNodeMap"> <select id="query" resultMap="treeNodeMap">
select distinct s.panel_group_id as id, u.nick_name as creator, g.name select distinct s.panel_group_id as id, u.nick_name as creator, g.name, u.user_id
from panel_share s from panel_share s
left join panel_group g on g.id = s.panel_group_id left join panel_group g on g.id = s.panel_group_id
left join sys_user u on u.username = IFNULL(s.granter,g.create_by) left join sys_user u on u.username = IFNULL(s.granter,g.create_by)
...@@ -61,14 +62,17 @@ ...@@ -61,14 +62,17 @@
</select> </select>
<select id="queryWithResource" parameterType="io.dataease.base.mapper.ext.query.GridExample" resultMap="io.dataease.base.mapper.PanelShareMapper.BaseResultMap"> <select id="queryWithResource" parameterType="io.dataease.controller.request.panel.PanelShareSearchRequest" resultMap="io.dataease.base.mapper.PanelShareMapper.BaseResultMap">
select * from panel_share select s.*
<if test="_parameter != null"> from panel_share s
<include refid="io.dataease.base.mapper.ext.query.GridSql.gridCondition" /> left join panel_group g on g.id = s.panel_group_id
</if> where
<if test="orderByClause != null"> s.panel_group_id = #{resourceId}
order by ${orderByClause} <if test="type != null">
and s.type = #{type}
</if> </if>
and (( s.granter is not null and s.granter = #{currentUserName} ) or ( s.granter is null and g.create_by = #{currentUserName} ))
order by s.create_time desc
</select> </select>
...@@ -89,6 +93,7 @@ ...@@ -89,6 +93,7 @@
) as target_name ) as target_name
from panel_share s from panel_share s
where s.panel_group_id = #{panelId} where s.panel_group_id = #{panelId}
and s.granter = #{userName}
</select> </select>
......
...@@ -4,9 +4,12 @@ import io.dataease.auth.api.dto.CurrentRoleDto; ...@@ -4,9 +4,12 @@ import io.dataease.auth.api.dto.CurrentRoleDto;
import io.dataease.auth.api.dto.CurrentUserDto; import io.dataease.auth.api.dto.CurrentUserDto;
import io.dataease.auth.entity.AuthItem; import io.dataease.auth.entity.AuthItem;
import io.dataease.auth.service.ExtAuthService; import io.dataease.auth.service.ExtAuthService;
import io.dataease.auth.service.ProxyAuthService;
import io.dataease.commons.constants.DePermissionType; import io.dataease.commons.constants.DePermissionType;
import io.dataease.commons.constants.ResourceAuthLevel; import io.dataease.commons.constants.ResourceAuthLevel;
import io.dataease.commons.model.AuthURD; import io.dataease.commons.model.AuthURD;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.SecurityUtils; import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -19,23 +22,43 @@ import java.util.stream.Collectors; ...@@ -19,23 +22,43 @@ import java.util.stream.Collectors;
@Component @Component
public class AuthUtils { public class AuthUtils {
private static final String[] defaultPanelPermissions = {"panel_list"}; private static final String[] defaultPanelPermissions = { "panel_list" };
private static final String[] defaultDataSetPermissions = {"0"}; private static final String[] defaultDataSetPermissions = { "0" };
private static final String[] defaultLinkPermissions = {"0"}; private static final String[] defaultLinkPermissions = { "0" };
private static final ThreadLocal<CurrentUserDto> USER_INFO = new ThreadLocal<CurrentUserDto>();
private static ExtAuthService extAuthService; private static ExtAuthService extAuthService;
private static ProxyAuthService proxyAuthService;
@Autowired @Autowired
public void setExtAuthService(ExtAuthService extAuthService) { public void setExtAuthService(ExtAuthService extAuthService) {
AuthUtils.extAuthService = extAuthService; AuthUtils.extAuthService = extAuthService;
} }
@Autowired
public void setProxyAuthService(ProxyAuthService proxyAuthService) {
AuthUtils.proxyAuthService = proxyAuthService;
}
public static CurrentUserDto getUser() { public static CurrentUserDto getUser() {
if (ObjectUtils.isNotEmpty(USER_INFO.get()))
return USER_INFO.get();
CurrentUserDto userDto = (CurrentUserDto) SecurityUtils.getSubject().getPrincipal(); CurrentUserDto userDto = (CurrentUserDto) SecurityUtils.getSubject().getPrincipal();
return userDto; return userDto;
} }
//根据组织 角色 用户 获取下属用户ID public static void setProxyUser(Long userId) {
CurrentUserDto currentUserDto = proxyAuthService.queryCacheUserDto(userId);
USER_INFO.set(currentUserDto);
}
public static void cleanProxyUser() {
USER_INFO.remove();
}
// 根据组织 角色 用户 获取下属用户ID
public static Set<Long> userIdsByURD(AuthURD request) { public static Set<Long> userIdsByURD(AuthURD request) {
Set<Long> userIds = extAuthService.userIdsByRD(request); Set<Long> userIds = extAuthService.userIdsByRD(request);
if (!CollectionUtils.isEmpty(request.getUserIds())) { if (!CollectionUtils.isEmpty(request.getUserIds())) {
...@@ -49,8 +72,6 @@ public class AuthUtils { ...@@ -49,8 +72,6 @@ public class AuthUtils {
return extAuthService.resourceTarget(resourceId); return extAuthService.resourceTarget(resourceId);
} }
public static Set<AuthItem> permissionByType(String type) { public static Set<AuthItem> permissionByType(String type) {
CurrentUserDto user = getUser(); CurrentUserDto user = getUser();
Long userId = user.getUserId(); Long userId = user.getUserId();
...@@ -59,7 +80,8 @@ public class AuthUtils { ...@@ -59,7 +80,8 @@ public class AuthUtils {
Set<AuthItem> result = new HashSet<>(); Set<AuthItem> result = new HashSet<>();
if (StringUtils.equals(DePermissionType.DATASOURCE.name().toLowerCase(), type)) { if (StringUtils.equals(DePermissionType.DATASOURCE.name().toLowerCase(), type)) {
Set<AuthItem> userSet = extAuthService.dataSourceIdByUser(userId).stream().collect(Collectors.toSet()); Set<AuthItem> userSet = extAuthService.dataSourceIdByUser(userId).stream().collect(Collectors.toSet());
Set<AuthItem> roleSet = roles.stream().map(role -> extAuthService.dataSourceIdByRole(role.getId())).flatMap(Collection::stream).collect(Collectors.toSet()); Set<AuthItem> roleSet = roles.stream().map(role -> extAuthService.dataSourceIdByRole(role.getId()))
.flatMap(Collection::stream).collect(Collectors.toSet());
Set<AuthItem> deptSet = extAuthService.dataSourceIdByDept(deptId).stream().collect(Collectors.toSet()); Set<AuthItem> deptSet = extAuthService.dataSourceIdByDept(deptId).stream().collect(Collectors.toSet());
result.addAll(userSet); result.addAll(userSet);
result.addAll(roleSet); result.addAll(roleSet);
...@@ -72,7 +94,8 @@ public class AuthUtils { ...@@ -72,7 +94,8 @@ public class AuthUtils {
else if (StringUtils.equals(DePermissionType.DATASET.name().toLowerCase(), type)) { else if (StringUtils.equals(DePermissionType.DATASET.name().toLowerCase(), type)) {
Set<AuthItem> userSet = extAuthService.dataSetIdByUser(userId).stream().collect(Collectors.toSet()); Set<AuthItem> userSet = extAuthService.dataSetIdByUser(userId).stream().collect(Collectors.toSet());
Set<AuthItem> roleSet = roles.stream().map(role -> extAuthService.dataSetIdByRole(role.getId())).flatMap(Collection::stream).collect(Collectors.toSet()); Set<AuthItem> roleSet = roles.stream().map(role -> extAuthService.dataSetIdByRole(role.getId()))
.flatMap(Collection::stream).collect(Collectors.toSet());
Set<AuthItem> deptSet = extAuthService.dataSetIdByDept(deptId).stream().collect(Collectors.toSet()); Set<AuthItem> deptSet = extAuthService.dataSetIdByDept(deptId).stream().collect(Collectors.toSet());
result.addAll(userSet); result.addAll(userSet);
result.addAll(roleSet); result.addAll(roleSet);
...@@ -81,10 +104,10 @@ public class AuthUtils { ...@@ -81,10 +104,10 @@ public class AuthUtils {
result.add(new AuthItem(item, ResourceAuthLevel.DATASET_LEVEL_MANAGE.getLevel())); result.add(new AuthItem(item, ResourceAuthLevel.DATASET_LEVEL_MANAGE.getLevel()));
}); });
return result; return result;
} } else if (StringUtils.equals(DePermissionType.PANEL.name().toLowerCase(), type)) {
else if (StringUtils.equals(DePermissionType.PANEL.name().toLowerCase(), type)) {
Set<AuthItem> userSet = extAuthService.panelIdByUser(userId).stream().collect(Collectors.toSet()); Set<AuthItem> userSet = extAuthService.panelIdByUser(userId).stream().collect(Collectors.toSet());
Set<AuthItem> roleSet = roles.stream().map(role -> extAuthService.panelIdByRole(role.getId())).flatMap(Collection::stream).collect(Collectors.toSet()); Set<AuthItem> roleSet = roles.stream().map(role -> extAuthService.panelIdByRole(role.getId()))
.flatMap(Collection::stream).collect(Collectors.toSet());
Set<AuthItem> deptSet = extAuthService.panelIdByDept(deptId).stream().collect(Collectors.toSet()); Set<AuthItem> deptSet = extAuthService.panelIdByDept(deptId).stream().collect(Collectors.toSet());
result.addAll(userSet); result.addAll(userSet);
result.addAll(roleSet); result.addAll(roleSet);
......
...@@ -2,6 +2,7 @@ package io.dataease.controller.chart; ...@@ -2,6 +2,7 @@ package io.dataease.controller.chart;
import com.github.xiaoymin.knife4j.annotations.ApiSupport; import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import io.dataease.auth.annotation.DePermission; import io.dataease.auth.annotation.DePermission;
import io.dataease.auth.annotation.DePermissionProxy;
import io.dataease.base.domain.ChartViewWithBLOBs; import io.dataease.base.domain.ChartViewWithBLOBs;
import io.dataease.commons.constants.DePermissionType; import io.dataease.commons.constants.DePermissionType;
import io.dataease.commons.constants.ResourceAuthLevel; import io.dataease.commons.constants.ResourceAuthLevel;
...@@ -66,10 +67,12 @@ public class ChartViewController { ...@@ -66,10 +67,12 @@ public class ChartViewController {
chartViewService.delete(id); chartViewService.delete(id);
} }
@DePermissionProxy(value = "proxy", paramIndex = 2)
@DePermission(type = DePermissionType.PANEL, level = ResourceAuthLevel.PANNEL_LEVEL_VIEW, paramIndex = 1) @DePermission(type = DePermissionType.PANEL, level = ResourceAuthLevel.PANNEL_LEVEL_VIEW, paramIndex = 1)
@ApiOperation("数据") @ApiOperation("数据")
@PostMapping("/getData/{id}/{panelId}") @PostMapping("/getData/{id}/{panelId}")
public ChartViewDTO getData(@PathVariable String id, @PathVariable String panelId, @RequestBody ChartExtRequest requestList) throws Exception { public ChartViewDTO getData(@PathVariable String id, @PathVariable String panelId,
@RequestBody ChartExtRequest requestList) throws Exception {
return chartViewService.getData(id, requestList); return chartViewService.getData(id, requestList);
} }
...@@ -110,7 +113,8 @@ public class ChartViewController { ...@@ -110,7 +113,8 @@ public class ChartViewController {
@ApiIgnore @ApiIgnore
@ApiOperation("验证视图是否使用相同数据集") @ApiOperation("验证视图是否使用相同数据集")
@GetMapping("/checkSameDataSet/{viewIdSource}/{viewIdTarget}") @GetMapping("/checkSameDataSet/{viewIdSource}/{viewIdTarget}")
public String checkSameDataSet(@PathVariable String viewIdSource, @PathVariable String viewIdTarget) throws Exception { public String checkSameDataSet(@PathVariable String viewIdSource, @PathVariable String viewIdTarget)
throws Exception {
return chartViewService.checkSameDataSet(viewIdSource, viewIdTarget); return chartViewService.checkSameDataSet(viewIdSource, viewIdTarget);
} }
} }
...@@ -2,6 +2,7 @@ package io.dataease.controller.panel; ...@@ -2,6 +2,7 @@ package io.dataease.controller.panel;
import com.github.xiaoymin.knife4j.annotations.ApiSupport; import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import io.dataease.auth.annotation.DePermission; import io.dataease.auth.annotation.DePermission;
import io.dataease.auth.annotation.DePermissionProxy;
import io.dataease.auth.annotation.DePermissions; import io.dataease.auth.annotation.DePermissions;
import io.dataease.base.domain.PanelGroup; import io.dataease.base.domain.PanelGroup;
import io.dataease.base.domain.PanelGroupWithBLOBs; import io.dataease.base.domain.PanelGroupWithBLOBs;
...@@ -9,13 +10,15 @@ import io.dataease.commons.constants.DePermissionType; ...@@ -9,13 +10,15 @@ import io.dataease.commons.constants.DePermissionType;
import io.dataease.commons.constants.ResourceAuthLevel; import io.dataease.commons.constants.ResourceAuthLevel;
import io.dataease.controller.handler.annotation.I18n; import io.dataease.controller.handler.annotation.I18n;
import io.dataease.controller.request.panel.PanelGroupRequest; import io.dataease.controller.request.panel.PanelGroupRequest;
import io.dataease.dto.PermissionProxy;
import io.dataease.dto.authModel.VAuthModelDTO; import io.dataease.dto.authModel.VAuthModelDTO;
import io.dataease.dto.panel.PanelGroupDTO; import io.dataease.dto.panel.PanelGroupDTO;
import io.dataease.service.panel.PanelGroupService; import io.dataease.service.panel.PanelGroupService;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import springfox.documentation.annotations.ApiIgnore;
import org.apache.shiro.authz.annotation.Logical; import org.apache.shiro.authz.annotation.Logical;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource; import javax.annotation.Resource;
...@@ -72,10 +75,20 @@ public class PanelGroupController { ...@@ -72,10 +75,20 @@ public class PanelGroupController {
return panelGroupService.findOne(id); return panelGroupService.findOne(id);
} }
@ApiIgnore
@ApiOperation("详细信息(分享人代理)")
@DePermissionProxy(paramIndex = 1)
@DePermission(type = DePermissionType.PANEL, level = ResourceAuthLevel.PANNEL_LEVEL_VIEW)
@PostMapping("/proxy/findOne/{id}")
public PanelGroupWithBLOBs proxyFindOne(@PathVariable String id, @RequestBody PermissionProxy proxy)
throws Exception {
return panelGroupService.findOne(id);
}
@ApiOperation("仪表板视图信息") @ApiOperation("仪表板视图信息")
@PostMapping("/queryPanelViewTree") @PostMapping("/queryPanelViewTree")
@I18n @I18n
public List<VAuthModelDTO> queryPanelViewTree(){ public List<VAuthModelDTO> queryPanelViewTree() {
return panelGroupService.queryPanelViewTree(); return panelGroupService.queryPanelViewTree();
} }
......
package io.dataease.controller.panel; package io.dataease.controller.panel;
import com.github.xiaoymin.knife4j.annotations.ApiSupport; import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import io.dataease.auth.annotation.DePermissionProxy;
import io.dataease.base.domain.DatasetTableField; import io.dataease.base.domain.DatasetTableField;
import io.dataease.dto.PermissionProxy;
import io.dataease.dto.panel.linkJump.PanelLinkJumpBaseRequest; import io.dataease.dto.panel.linkJump.PanelLinkJumpBaseRequest;
import io.dataease.dto.panel.linkJump.PanelLinkJumpBaseResponse; import io.dataease.dto.panel.linkJump.PanelLinkJumpBaseResponse;
import io.dataease.dto.panel.linkJump.PanelLinkJumpDTO; import io.dataease.dto.panel.linkJump.PanelLinkJumpDTO;
import io.dataease.service.panel.PanelLinkJumpService; import io.dataease.service.panel.PanelLinkJumpService;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import springfox.documentation.annotations.ApiIgnore;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource; import javax.annotation.Resource;
...@@ -33,7 +38,6 @@ public class PanelLinkJumpController { ...@@ -33,7 +38,6 @@ public class PanelLinkJumpController {
return panelLinkJumpService.getViewFields(viewId); return panelLinkJumpService.getViewFields(viewId);
} }
@ApiOperation("根据仪表板ID和视图ID获取跳转信息") @ApiOperation("根据仪表板ID和视图ID获取跳转信息")
@GetMapping("/queryWithViewId/{panelId}/{viewId}") @GetMapping("/queryWithViewId/{panelId}/{viewId}")
public PanelLinkJumpDTO queryWithViewId(@PathVariable String panelId, @PathVariable String viewId) { public PanelLinkJumpDTO queryWithViewId(@PathVariable String panelId, @PathVariable String viewId) {
...@@ -46,6 +50,15 @@ public class PanelLinkJumpController { ...@@ -46,6 +50,15 @@ public class PanelLinkJumpController {
return panelLinkJumpService.queryPanelJumpInfo(panelId); return panelLinkJumpService.queryPanelJumpInfo(panelId);
} }
@ApiIgnore
@ApiOperation("根据仪表板ID获取跳转信息(分享人代理)")
@DePermissionProxy(paramIndex = 1)
@PostMapping("/proxy/queryPanelJumpInfo/{panelId}")
public PanelLinkJumpBaseResponse queryPanelJumpInfo(@PathVariable String panelId,
@RequestBody PermissionProxy proxy) {
return panelLinkJumpService.queryPanelJumpInfo(panelId);
}
@ApiOperation("更新跳转信息") @ApiOperation("更新跳转信息")
@PostMapping("/updateJumpSet") @PostMapping("/updateJumpSet")
public void updateJumpSet(@RequestBody PanelLinkJumpDTO jumpDTO) { public void updateJumpSet(@RequestBody PanelLinkJumpDTO jumpDTO) {
......
package io.dataease.controller.panel; package io.dataease.controller.panel;
import com.github.xiaoymin.knife4j.annotations.ApiSupport; import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import io.dataease.auth.annotation.DePermissionProxy;
import io.dataease.commons.model.BaseRspModel; import io.dataease.commons.model.BaseRspModel;
import io.dataease.controller.request.panel.PanelLinkageRequest; import io.dataease.controller.request.panel.PanelLinkageRequest;
import io.dataease.dto.PanelViewLinkageDTO; import io.dataease.dto.PanelViewLinkageDTO;
import io.dataease.dto.PermissionProxy;
import io.dataease.service.panel.PanelViewLinkageService; import io.dataease.service.panel.PanelViewLinkageService;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import springfox.documentation.annotations.ApiIgnore;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource; import javax.annotation.Resource;
...@@ -46,4 +51,13 @@ public class PanelViewLinkageController { ...@@ -46,4 +51,13 @@ public class PanelViewLinkageController {
return panelViewLinkageService.getPanelAllLinkageInfo(panelId); return panelViewLinkageService.getPanelAllLinkageInfo(panelId);
} }
@ApiIgnore
@ApiOperation("获取当前仪表板所有联动信息(分享人代理)")
@DePermissionProxy(paramIndex = 1)
@PostMapping("/proxy/getPanelAllLinkageInfo/{panelId}")
public Map<String, List<String>> getPanelAllLinkageInfo(@PathVariable String panelId,
@RequestBody PermissionProxy proxy) {
return panelViewLinkageService.getPanelAllLinkageInfo(panelId);
}
} }
...@@ -6,6 +6,7 @@ import io.dataease.base.domain.PanelShare; ...@@ -6,6 +6,7 @@ import io.dataease.base.domain.PanelShare;
import io.dataease.commons.constants.DePermissionType; import io.dataease.commons.constants.DePermissionType;
import io.dataease.controller.request.panel.PanelShareFineDto; import io.dataease.controller.request.panel.PanelShareFineDto;
import io.dataease.controller.request.panel.PanelShareRemoveRequest; import io.dataease.controller.request.panel.PanelShareRemoveRequest;
import io.dataease.controller.request.panel.PanelShareSearchRequest;
import io.dataease.controller.sys.base.BaseGridRequest; import io.dataease.controller.sys.base.BaseGridRequest;
import io.dataease.dto.panel.PanelShareDto; import io.dataease.dto.panel.PanelShareDto;
import io.dataease.dto.panel.PanelShareOutDTO; import io.dataease.dto.panel.PanelShareOutDTO;
...@@ -27,8 +28,6 @@ import java.util.List; ...@@ -27,8 +28,6 @@ import java.util.List;
@RequestMapping("/api/share") @RequestMapping("/api/share")
public interface ShareApi { public interface ShareApi {
@ApiOperation("查询分享给我") @ApiOperation("查询分享给我")
@PostMapping("/treeList") @PostMapping("/treeList")
List<PanelShareDto> treeList(BaseGridRequest request); List<PanelShareDto> treeList(BaseGridRequest request);
...@@ -37,25 +36,20 @@ public interface ShareApi { ...@@ -37,25 +36,20 @@ public interface ShareApi {
@PostMapping("/shareOut") @PostMapping("/shareOut")
List<PanelSharePo> shareOut(); List<PanelSharePo> shareOut();
@ApiOperation("根据资源查询分享") @ApiOperation("根据资源查询分享")
@PostMapping("/queryWithResourceId") @PostMapping("/queryWithResourceId")
List<PanelShare> queryWithResourceId(BaseGridRequest request); List<PanelShare> queryWithResourceId(PanelShareSearchRequest request);
@ApiOperation("查询分享目标") @ApiOperation("查询分享目标")
@PostMapping("/queryTargets/{panelId}") @PostMapping("/queryTargets/{panelId}")
@ApiImplicitParam(paramType = "path", value = "仪表板ID", name = "panelId", required = true, dataType = "String") @ApiImplicitParam(paramType = "path", value = "仪表板ID", name = "panelId", required = true, dataType = "String")
List<PanelShareOutDTO> queryTargets(@PathVariable("panelId") String panelId); List<PanelShareOutDTO> queryTargets(@PathVariable("panelId") String panelId);
@DePermission(type = DePermissionType.PANEL, value = "resourceId") @DePermission(type = DePermissionType.PANEL, value = "resourceId")
@ApiOperation("创建分享") @ApiOperation("创建分享")
@PostMapping("/fineSave") @PostMapping("/fineSave")
void fineSave(PanelShareFineDto panelShareFineDto); void fineSave(PanelShareFineDto panelShareFineDto);
@ApiOperation("删除分享") @ApiOperation("删除分享")
@PostMapping("/removeShares") @PostMapping("/removeShares")
void removeShares(PanelShareRemoveRequest request); void removeShares(PanelShareRemoveRequest request);
......
...@@ -4,7 +4,7 @@ import io.dataease.base.domain.PanelShare; ...@@ -4,7 +4,7 @@ import io.dataease.base.domain.PanelShare;
import io.dataease.controller.panel.api.ShareApi; import io.dataease.controller.panel.api.ShareApi;
import io.dataease.controller.request.panel.PanelShareFineDto; import io.dataease.controller.request.panel.PanelShareFineDto;
import io.dataease.controller.request.panel.PanelShareRemoveRequest; import io.dataease.controller.request.panel.PanelShareRemoveRequest;
import io.dataease.controller.request.panel.PanelShareRequest; import io.dataease.controller.request.panel.PanelShareSearchRequest;
import io.dataease.controller.sys.base.BaseGridRequest; import io.dataease.controller.sys.base.BaseGridRequest;
import io.dataease.dto.panel.PanelShareDto; import io.dataease.dto.panel.PanelShareDto;
import io.dataease.dto.panel.PanelShareOutDTO; import io.dataease.dto.panel.PanelShareOutDTO;
...@@ -23,7 +23,6 @@ public class ShareServer implements ShareApi { ...@@ -23,7 +23,6 @@ public class ShareServer implements ShareApi {
@Resource @Resource
private ShareService shareService; private ShareService shareService;
@Override @Override
public List<PanelShareDto> treeList(@RequestBody BaseGridRequest request) { public List<PanelShareDto> treeList(@RequestBody BaseGridRequest request) {
return shareService.queryTree(request); return shareService.queryTree(request);
...@@ -35,7 +34,7 @@ public class ShareServer implements ShareApi { ...@@ -35,7 +34,7 @@ public class ShareServer implements ShareApi {
} }
@Override @Override
public List<PanelShare> queryWithResourceId(@RequestBody BaseGridRequest request) { public List<PanelShare> queryWithResourceId(@RequestBody PanelShareSearchRequest request) {
return shareService.queryWithResource(request); return shareService.queryWithResource(request);
} }
...@@ -54,5 +53,3 @@ public class ShareServer implements ShareApi { ...@@ -54,5 +53,3 @@ public class ShareServer implements ShareApi {
shareService.removeShares(request); shareService.removeShares(request);
} }
} }
package io.dataease.controller.request.chart; package io.dataease.controller.request.chart;
import io.dataease.dto.PermissionProxy;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import springfox.documentation.annotations.ApiIgnore;
import java.util.List; import java.util.List;
...@@ -16,7 +18,7 @@ public class ChartExtRequest { ...@@ -16,7 +18,7 @@ public class ChartExtRequest {
@ApiModelProperty("视图额外过滤条件集合") @ApiModelProperty("视图额外过滤条件集合")
private List<ChartExtFilterRequest> filter; private List<ChartExtFilterRequest> filter;
//联动过滤条件 // 联动过滤条件
@ApiModelProperty("联动过滤条件集合") @ApiModelProperty("联动过滤条件集合")
private List<ChartExtFilterRequest> linkageFilters; private List<ChartExtFilterRequest> linkageFilters;
...@@ -37,4 +39,7 @@ public class ChartExtRequest { ...@@ -37,4 +39,7 @@ public class ChartExtRequest {
@ApiModelProperty("用户ID") @ApiModelProperty("用户ID")
private Long user = null; private Long user = null;
@ApiModelProperty(hidden = true)
private PermissionProxy proxy;
} }
package io.dataease.controller.request.panel;
import java.io.Serializable;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@Data
public class PanelShareSearchRequest implements Serializable {
@ApiModelProperty(value = "分享目标类型", allowableValues = "0:user,1:role,2:dept")
private String type;
@ApiModelProperty("仪表板ID")
private String resourceId;
@ApiModelProperty("当前用户")
private String currentUserName;
}
package io.dataease.dto;
import java.io.Serializable;
import lombok.Data;
@Data
public class PermissionProxy implements Serializable {
private Long userId;
}
...@@ -4,7 +4,6 @@ import io.swagger.annotations.ApiModelProperty; ...@@ -4,7 +4,6 @@ import io.swagger.annotations.ApiModelProperty;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
@Data @Data
@NoArgsConstructor @NoArgsConstructor
public class PanelSharePo { public class PanelSharePo {
...@@ -15,6 +14,7 @@ public class PanelSharePo { ...@@ -15,6 +14,7 @@ public class PanelSharePo {
private String name; private String name;
@ApiModelProperty("节点父ID") @ApiModelProperty("节点父ID")
private String creator; private String creator;
@ApiModelProperty("分享人ID")
private Long userId;
} }
...@@ -9,7 +9,6 @@ import io.dataease.base.domain.PanelShareExample; ...@@ -9,7 +9,6 @@ import io.dataease.base.domain.PanelShareExample;
import io.dataease.base.mapper.PanelGroupMapper; import io.dataease.base.mapper.PanelGroupMapper;
import io.dataease.base.mapper.PanelShareMapper; import io.dataease.base.mapper.PanelShareMapper;
import io.dataease.base.mapper.ext.ExtPanelShareMapper; import io.dataease.base.mapper.ext.ExtPanelShareMapper;
import io.dataease.base.mapper.ext.query.GridExample;
import io.dataease.commons.model.AuthURD; import io.dataease.commons.model.AuthURD;
import io.dataease.commons.utils.AuthUtils; import io.dataease.commons.utils.AuthUtils;
import io.dataease.commons.utils.BeanUtils; import io.dataease.commons.utils.BeanUtils;
...@@ -17,6 +16,7 @@ import io.dataease.commons.utils.CommonBeanFactory; ...@@ -17,6 +16,7 @@ import io.dataease.commons.utils.CommonBeanFactory;
import io.dataease.controller.request.panel.PanelShareFineDto; import io.dataease.controller.request.panel.PanelShareFineDto;
import io.dataease.controller.request.panel.PanelShareRemoveRequest; import io.dataease.controller.request.panel.PanelShareRemoveRequest;
import io.dataease.controller.request.panel.PanelShareRequest; import io.dataease.controller.request.panel.PanelShareRequest;
import io.dataease.controller.request.panel.PanelShareSearchRequest;
import io.dataease.controller.sys.base.BaseGridRequest; import io.dataease.controller.sys.base.BaseGridRequest;
import io.dataease.dto.panel.PanelShareDto; import io.dataease.dto.panel.PanelShareDto;
import io.dataease.dto.panel.PanelShareOutDTO; import io.dataease.dto.panel.PanelShareOutDTO;
...@@ -32,7 +32,6 @@ import javax.annotation.Resource; ...@@ -32,7 +32,6 @@ import javax.annotation.Resource;
import java.util.*; import java.util.*;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@Service @Service
public class ShareService { public class ShareService {
...@@ -53,43 +52,50 @@ public class ShareService { ...@@ -53,43 +52,50 @@ public class ShareService {
* 5.批量新增 * 5.批量新增
* 6.发送取消分享消息 * 6.发送取消分享消息
* 7.发送新增分享消息 * 7.发送新增分享消息
*
* @param panelShareFineDto * @param panelShareFineDto
*/ */
@Transactional @Transactional
public void fineSave(PanelShareFineDto panelShareFineDto) { public void fineSave(PanelShareFineDto panelShareFineDto) {
List<PanelShare> addShares = new ArrayList<>();//新增的分享 List<PanelShare> addShares = new ArrayList<>();// 新增的分享
List<Long> redShareIdLists = new ArrayList<>();//取消的分享 List<Long> redShareIdLists = new ArrayList<>();// 取消的分享
String panelGroupId = panelShareFineDto.getResourceId(); String panelGroupId = panelShareFineDto.getResourceId();
AuthURD authURD = panelShareFineDto.getAuthURD(); AuthURD authURD = panelShareFineDto.getAuthURD();
AuthURD sharedAuthURD = new AuthURD(); AuthURD sharedAuthURD = new AuthURD();
AuthURD addAuthURD = new AuthURD(); AuthURD addAuthURD = new AuthURD();
Map<Integer, List<Long>> authURDMap = new HashMap<>(); Map<Integer, List<Long>> authURDMap = new HashMap<>();
authURDMap.put(0, authURD.getUserIds()); authURDMap.put(0, authURD.getUserIds());
authURDMap.put(1, authURD.getRoleIds()); authURDMap.put(1, authURD.getRoleIds());
authURDMap.put(2, authURD.getDeptIds()); authURDMap.put(2, authURD.getDeptIds());
PanelShareExample example = new PanelShareExample(); /*
example.createCriteria().andPanelGroupIdEqualTo(panelGroupId); * PanelShareExample example = new PanelShareExample();
List<PanelShare> panelShares = mapper.selectByExample(example); * example.createCriteria().andPanelGroupIdEqualTo(panelGroupId);
Map<Integer, List<TempShareNode>> typeSharedMap = panelShares.stream().map(this::convertNode).collect(Collectors.groupingBy(TempShareNode::getType)); * List<PanelShare> panelShares = mapper.selectByExample(example);
*/
PanelShareSearchRequest request = new PanelShareSearchRequest();
request.setCurrentUserName(AuthUtils.getUser().getUsername());
request.setResourceId(panelGroupId);
// 当前用户已经分享出去的
List<PanelShare> panelShares = extPanelShareMapper.queryWithResource(request);
Map<Integer, List<TempShareNode>> typeSharedMap = panelShares.stream().map(this::convertNode)
.collect(Collectors.groupingBy(TempShareNode::getType));
for (Map.Entry<Integer, List<Long>> entry : authURDMap.entrySet()) { for (Map.Entry<Integer, List<Long>> entry : authURDMap.entrySet()) {
Integer key = entry.getKey(); Integer key = entry.getKey();
List<TempShareNode> shareNodes; List<TempShareNode> shareNodes;
if (null == typeSharedMap || null == typeSharedMap.get(key)) { if (null == typeSharedMap || null == typeSharedMap.get(key)) {
shareNodes = new ArrayList<>(); shareNodes = new ArrayList<>();
}else{ } else {
shareNodes = typeSharedMap.get(key); shareNodes = typeSharedMap.get(key);
} }
if (null != authURDMap.get(key)) { if (null != authURDMap.get(key)) {
Map<String, Object> dataMap = filterData(authURDMap.get(key), shareNodes); Map<String, Object> dataMap = filterData(authURDMap.get(key), shareNodes);
List<Long> newIds = (List<Long>)dataMap.get("add"); List<Long> newIds = (List<Long>) dataMap.get("add");
for (int i = 0; i < newIds.size(); i++) { for (int i = 0; i < newIds.size(); i++) {
Long id = newIds.get(i); Long id = newIds.get(i);
PanelShare share = new PanelShare(); PanelShare share = new PanelShare();
...@@ -99,21 +105,24 @@ public class ShareService { ...@@ -99,21 +105,24 @@ public class ShareService {
share.setType(key); share.setType(key);
addShares.add(share); addShares.add(share);
} }
List<TempShareNode> redNodes = (List<TempShareNode>)dataMap.get("red"); List<TempShareNode> redNodes = (List<TempShareNode>) dataMap.get("red");
List<Long> redIds = redNodes.stream().map(TempShareNode::getShareId).distinct().collect(Collectors.toList()); List<Long> redIds = redNodes.stream().map(TempShareNode::getShareId).distinct()
.collect(Collectors.toList());
redShareIdLists.addAll(redIds); redShareIdLists.addAll(redIds);
buildRedAuthURD(key, redNodes.stream().map(TempShareNode::getTargetId).distinct().collect(Collectors.toList()) , sharedAuthURD); buildRedAuthURD(key,
redNodes.stream().map(TempShareNode::getTargetId).distinct().collect(Collectors.toList()),
sharedAuthURD);
buildRedAuthURD(key, newIds, addAuthURD); buildRedAuthURD(key, newIds, addAuthURD);
} }
} }
if (CollectionUtils.isNotEmpty(redShareIdLists)){ if (CollectionUtils.isNotEmpty(redShareIdLists)) {
extPanelShareMapper.batchDelete(redShareIdLists); extPanelShareMapper.batchDelete(redShareIdLists);
} }
if (CollectionUtils.isNotEmpty(addShares)){ if (CollectionUtils.isNotEmpty(addShares)) {
extPanelShareMapper.batchInsert(addShares, AuthUtils.getUser().getUsername()); extPanelShareMapper.batchInsert(addShares, AuthUtils.getUser().getUsername());
} }
...@@ -129,20 +138,21 @@ public class ShareService { ...@@ -129,20 +138,21 @@ public class ShareService {
List<String> msgParam = new ArrayList<>(); List<String> msgParam = new ArrayList<>();
msgParam.add(panelGroupId); msgParam.add(panelGroupId);
addUserIdSet.forEach(userId -> { addUserIdSet.forEach(userId -> {
if (!redUserIdSet.contains(userId) && !user.getUserId().equals(userId)){ if (!redUserIdSet.contains(userId) && !user.getUserId().equals(userId)) {
DeMsgutil.sendMsg(userId, 2L,user.getNickName()+" 分享了仪表板【"+msg+"】,请查收!", gson.toJson(msgParam)); DeMsgutil.sendMsg(userId, 2L, user.getNickName() + " 分享了仪表板【" + msg + "】,请查收!", gson.toJson(msgParam));
} }
}); });
redUserIdSet.forEach(userId -> { redUserIdSet.forEach(userId -> {
if (!addUserIdSet.contains(userId) && !user.getUserId().equals(userId)){ if (!addUserIdSet.contains(userId) && !user.getUserId().equals(userId)) {
DeMsgutil.sendMsg(userId, 3L, user.getNickName()+" 取消分享了仪表板【"+msg+"】,请查收!", gson.toJson(msgParam)); DeMsgutil.sendMsg(userId, 3L, user.getNickName() + " 取消分享了仪表板【" + msg + "】,请查收!",
gson.toJson(msgParam));
} }
}); });
} }
private void buildRedAuthURD(Integer type, List<Long> redIds , AuthURD authURD) { private void buildRedAuthURD(Integer type, List<Long> redIds, AuthURD authURD) {
if (type == 0) { if (type == 0) {
authURD.setUserIds(redIds); authURD.setUserIds(redIds);
} }
...@@ -179,8 +189,9 @@ public class ShareService { ...@@ -179,8 +189,9 @@ public class ShareService {
newUserIds.add(newTargetId); newUserIds.add(newTargetId);
} }
} }
//获取需要取消分享的 // 获取需要取消分享的
List<TempShareNode> missNodes = shareNodes.stream().filter(item -> !item.getMatched()).collect(Collectors.toList()); List<TempShareNode> missNodes = shareNodes.stream().filter(item -> !item.getMatched())
.collect(Collectors.toList());
result.put("add", newUserIds); result.put("add", newUserIds);
result.put("red", missNodes); result.put("red", missNodes);
return result; return result;
...@@ -202,33 +213,31 @@ public class ShareService { ...@@ -202,33 +213,31 @@ public class ShareService {
return BeanUtils.copyBean(new TempShareNode(), panelShare); return BeanUtils.copyBean(new TempShareNode(), panelShare);
} }
@Transactional @Transactional
public void save(PanelShareRequest request){ public void save(PanelShareRequest request) {
List<PanelGroup> panelGroups = queryGroup(request.getPanelIds()); List<PanelGroup> panelGroups = queryGroup(request.getPanelIds());
//1.先根据仪表板删除所有已经分享的 // 1.先根据仪表板删除所有已经分享的
Integer type = request.getType(); Integer type = request.getType();
List<String> panelIds = request.getPanelIds(); List<String> panelIds = request.getPanelIds();
List<Long> targetIds = request.getTargetIds(); List<Long> targetIds = request.getTargetIds();
// 使用原生对象会导致事物失效 所以这里需要使用spring代理对象 // 使用原生对象会导致事物失效 所以这里需要使用spring代理对象
if (CollectionUtils.isNotEmpty(panelIds)){ if (CollectionUtils.isNotEmpty(panelIds)) {
ShareService proxy = CommonBeanFactory.getBean(ShareService.class); ShareService proxy = CommonBeanFactory.getBean(ShareService.class);
panelIds.forEach(panelId -> proxy.delete(panelId, type)); panelIds.forEach(panelId -> proxy.delete(panelId, type));
} }
if (CollectionUtils.isEmpty(targetIds)) return; if (CollectionUtils.isEmpty(targetIds))
return;
long now = System.currentTimeMillis(); long now = System.currentTimeMillis();
List<PanelShare> shares = panelIds.stream().flatMap(panelId -> List<PanelShare> shares = panelIds.stream().flatMap(panelId -> targetIds.stream().map(targetId -> {
targetIds.stream().map(targetId -> {
PanelShare share = new PanelShare(); PanelShare share = new PanelShare();
share.setCreateTime(now); share.setCreateTime(now);
share.setPanelGroupId(panelId); share.setPanelGroupId(panelId);
share.setTargetId(targetId); share.setTargetId(targetId);
share.setType(type); share.setType(type);
return share; return share;
}) })).collect(Collectors.toList());
).collect(Collectors.toList()); if (CollectionUtils.isNotEmpty(shares)) {
if (CollectionUtils.isNotEmpty(shares)){
extPanelShareMapper.batchInsert(shares, AuthUtils.getUser().getUsername()); extPanelShareMapper.batchInsert(shares, AuthUtils.getUser().getUsername());
} }
...@@ -241,15 +250,17 @@ public class ShareService { ...@@ -241,15 +250,17 @@ public class ShareService {
if (type == 1) { if (type == 1) {
authURD.setRoleIds(targetIds); authURD.setRoleIds(targetIds);
} }
if(type == 2) { if (type == 2) {
authURD.setDeptIds(targetIds); authURD.setDeptIds(targetIds);
} }
userIdSet = AuthUtils.userIdsByURD(authURD); userIdSet = AuthUtils.userIdsByURD(authURD);
CurrentUserDto user = AuthUtils.getUser(); CurrentUserDto user = AuthUtils.getUser();
String msg = StringUtils.joinWith(",", panelGroups.stream().map(PanelGroup::getName).collect(Collectors.toList())); String msg = StringUtils.joinWith(",",
panelGroups.stream().map(PanelGroup::getName).collect(Collectors.toList()));
Gson gson = new Gson(); Gson gson = new Gson();
userIdSet.forEach(userId -> DeMsgutil.sendMsg(userId, 2L, user.getNickName()+" 分享了仪表板【"+msg+"】给您,请查收!", gson.toJson(panelIds))); userIdSet.forEach(userId -> DeMsgutil.sendMsg(userId, 2L, user.getNickName() + " 分享了仪表板【" + msg + "】给您,请查收!",
gson.toJson(panelIds)));
} }
...@@ -259,14 +270,15 @@ public class ShareService { ...@@ -259,14 +270,15 @@ public class ShareService {
/** /**
* panel_group_id建了索引 效率不会很差 * panel_group_id建了索引 效率不会很差
*
* @param panel_group_id * @param panel_group_id
*/ */
@Transactional @Transactional
public void delete(String panel_group_id, Integer type){ public void delete(String panel_group_id, Integer type) {
PanelShareExample example = new PanelShareExample(); PanelShareExample example = new PanelShareExample();
PanelShareExample.Criteria criteria = example.createCriteria(); PanelShareExample.Criteria criteria = example.createCriteria();
criteria.andPanelGroupIdEqualTo(panel_group_id); criteria.andPanelGroupIdEqualTo(panel_group_id);
if(type != null){ if (type != null) {
criteria.andTypeEqualTo(type); criteria.andTypeEqualTo(type);
} }
mapper.deleteByExample(example); mapper.deleteByExample(example);
...@@ -281,7 +293,7 @@ public class ShareService { ...@@ -281,7 +293,7 @@ public class ShareService {
return extPanelShareMapper.queryOut(username); return extPanelShareMapper.queryOut(username);
} }
public List<PanelShareDto> queryTree(BaseGridRequest request){ public List<PanelShareDto> queryTree(BaseGridRequest request) {
CurrentUserDto user = AuthUtils.getUser(); CurrentUserDto user = AuthUtils.getUser();
Long userId = user.getUserId(); Long userId = user.getUserId();
Long deptId = user.getDeptId(); Long deptId = user.getDeptId();
...@@ -293,14 +305,18 @@ public class ShareService { ...@@ -293,14 +305,18 @@ public class ShareService {
param.put("roleIds", roleIds); param.put("roleIds", roleIds);
List<PanelSharePo> datas = extPanelShareMapper.query(param); List<PanelSharePo> datas = extPanelShareMapper.query(param);
List<PanelShareDto> dtoLists = datas.stream().map(po -> BeanUtils.copyBean(new PanelShareDto(), po)).collect(Collectors.toList()); List<PanelShareDto> dtoLists = datas.stream().map(po -> BeanUtils.copyBean(new PanelShareDto(), po))
.collect(Collectors.toList());
return convertTree(dtoLists); return convertTree(dtoLists);
} }
//List构建Tree // List构建Tree
private List<PanelShareDto> convertTree(List<PanelShareDto> datas){ private List<PanelShareDto> convertTree(List<PanelShareDto> datas) {
String username = AuthUtils.getUser().getUsername(); String username = AuthUtils.getUser().getUsername();
Map<String, List<PanelShareDto>> map = datas.stream().filter(panelShareDto -> StringUtils.isNotEmpty(panelShareDto.getCreator()) && !StringUtils.equals(username, panelShareDto.getCreator())).collect(Collectors.groupingBy(PanelShareDto::getCreator)); Map<String, List<PanelShareDto>> map = datas.stream()
.filter(panelShareDto -> StringUtils.isNotEmpty(panelShareDto.getCreator())
&& !StringUtils.equals(username, panelShareDto.getCreator()))
.collect(Collectors.groupingBy(PanelShareDto::getCreator));
return map.entrySet().stream().map(entry -> { return map.entrySet().stream().map(entry -> {
PanelShareDto panelShareDto = new PanelShareDto(); PanelShareDto panelShareDto = new PanelShareDto();
panelShareDto.setName(entry.getKey()); panelShareDto.setName(entry.getKey());
...@@ -309,15 +325,19 @@ public class ShareService { ...@@ -309,15 +325,19 @@ public class ShareService {
}).collect(Collectors.toList()); }).collect(Collectors.toList());
} }
public List<PanelShare> queryWithResource(BaseGridRequest request){ public List<PanelShare> queryWithResource(PanelShareSearchRequest request) {
GridExample example = request.convertExample(); String username = AuthUtils.getUser().getUsername();
return extPanelShareMapper.queryWithResource(example); request.setCurrentUserName(username);
return extPanelShareMapper.queryWithResource(request);
} }
public List<PanelShareOutDTO> queryTargets(String panelId) { public List<PanelShareOutDTO> queryTargets(String panelId) {
List<PanelShareOutDTO> targets = extPanelShareMapper.queryTargets(panelId); String username = AuthUtils.getUser().getUsername();
if (CollectionUtils.isEmpty(targets)) return new ArrayList<>(); List<PanelShareOutDTO> targets = extPanelShareMapper.queryTargets(panelId, username);
return targets.stream().filter(item -> StringUtils.isNotEmpty(item.getTargetName())).collect(Collectors.toList()); if (CollectionUtils.isEmpty(targets))
return new ArrayList<>();
return targets.stream().filter(item -> StringUtils.isNotEmpty(item.getTargetName()))
.collect(Collectors.toList());
} }
public void removeShares(PanelShareRemoveRequest removeRequest) { public void removeShares(PanelShareRemoveRequest removeRequest) {
......
import request from '@/utils/request'
import { panelInit } from '@/components/canvas/utils/utils'
import store from '@/store'
export function proxyInitPanelData(panelId, proxy, callback) {
// 加载视图数据
findOne(panelId, proxy).then(response => {
// 初始化视图data和style 数据
panelInit(JSON.parse(response.data.panelData), JSON.parse(response.data.panelStyle))
// 设置当前仪表板全局信息
store.dispatch('panel/setPanelInfo', {
id: response.data.id,
name: response.data.name,
privileges: response.data.privileges,
proxy: proxy.userId
})
// 刷新联动信息
getPanelAllLinkageInfo(panelId, proxy).then(rsp => {
store.commit('setNowPanelTrackInfo', rsp.data)
})
// 刷新跳转信息
queryPanelJumpInfo(panelId, proxy).then(rsp => {
store.commit('setNowPanelJumpInfo', rsp.data)
})
callback(response)
})
}
export function findOne(id, data) {
return request({
url: '/panel/group/proxy/findOne/' + id,
method: 'post',
loading: true,
data
})
}
export function getPanelAllLinkageInfo(panelId, data) {
return request({
url: '/linkage/proxy/getPanelAllLinkageInfo/' + panelId,
method: 'post',
data
})
}
export function queryPanelJumpInfo(panelId, data) {
return request({
url: '/linkJump/proxy/queryPanelJumpInfo/' + panelId,
method: 'post',
data
})
}
...@@ -433,6 +433,10 @@ export default { ...@@ -433,6 +433,10 @@ export default {
...this.filter, ...this.filter,
cache: cache cache: cache
} }
if (this.panelInfo.proxy) {
// method = viewInfo
requestInfo.proxy = { userId: this.panelInfo.proxy }
}
method(id, this.panelInfo.id, requestInfo).then(response => { method(id, this.panelInfo.id, requestInfo).then(response => {
// 将视图传入echart组件 // 将视图传入echart组件
if (response.success) { if (response.success) {
......
...@@ -73,6 +73,9 @@ export default { ...@@ -73,6 +73,9 @@ export default {
}, },
manualModify() { manualModify() {
return !!this.element.options.manualModify return !!this.element.options.manualModify
},
panelInfo() {
return this.$store.state.panel.panelInfo
} }
}, },
...@@ -96,9 +99,13 @@ export default { ...@@ -96,9 +99,13 @@ export default {
if (!token && linkToken) { if (!token && linkToken) {
method = linkMultFieldValues method = linkMultFieldValues
} }
const param = { fieldIds: this.element.options.attrs.fieldId.split(',') }
if (this.panelInfo.proxy) {
param.userId = this.panelInfo.proxy
}
this.element.options.attrs.fieldId && this.element.options.attrs.fieldId &&
this.element.options.attrs.fieldId.length > 0 && this.element.options.attrs.fieldId.length > 0 &&
method({ fieldIds: this.element.options.attrs.fieldId.split(',') }).then(res => { method(param).then(res => {
this.datas = this.optionDatas(res.data) this.datas = this.optionDatas(res.data)
}) || (this.element.options.value = '') }) || (this.element.options.value = '')
}, },
......
...@@ -93,6 +93,9 @@ export default { ...@@ -93,6 +93,9 @@ export default {
}, },
manualModify() { manualModify() {
return !!this.element.options.manualModify return !!this.element.options.manualModify
},
panelInfo() {
return this.$store.state.panel.panelInfo
} }
}, },
watch: { watch: {
...@@ -119,9 +122,13 @@ export default { ...@@ -119,9 +122,13 @@ export default {
if (!token && linkToken) { if (!token && linkToken) {
method = linkMultFieldValues method = linkMultFieldValues
} }
const param = { fieldIds: this.element.options.attrs.fieldId.split(',') }
if (this.panelInfo.proxy) {
param.userId = this.panelInfo.proxy
}
this.element.options.attrs.fieldId && this.element.options.attrs.fieldId &&
this.element.options.attrs.fieldId.length > 0 && this.element.options.attrs.fieldId.length > 0 &&
method({ fieldIds: this.element.options.attrs.fieldId.split(',') }).then(res => { method(param).then(res => {
this.datas = this.optionDatas(res.data) this.datas = this.optionDatas(res.data)
}) || (this.element.options.value = '') }) || (this.element.options.value = '')
}, },
......
...@@ -5,7 +5,8 @@ const getDefaultState = () => { ...@@ -5,7 +5,8 @@ const getDefaultState = () => {
panelInfo: { panelInfo: {
id: null, id: null,
name: '', name: '',
preStyle: null preStyle: null,
proxy: null
}, },
canvasStyleDataTemp: null, // 页面全局临时存储数据 canvasStyleDataTemp: null, // 页面全局临时存储数据
componentDataTemp: null, // 画布组件临时存储数据 componentDataTemp: null, // 画布组件临时存储数据
......
...@@ -208,9 +208,7 @@ export default { ...@@ -208,9 +208,7 @@ export default {
}, },
queryShareNodeIds(callBack) { queryShareNodeIds(callBack) {
const conditionResourceId = { field: 'panel_group_id', operator: 'eq', value: this.resourceId } const param = { resourceId: this.resourceId, type: this.type }
const conditionType = { field: 'type', operator: 'eq', value: this.type }
const param = { conditions: [conditionResourceId, conditionType] }
loadShares(param).then(res => { loadShares(param).then(res => {
const shares = res.data const shares = res.data
const nodeIds = shares.map(share => share.targetId) const nodeIds = shares.map(share => share.targetId)
......
...@@ -93,9 +93,7 @@ export default { ...@@ -93,9 +93,7 @@ export default {
}, },
queryShareNodeIds(callBack) { queryShareNodeIds(callBack) {
const conditionResourceId = { field: 'panel_group_id', operator: 'eq', value: this.resourceId } const param = { resourceId: this.resourceId, type: this.type }
const conditionType = { field: 'type', operator: 'eq', value: this.type }
const param = { conditions: [conditionResourceId, conditionType] }
loadShares(param).then(res => { loadShares(param).then(res => {
const shares = res.data const shares = res.data
const nodeIds = shares.map(share => share.targetId) const nodeIds = shares.map(share => share.targetId)
......
...@@ -50,7 +50,8 @@ ...@@ -50,7 +50,8 @@
<script> <script>
import { loadTree, loadShareOutTree, removeShares } from '@/api/panel/share' import { loadTree, loadShareOutTree, removeShares } from '@/api/panel/share'
import { uuid } from 'vue-uuid' import { uuid } from 'vue-uuid'
import { get, initPanelData } from '@/api/panel/panel' import { initPanelData } from '@/api/panel/panel'
import { proxyInitPanelData } from '@/api/panel/shareProxy'
import bus from '@/utils/bus' import bus from '@/utils/bus'
export default { export default {
name: 'ShareTree', name: 'ShareTree',
...@@ -103,7 +104,11 @@ export default { ...@@ -103,7 +104,11 @@ export default {
return loadShareOutTree() return loadShareOutTree()
}, },
handleNodeClick(data) { handleNodeClick(data) {
initPanelData(data.id, function() { if (!data || !data.userId || !data.id) {
return
}
const param = { userId: data.userId }
proxyInitPanelData(data.id, param, function() {
bus.$emit('set-panel-show-type', 1) bus.$emit('set-panel-show-type', 1)
}) })
this.$refs['botTree'].setCurrentKey(null) this.$refs['botTree'].setCurrentKey(null)
......
...@@ -100,9 +100,7 @@ export default { ...@@ -100,9 +100,7 @@ export default {
}, },
queryShareNodeIds(callBack) { queryShareNodeIds(callBack) {
const conditionResourceId = { field: 'panel_group_id', operator: 'eq', value: this.resourceId } const param = { resourceId: this.resourceId, type: this.type }
const conditionType = { field: 'type', operator: 'eq', value: this.type }
const param = { conditions: [conditionResourceId, conditionType] }
loadShares(param).then(res => { loadShares(param).then(res => {
const shares = res.data const shares = res.data
const nodeIds = shares.map(share => share.targetId) const nodeIds = shares.map(share => share.targetId)
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论