删除用户时同时删除用户角色

This commit is contained in:
shiziyuan9527 2020-06-08 14:10:44 +08:00
parent 5ab8c54f93
commit 0e240b1ad9
2 changed files with 9 additions and 3 deletions

View File

@ -9,7 +9,6 @@ import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.*;
import org.apache.shiro.authz.UnauthorizedException;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.apache.shiro.subject.Subject;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.web.bind.annotation.*;
@ -18,6 +17,8 @@ import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;
import static io.metersphere.commons.constants.SessionConstants.ATTR_USER;
@RestController
@RequestMapping
public class LoginController {
@ -48,9 +49,9 @@ public class LoginController {
try {
subject.login(token);
if (subject.isAuthenticated()) {
UserDTO user = (UserDTO) subject.getSession().getAttribute("user");
UserDTO user = (UserDTO) subject.getSession().getAttribute(ATTR_USER);
// 自动选中组织工作空间
if (StringUtils.isBlank(user.getLastOrganizationId())) {
if (StringUtils.isEmpty(user.getLastOrganizationId())) {
List<UserRole> userRoles = user.getUserRoles();
List<UserRole> test = userRoles.stream().filter(ur -> ur.getRoleId().startsWith("test")).collect(Collectors.toList());
List<UserRole> org = userRoles.stream().filter(ur -> ur.getRoleId().startsWith("org")).collect(Collectors.toList());

View File

@ -183,6 +183,11 @@ public class UserService {
if (StringUtils.equals(user.getId(), userId)) {
MSException.throwException(Translator.get("cannot_delete_current_user"));
}
UserRoleExample example = new UserRoleExample();
example.createCriteria().andUserIdEqualTo(userId);
userRoleMapper.deleteByExample(example);
userMapper.deleteByPrimaryKey(userId);
}