Search in sources :

Example 1 with SysRole

use of com.ruoyi.project.system.domain.SysRole in project RuoYi-Vue-Oracle 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.project.system.domain.SysRole)

Example 2 with SysRole

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

the class SysRoleServiceImpl method selectRolesByUserId.

/**
 * 根据用户ID查询角色
 *
 * @param userId 用户ID
 * @return 角色列表
 */
@Override
public List<SysRole> selectRolesByUserId(Long userId) {
    List<SysRole> userRoles = roleMapper.selectRolePermissionByUserId(userId);
    List<SysRole> roles = selectRoleAll();
    for (SysRole role : roles) {
        for (SysRole userRole : userRoles) {
            if (role.getRoleId().longValue() == userRole.getRoleId().longValue()) {
                role.setFlag(true);
                break;
            }
        }
    }
    return roles;
}
Also used : SysRole(com.ruoyi.project.system.domain.SysRole)

Example 3 with SysRole

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

the class SysUserController method getInfo.

/**
 * 根据用户编号获取详细信息
 */
@PreAuthorize("@ss.hasPermi('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 : SysUser(com.ruoyi.project.system.domain.SysUser) PathVariable(org.springframework.web.bind.annotation.PathVariable) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) Autowired(org.springframework.beans.factory.annotation.Autowired) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ArrayUtils(org.apache.commons.lang3.ArrayUtils) TableDataInfo(com.ruoyi.framework.web.page.TableDataInfo) ISysRoleService(com.ruoyi.project.system.service.ISysRoleService) Log(com.ruoyi.framework.aspectj.lang.annotation.Log) ISysPostService(com.ruoyi.project.system.service.ISysPostService) RequestBody(org.springframework.web.bind.annotation.RequestBody) AjaxResult(com.ruoyi.framework.web.domain.AjaxResult) StringUtils(com.ruoyi.common.utils.StringUtils) PutMapping(org.springframework.web.bind.annotation.PutMapping) SecurityUtils(com.ruoyi.common.utils.SecurityUtils) GetMapping(org.springframework.web.bind.annotation.GetMapping) SysRole(com.ruoyi.project.system.domain.SysRole) DeleteMapping(org.springframework.web.bind.annotation.DeleteMapping) ISysUserService(com.ruoyi.project.system.service.ISysUserService) PostMapping(org.springframework.web.bind.annotation.PostMapping) Validated(org.springframework.validation.annotation.Validated) HttpServletResponse(javax.servlet.http.HttpServletResponse) Collectors(java.util.stream.Collectors) RestController(org.springframework.web.bind.annotation.RestController) BaseController(com.ruoyi.framework.web.controller.BaseController) List(java.util.List) UserConstants(com.ruoyi.common.constant.UserConstants) ExcelUtil(com.ruoyi.common.utils.poi.ExcelUtil) MultipartFile(org.springframework.web.multipart.MultipartFile) BusinessType(com.ruoyi.framework.aspectj.lang.enums.BusinessType) AjaxResult(com.ruoyi.framework.web.domain.AjaxResult) SysUser(com.ruoyi.project.system.domain.SysUser) SysRole(com.ruoyi.project.system.domain.SysRole) GetMapping(org.springframework.web.bind.annotation.GetMapping) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 4 with SysRole

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

the class SysUserController method authRole.

/**
 * 根据用户编号获取授权角色
 */
@PreAuthorize("@ss.hasPermi('system:user:query')")
@GetMapping("/authRole/{userId}")
public AjaxResult authRole(@PathVariable("userId") Long userId) {
    AjaxResult ajax = AjaxResult.success();
    SysUser user = userService.selectUserById(userId);
    List<SysRole> roles = roleService.selectRolesByUserId(userId);
    ajax.put("user", user);
    ajax.put("roles", SysUser.isAdmin(userId) ? roles : roles.stream().filter(r -> !r.isAdmin()).collect(Collectors.toList()));
    return ajax;
}
Also used : SysUser(com.ruoyi.project.system.domain.SysUser) PathVariable(org.springframework.web.bind.annotation.PathVariable) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) Autowired(org.springframework.beans.factory.annotation.Autowired) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ArrayUtils(org.apache.commons.lang3.ArrayUtils) TableDataInfo(com.ruoyi.framework.web.page.TableDataInfo) ISysRoleService(com.ruoyi.project.system.service.ISysRoleService) Log(com.ruoyi.framework.aspectj.lang.annotation.Log) ISysPostService(com.ruoyi.project.system.service.ISysPostService) RequestBody(org.springframework.web.bind.annotation.RequestBody) AjaxResult(com.ruoyi.framework.web.domain.AjaxResult) StringUtils(com.ruoyi.common.utils.StringUtils) PutMapping(org.springframework.web.bind.annotation.PutMapping) SecurityUtils(com.ruoyi.common.utils.SecurityUtils) GetMapping(org.springframework.web.bind.annotation.GetMapping) SysRole(com.ruoyi.project.system.domain.SysRole) DeleteMapping(org.springframework.web.bind.annotation.DeleteMapping) ISysUserService(com.ruoyi.project.system.service.ISysUserService) PostMapping(org.springframework.web.bind.annotation.PostMapping) Validated(org.springframework.validation.annotation.Validated) HttpServletResponse(javax.servlet.http.HttpServletResponse) Collectors(java.util.stream.Collectors) RestController(org.springframework.web.bind.annotation.RestController) BaseController(com.ruoyi.framework.web.controller.BaseController) List(java.util.List) UserConstants(com.ruoyi.common.constant.UserConstants) ExcelUtil(com.ruoyi.common.utils.poi.ExcelUtil) MultipartFile(org.springframework.web.multipart.MultipartFile) BusinessType(com.ruoyi.framework.aspectj.lang.enums.BusinessType) AjaxResult(com.ruoyi.framework.web.domain.AjaxResult) SysUser(com.ruoyi.project.system.domain.SysUser) SysRole(com.ruoyi.project.system.domain.SysRole) GetMapping(org.springframework.web.bind.annotation.GetMapping) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 5 with SysRole

use of com.ruoyi.project.system.domain.SysRole in project RuoYi-Vue-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 ) <> 0 )", 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.project.system.domain.SysRole) BaseEntity(com.ruoyi.framework.web.domain.BaseEntity)

Aggregations

SysRole (com.ruoyi.project.system.domain.SysRole)18 UserConstants (com.ruoyi.common.constant.UserConstants)4 ServiceException (com.ruoyi.common.exception.ServiceException)4 SecurityUtils (com.ruoyi.common.utils.SecurityUtils)4 StringUtils (com.ruoyi.common.utils.StringUtils)4 ExcelUtil (com.ruoyi.common.utils.poi.ExcelUtil)4 Log (com.ruoyi.framework.aspectj.lang.annotation.Log)4 BusinessType (com.ruoyi.framework.aspectj.lang.enums.BusinessType)4 BaseController (com.ruoyi.framework.web.controller.BaseController)4 AjaxResult (com.ruoyi.framework.web.domain.AjaxResult)4 TableDataInfo (com.ruoyi.framework.web.page.TableDataInfo)4 SysUser (com.ruoyi.project.system.domain.SysUser)4 ISysPostService (com.ruoyi.project.system.service.ISysPostService)4 ISysRoleService (com.ruoyi.project.system.service.ISysRoleService)4 ISysUserService (com.ruoyi.project.system.service.ISysUserService)4 List (java.util.List)4 Collectors (java.util.stream.Collectors)4 HttpServletResponse (javax.servlet.http.HttpServletResponse)4 ArrayUtils (org.apache.commons.lang3.ArrayUtils)4 Autowired (org.springframework.beans.factory.annotation.Autowired)4