Search in sources :

Example 1 with UserRole

use of com.vip.saturn.job.console.mybatis.entity.UserRole in project Saturn by vipshop.

the class AuthorizationController method addUserRoles.

@ApiResponses(value = { @ApiResponse(code = 200, message = "Success/Fail", response = RequestResult.class) })
@Audit
@PostMapping("/addUserRoles")
public SuccessResponseEntity addUserRoles(@AuditParam("userName") @RequestParam String userName, @AuditParam("roleKey") @RequestParam String roleKey, @AuditParam("namespace") @RequestParam String namespace, @AuditParam("needApproval") @RequestParam Boolean needApproval, HttpSession httpSession) throws SaturnJobConsoleException {
    assertIsSystemAdmin();
    String currentLoginUserName = getCurrentLoginUserName();
    Date now = new Date();
    UserRole userRole = new UserRole();
    userRole.setUserName(userName);
    userRole.setRoleKey(roleKey);
    userRole.setNamespace(namespace);
    userRole.setNeedApproval(needApproval);
    userRole.setIsDeleted(false);
    userRole.setCreatedBy(currentLoginUserName);
    userRole.setCreateTime(now);
    userRole.setLastUpdatedBy(currentLoginUserName);
    userRole.setLastUpdateTime(now);
    User user = new User();
    user.setUserName(userName);
    user.setPassword("");
    user.setRealName("");
    user.setEmployeeId("");
    user.setEmail("");
    user.setCreatedBy(currentLoginUserName);
    user.setCreateTime(now);
    user.setLastUpdatedBy(currentLoginUserName);
    user.setLastUpdateTime(now);
    user.setIsDeleted(false);
    userRole.setUser(user);
    authorizationService.addUserRole(userRole);
    return new SuccessResponseEntity();
}
Also used : User(com.vip.saturn.job.console.mybatis.entity.User) UserRole(com.vip.saturn.job.console.mybatis.entity.UserRole) SuccessResponseEntity(com.vip.saturn.job.console.controller.SuccessResponseEntity) Date(java.util.Date) Audit(com.vip.saturn.job.console.aop.annotation.Audit) PostMapping(org.springframework.web.bind.annotation.PostMapping) ApiResponses(io.swagger.annotations.ApiResponses)

Example 2 with UserRole

use of com.vip.saturn.job.console.mybatis.entity.UserRole in project Saturn by vipshop.

the class AuthorizationController method deleteUserRole.

@ApiResponses(value = { @ApiResponse(code = 200, message = "Success/Fail", response = RequestResult.class) })
@Audit
@PostMapping("/deleteUserRole")
public SuccessResponseEntity deleteUserRole(@AuditParam("userName") @RequestParam String userName, @AuditParam("roleKey") @RequestParam String roleKey, @AuditParam("namespace") @RequestParam String namespace, HttpSession httpSession) throws SaturnJobConsoleException {
    assertIsSystemAdmin();
    UserRole userRole = new UserRole();
    userRole.setUserName(userName);
    userRole.setRoleKey(roleKey);
    userRole.setNamespace(namespace);
    String currentLoginUserName = getCurrentLoginUserName();
    userRole.setLastUpdatedBy(currentLoginUserName);
    authorizationService.deleteUserRole(userRole);
    return new SuccessResponseEntity();
}
Also used : UserRole(com.vip.saturn.job.console.mybatis.entity.UserRole) SuccessResponseEntity(com.vip.saturn.job.console.controller.SuccessResponseEntity) Audit(com.vip.saturn.job.console.aop.annotation.Audit) PostMapping(org.springframework.web.bind.annotation.PostMapping) ApiResponses(io.swagger.annotations.ApiResponses)

Example 3 with UserRole

use of com.vip.saturn.job.console.mybatis.entity.UserRole in project Saturn by vipshop.

the class AuthorizationManageServiceImpl method addUserRole.

@Transactional(rollbackFor = Exception.class)
@Override
public void addUserRole(UserRole userRole) throws SaturnJobConsoleException {
    validateUser(userRole);
    // check role is existing
    String roleKey = userRole.getRoleKey();
    Role role = roleRepository.selectByKey(roleKey);
    if (role == null) {
        throw new SaturnJobConsoleException(String.format("角色key(%s)不存在", roleKey));
    }
    // insert or update userRole
    UserRole pre = userRoleRepository.selectWithNotFilterDeleted(userRole);
    if (pre == null) {
        userRoleRepository.insert(userRole);
    } else {
        userRoleRepository.update(pre, userRole);
    }
}
Also used : UserRole(com.vip.saturn.job.console.mybatis.entity.UserRole) Role(com.vip.saturn.job.console.mybatis.entity.Role) UserRole(com.vip.saturn.job.console.mybatis.entity.UserRole) SaturnJobConsoleException(com.vip.saturn.job.console.exception.SaturnJobConsoleException) Transactional(org.springframework.transaction.annotation.Transactional)

Example 4 with UserRole

use of com.vip.saturn.job.console.mybatis.entity.UserRole in project Saturn by vipshop.

the class AuthorizationManageServiceImpl method updateUserRole.

@Transactional(rollbackFor = Exception.class)
@Override
public void updateUserRole(UserRole pre, UserRole cur) throws SaturnJobConsoleException {
    userRoleRepository.delete(pre);
    UserRole userRole = userRoleRepository.selectWithNotFilterDeleted(cur);
    if (userRole == null) {
        userRoleRepository.insert(cur);
    } else {
        userRoleRepository.update(userRole, cur);
    }
}
Also used : UserRole(com.vip.saturn.job.console.mybatis.entity.UserRole) Transactional(org.springframework.transaction.annotation.Transactional)

Example 5 with UserRole

use of com.vip.saturn.job.console.mybatis.entity.UserRole in project Saturn by vipshop.

the class AuthorizationManageController method updateUserRole.

@ApiResponses(value = { @ApiResponse(code = 200, message = "Success/Fail", response = RequestResult.class) })
@Audit
@PostMapping("/updateUserRole")
public SuccessResponseEntity updateUserRole(@AuditParam("preUserName") @RequestParam String preUserName, @AuditParam("preRoleKey") @RequestParam String preRoleKey, @AuditParam("preNamespace") @RequestParam String preNamespace, @AuditParam("userName") @RequestParam String userName, @AuditParam("roleKey") @RequestParam String roleKey, @AuditParam("namespace") @RequestParam String namespace, @AuditParam("needApproval") @RequestParam Boolean needApproval) throws SaturnJobConsoleException {
    assertIsSystemAdmin();
    String currentLoginUserName = getCurrentLoginUserName();
    Date now = new Date();
    UserRole pre = new UserRole();
    pre.setUserName(preUserName);
    pre.setRoleKey(preRoleKey);
    pre.setNamespace(preNamespace);
    pre.setLastUpdateTime(now);
    pre.setLastUpdatedBy(currentLoginUserName);
    UserRole cur = new UserRole();
    cur.setUserName(userName);
    cur.setRoleKey(roleKey);
    cur.setNamespace(namespace);
    cur.setNeedApproval(needApproval);
    cur.setCreatedBy(currentLoginUserName);
    cur.setCreateTime(now);
    cur.setLastUpdatedBy(currentLoginUserName);
    cur.setLastUpdateTime(now);
    cur.setIsDeleted(false);
    authorizationManageService.updateUserRole(pre, cur);
    return new SuccessResponseEntity();
}
Also used : UserRole(com.vip.saturn.job.console.mybatis.entity.UserRole) SuccessResponseEntity(com.vip.saturn.job.console.controller.SuccessResponseEntity) Date(java.util.Date) Audit(com.vip.saturn.job.console.aop.annotation.Audit) PostMapping(org.springframework.web.bind.annotation.PostMapping) ApiResponses(io.swagger.annotations.ApiResponses)

Aggregations

UserRole (com.vip.saturn.job.console.mybatis.entity.UserRole)8 Audit (com.vip.saturn.job.console.aop.annotation.Audit)6 SuccessResponseEntity (com.vip.saturn.job.console.controller.SuccessResponseEntity)6 ApiResponses (io.swagger.annotations.ApiResponses)6 PostMapping (org.springframework.web.bind.annotation.PostMapping)6 Date (java.util.Date)4 Transactional (org.springframework.transaction.annotation.Transactional)2 SaturnJobConsoleException (com.vip.saturn.job.console.exception.SaturnJobConsoleException)1 Role (com.vip.saturn.job.console.mybatis.entity.Role)1 User (com.vip.saturn.job.console.mybatis.entity.User)1