|
@@ -53,6 +53,8 @@ public class CheckPermitAspect {
|
|
|
private IUserService userService;
|
|
|
@Autowired
|
|
|
private ICameraDetailService cameraDetailService;
|
|
|
+ @Autowired
|
|
|
+ private ISysRoleService sysRoleService;
|
|
|
|
|
|
|
|
|
@Pointcut("@annotation(com.fdkankan.scene.annotation.CheckPermit)")
|
|
@@ -90,7 +92,12 @@ public class CheckPermitAspect {
|
|
|
throw new BusinessException(ErrorCode.FAILURE_CODE_5033);
|
|
|
}
|
|
|
|
|
|
- //如果上面场景用户与当前用户不匹配,需要校验当前用户是否拥有某些角色,从而可以访问此场景
|
|
|
+ //判断场景的userid是否与当前登录用户id相等,如果相等,则有编辑权限
|
|
|
+ if(Objects.nonNull(scenePlus.getUserId()) && scenePlus.getUserId().equals(user.getId())){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ //如果上面场景用户与当前用户不匹配,需要校验当前用户是否拥有管理员角色,管理员角色可以访问任何场景
|
|
|
List<UserRole> list = userRoleService.list(new LambdaQueryWrapper<UserRole>().eq(UserRole::getUserId, user.getId()));
|
|
|
Set<Long> roleIdSet = null;
|
|
|
if(CollUtil.isNotEmpty(list)){
|
|
@@ -99,30 +106,16 @@ public class CheckPermitAspect {
|
|
|
if(CollUtil.isEmpty(roleIdSet)){
|
|
|
throw new BusinessException(ErrorCode.FAILURE_CODE_5014);
|
|
|
}
|
|
|
- //平台管理员拥有最高权限
|
|
|
- if(roleIdSet.contains(5L)){
|
|
|
- return;
|
|
|
- }
|
|
|
|
|
|
- //判断是否有公司管理者权限,有则放开
|
|
|
- if(roleIdSet.contains(6L)){
|
|
|
- //当前登录用户user
|
|
|
- User currentUser = userService.getById(user.getId());
|
|
|
- CameraDetail cameraDetail = cameraDetailService.findByCameraId(scenePlus.getCameraId());
|
|
|
- if(Objects.isNull(currentUser) || Objects.isNull(currentUser.getCompanyId())
|
|
|
- || Objects.isNull(cameraDetail) || Objects.isNull(cameraDetail.getCompanyId())
|
|
|
- || !currentUser.getCompanyId().equals(cameraDetail.getCompanyId())){
|
|
|
- throw new BusinessException(ErrorCode.FAILURE_CODE_5014);
|
|
|
- }else{
|
|
|
- return;
|
|
|
- }
|
|
|
+ List<SysRole> validRoleList = sysRoleService.getValidRoleByRoleIds(roleIdSet);
|
|
|
+ if(CollUtil.isEmpty(validRoleList)){
|
|
|
+ throw new BusinessException(ErrorCode.FAILURE_CODE_5014);
|
|
|
}
|
|
|
|
|
|
- //校验场景用户是否与当前登录用户相同,相同则跳出
|
|
|
- if(Objects.isNull(scenePlus.getUserId()) || !scenePlus.getUserId().equals(user.getId())){
|
|
|
+ boolean isAdmin = validRoleList.stream().anyMatch(sysRole -> sysRole.getRoleType().contains("admin"));
|
|
|
+ if(!isAdmin){
|
|
|
throw new BusinessException(ErrorCode.FAILURE_CODE_5014);
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
|
|
|
}
|