Skip to content

Commit

Permalink
refactor: 适配 ContiNew Starter 数据权限解决方案(数据访问模块-MyBatis Plus)
Browse files Browse the repository at this point in the history
1.移除数据权限相关内容,适配 ContiNew Starter 数据权限解决方案
2.适配 ContiNew Starter 部分包结构变动
  • Loading branch information
Charles7c committed Dec 21, 2023
1 parent 4a50e72 commit 0849426
Show file tree
Hide file tree
Showing 41 changed files with 118 additions and 356 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* Copyright (c) 2022-present Charles7c Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http:https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package top.charles7c.continew.admin.common.config.mybatis;

import java.util.stream.Collectors;

import cn.hutool.core.convert.Convert;

import top.charles7c.continew.admin.common.model.dto.LoginUser;
import top.charles7c.continew.admin.common.util.helper.LoginHelper;
import top.charles7c.continew.starter.data.mybatis.plus.datapermission.DataPermissionCurrentUser;
import top.charles7c.continew.starter.data.mybatis.plus.datapermission.DataPermissionFilter;
import top.charles7c.continew.starter.data.mybatis.plus.datapermission.DataScope;

/**
* 数据权限过滤器实现类
*
* @author Charles7c
* @since 2023/12/21 21:19
*/
public class DataPermissionFilterImpl implements DataPermissionFilter {

@Override
public boolean isFilter() {
LoginUser loginUser = LoginHelper.getLoginUser();
return null != loginUser && !loginUser.isAdmin();
}

@Override
public DataPermissionCurrentUser getCurrentUser() {
LoginUser loginUser = LoginHelper.getLoginUser();
if (null == loginUser) {
throw new IllegalArgumentException("Current user is not allowed to be empty.");
}
DataPermissionCurrentUser currentUser = new DataPermissionCurrentUser();
currentUser.setUserId(Convert.toStr(loginUser.getId()));
currentUser.setDeptId(Convert.toStr(loginUser.getDeptId()));
currentUser.setRoles(loginUser.getRoles().stream()
.map(r -> new DataPermissionCurrentUser.CurrentUserRole(Convert.toStr(r.getId()),
DataScope.valueOf(r.getDataScope().name())))
.collect(Collectors.toSet()));
return currentUser;
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package top.charles7c.continew.admin.common.base;
package top.charles7c.continew.admin.common.config.mybatis;

import java.util.List;

Expand All @@ -24,8 +24,8 @@
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Constants;

import top.charles7c.continew.admin.common.annotation.DataPermission;
import top.charles7c.continew.starter.extension.crud.base.BaseMapper;
import top.charles7c.continew.starter.data.mybatis.plus.base.BaseMapper;
import top.charles7c.continew.starter.data.mybatis.plus.datapermission.DataPermission;

/**
* 数据权限 Mapper 基类
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;

import top.charles7c.continew.starter.data.mybatis.plus.datapermission.DataPermissionFilter;

/**
* MyBatis Plus 配置
*
Expand All @@ -37,4 +39,12 @@ public class MybatisPlusConfiguration {
public MetaObjectHandler metaObjectHandler() {
return new MyBatisPlusMetaObjectHandler();
}

/**
* 数据权限过滤器
*/
@Bean
public DataPermissionFilter dataPermissionFilter() {
return new DataPermissionFilterImpl();
}
}
Loading

0 comments on commit 0849426

Please sign in to comment.