Search in sources :

Example 1 with SysRole

use of com.ruoyi.system.api.domain.SysRole in project RuoYi-Cloud by yangzongzhuan.

the class DataScopeAspect method dataScopeFilter.

/**
 * 数据范围过滤
 *
 * @param joinPoint 切点
 * @param user 用户
 * @param deptAlias 部门别名
 * @param userAlias 用户别名
 */
public static void dataScopeFilter(JoinPoint joinPoint, SysUser user, String deptAlias, String userAlias) {
    StringBuilder sqlString = new StringBuilder();
    for (SysRole role : user.getRoles()) {
        String dataScope = role.getDataScope();
        if (DATA_SCOPE_ALL.equals(dataScope)) {
            sqlString = new StringBuilder();
            break;
        } else if (DATA_SCOPE_CUSTOM.equals(dataScope)) {
            sqlString.append(StringUtils.format(" OR {}.dept_id IN ( SELECT dept_id FROM sys_role_dept WHERE role_id = {} ) ", deptAlias, role.getRoleId()));
        } else if (DATA_SCOPE_DEPT.equals(dataScope)) {
            sqlString.append(StringUtils.format(" OR {}.dept_id = {} ", deptAlias, user.getDeptId()));
        } else if (DATA_SCOPE_DEPT_AND_CHILD.equals(dataScope)) {
            sqlString.append(StringUtils.format(" OR {}.dept_id IN ( SELECT dept_id FROM sys_dept WHERE dept_id = {} or find_in_set( {} , ancestors ) )", deptAlias, user.getDeptId(), user.getDeptId()));
        } else if (DATA_SCOPE_SELF.equals(dataScope)) {
            if (StringUtils.isNotBlank(userAlias)) {
                sqlString.append(StringUtils.format(" OR {}.user_id = {} ", userAlias, user.getUserId()));
            } else {
                // 数据权限为仅本人且没有userAlias别名不查询任何数据
                sqlString.append(" OR 1=0 ");
            }
        }
    }
    if (StringUtils.isNotBlank(sqlString.toString())) {
        Object params = joinPoint.getArgs()[0];
        if (StringUtils.isNotNull(params) && params instanceof BaseEntity) {
            BaseEntity baseEntity = (BaseEntity) params;
            baseEntity.getParams().put(DATA_SCOPE, " AND (" + sqlString.substring(4) + ")");
        }
    }
}
Also used : SysRole(com.ruoyi.system.api.domain.SysRole) BaseEntity(com.ruoyi.common.core.web.domain.BaseEntity)

Example 2 with SysRole

use of com.ruoyi.system.api.domain.SysRole in project RuoYi-Cloud by yangzongzhuan.

the class SysRoleServiceImpl method checkRoleKeyUnique.

/**
 * 校验角色权限是否唯一
 *
 * @param role 角色信息
 * @return 结果
 */
@Override
public String checkRoleKeyUnique(SysRole role) {
    Long roleId = StringUtils.isNull(role.getRoleId()) ? -1L : role.getRoleId();
    SysRole info = roleMapper.checkRoleKeyUnique(role.getRoleKey());
    if (StringUtils.isNotNull(info) && info.getRoleId().longValue() != roleId.longValue()) {
        return UserConstants.NOT_UNIQUE;
    }
    return UserConstants.UNIQUE;
}
Also used : SysRole(com.ruoyi.system.api.domain.SysRole)

Example 3 with SysRole

use of com.ruoyi.system.api.domain.SysRole in project RuoYi-Cloud by yangzongzhuan.

the class SysUserController method getInfo.

/**
 * 根据用户编号获取详细信息
 */
@RequiresPermissions("system:user:query")
@GetMapping(value = { "/", "/{userId}" })
public AjaxResult getInfo(@PathVariable(value = "userId", required = false) Long userId) {
    userService.checkUserDataScope(userId);
    AjaxResult ajax = AjaxResult.success();
    List<SysRole> roles = roleService.selectRoleAll();
    ajax.put("roles", SysUser.isAdmin(userId) ? roles : roles.stream().filter(r -> !r.isAdmin()).collect(Collectors.toList()));
    ajax.put("posts", postService.selectPostAll());
    if (StringUtils.isNotNull(userId)) {
        SysUser sysUser = userService.selectUserById(userId);
        ajax.put(AjaxResult.DATA_TAG, sysUser);
        ajax.put("postIds", postService.selectPostListByUserId(userId));
        ajax.put("roleIds", sysUser.getRoles().stream().map(SysRole::getRoleId).collect(Collectors.toList()));
    }
    return ajax;
}
Also used : R(com.ruoyi.common.core.domain.R) PathVariable(org.springframework.web.bind.annotation.PathVariable) Log(com.ruoyi.common.log.annotation.Log) SysRole(com.ruoyi.system.api.domain.SysRole) Autowired(org.springframework.beans.factory.annotation.Autowired) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ArrayUtils(org.apache.commons.lang3.ArrayUtils) InnerAuth(com.ruoyi.common.security.annotation.InnerAuth) TableDataInfo(com.ruoyi.common.core.web.page.TableDataInfo) RequiresPermissions(com.ruoyi.common.security.annotation.RequiresPermissions) RequestBody(org.springframework.web.bind.annotation.RequestBody) ISysConfigService(com.ruoyi.system.service.ISysConfigService) BaseController(com.ruoyi.common.core.web.controller.BaseController) PutMapping(org.springframework.web.bind.annotation.PutMapping) ISysRoleService(com.ruoyi.system.service.ISysRoleService) GetMapping(org.springframework.web.bind.annotation.GetMapping) DeleteMapping(org.springframework.web.bind.annotation.DeleteMapping) BusinessType(com.ruoyi.common.log.enums.BusinessType) LoginUser(com.ruoyi.system.api.model.LoginUser) ISysPermissionService(com.ruoyi.system.service.ISysPermissionService) PostMapping(org.springframework.web.bind.annotation.PostMapping) Validated(org.springframework.validation.annotation.Validated) HttpServletResponse(javax.servlet.http.HttpServletResponse) Set(java.util.Set) IOException(java.io.IOException) AjaxResult(com.ruoyi.common.core.web.domain.AjaxResult) StringUtils(com.ruoyi.common.core.utils.StringUtils) SysUser(com.ruoyi.system.api.domain.SysUser) Collectors(java.util.stream.Collectors) RestController(org.springframework.web.bind.annotation.RestController) List(java.util.List) ISysUserService(com.ruoyi.system.service.ISysUserService) MultipartFile(org.springframework.web.multipart.MultipartFile) UserConstants(com.ruoyi.common.core.constant.UserConstants) ExcelUtil(com.ruoyi.common.core.utils.poi.ExcelUtil) ISysPostService(com.ruoyi.system.service.ISysPostService) SecurityUtils(com.ruoyi.common.security.utils.SecurityUtils) AjaxResult(com.ruoyi.common.core.web.domain.AjaxResult) SysUser(com.ruoyi.system.api.domain.SysUser) SysRole(com.ruoyi.system.api.domain.SysRole) RequiresPermissions(com.ruoyi.common.security.annotation.RequiresPermissions) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 4 with SysRole

use of com.ruoyi.system.api.domain.SysRole in project RuoYi-Cloud-Oracle by yangzongzhuan.

the class DataScopeAspect method dataScopeFilter.

/**
 * 数据范围过滤
 *
 * @param joinPoint 切点
 * @param user 用户
 * @param deptAlias 部门别名
 * @param userAlias 用户别名
 */
public static void dataScopeFilter(JoinPoint joinPoint, SysUser user, String deptAlias, String userAlias) {
    StringBuilder sqlString = new StringBuilder();
    for (SysRole role : user.getRoles()) {
        String dataScope = role.getDataScope();
        if (DATA_SCOPE_ALL.equals(dataScope)) {
            sqlString = new StringBuilder();
            break;
        } else if (DATA_SCOPE_CUSTOM.equals(dataScope)) {
            sqlString.append(StringUtils.format(" OR {}.dept_id IN ( SELECT dept_id FROM sys_role_dept WHERE role_id = {} ) ", deptAlias, role.getRoleId()));
        } else if (DATA_SCOPE_DEPT.equals(dataScope)) {
            sqlString.append(StringUtils.format(" OR {}.dept_id = {} ", deptAlias, user.getDeptId()));
        } else if (DATA_SCOPE_DEPT_AND_CHILD.equals(dataScope)) {
            sqlString.append(StringUtils.format(" OR {}.dept_id IN ( SELECT dept_id FROM sys_dept WHERE dept_id = {} or find_in_set( {} , ancestors ) )", deptAlias, user.getDeptId(), user.getDeptId()));
        } else if (DATA_SCOPE_SELF.equals(dataScope)) {
            if (StringUtils.isNotBlank(userAlias)) {
                sqlString.append(StringUtils.format(" OR {}.user_id = {} ", userAlias, user.getUserId()));
            } else {
                // 数据权限为仅本人且没有userAlias别名不查询任何数据
                sqlString.append(" OR 1=0 ");
            }
        }
    }
    if (StringUtils.isNotBlank(sqlString.toString())) {
        Object params = joinPoint.getArgs()[0];
        if (StringUtils.isNotNull(params) && params instanceof BaseEntity) {
            BaseEntity baseEntity = (BaseEntity) params;
            baseEntity.getParams().put(DATA_SCOPE, " AND (" + sqlString.substring(4) + ")");
        }
    }
}
Also used : SysRole(com.ruoyi.system.api.domain.SysRole) BaseEntity(com.ruoyi.common.core.web.domain.BaseEntity)

Example 5 with SysRole

use of com.ruoyi.system.api.domain.SysRole in project RuoYi-Cloud-Oracle by yangzongzhuan.

the class SysRoleServiceImpl method selectRolePermissionByUserId.

/**
 * 根据用户ID查询权限
 *
 * @param userId 用户ID
 * @return 权限列表
 */
@Override
public Set<String> selectRolePermissionByUserId(Long userId) {
    List<SysRole> perms = roleMapper.selectRolePermissionByUserId(userId);
    Set<String> permsSet = new HashSet<>();
    for (SysRole perm : perms) {
        if (StringUtils.isNotNull(perm)) {
            permsSet.addAll(Arrays.asList(perm.getRoleKey().trim().split(",")));
        }
    }
    return permsSet;
}
Also used : SysRole(com.ruoyi.system.api.domain.SysRole) HashSet(java.util.HashSet)

Aggregations

SysRole (com.ruoyi.system.api.domain.SysRole)24 UserConstants (com.ruoyi.common.core.constant.UserConstants)6 R (com.ruoyi.common.core.domain.R)6 ServiceException (com.ruoyi.common.core.exception.ServiceException)6 StringUtils (com.ruoyi.common.core.utils.StringUtils)6 BaseController (com.ruoyi.common.core.web.controller.BaseController)6 Log (com.ruoyi.common.log.annotation.Log)6 BusinessType (com.ruoyi.common.log.enums.BusinessType)6 SysUser (com.ruoyi.system.api.domain.SysUser)6 ISysPermissionService (com.ruoyi.system.service.ISysPermissionService)6 ISysPostService (com.ruoyi.system.service.ISysPostService)6 ISysRoleService (com.ruoyi.system.service.ISysRoleService)6 ISysUserService (com.ruoyi.system.service.ISysUserService)6 IOException (java.io.IOException)6 Collectors (java.util.stream.Collectors)6 HttpServletResponse (javax.servlet.http.HttpServletResponse)6 ArrayUtils (org.apache.commons.lang3.ArrayUtils)6 Validated (org.springframework.validation.annotation.Validated)6 MultipartFile (org.springframework.web.multipart.MultipartFile)6 ExcelUtil (com.ruoyi.common.core.utils.poi.ExcelUtil)4