mirror of
https://codeup.aliyun.com/64f7d6b8ce01efaafef1e678/coal/coal.git
synced 2026-01-25 07:46:40 +08:00
feat: 用户相关接口确保要有一个管理员账户
This commit is contained in:
@@ -81,8 +81,7 @@ public class UserService extends BaseService<UserEntity, UserRepository> {
|
||||
@Autowired PasswordDictService passwordDictService;
|
||||
private Pbkdf2PasswordEncoder passwordEncoder;
|
||||
|
||||
@Autowired
|
||||
UserService that;
|
||||
@Autowired UserService that;
|
||||
|
||||
@PostConstruct
|
||||
public void init() {
|
||||
@@ -193,14 +192,41 @@ public class UserService extends BaseService<UserEntity, UserRepository> {
|
||||
UserEntity user = this.repository.get(request.getId());
|
||||
this.mapper.updateEntity(user, request);
|
||||
this.repository.save(user);
|
||||
String organizationId = user.getOrganizationId();
|
||||
|
||||
assertAdmin(organizationId);
|
||||
|
||||
clearUserCache(request.getId());
|
||||
return getById(user.getId());
|
||||
}
|
||||
|
||||
private void assertAdmin(String organizationId) {
|
||||
long adminCnt =
|
||||
this.repository.count(
|
||||
new Specification<UserEntity>() {
|
||||
@Override
|
||||
public Predicate toPredicate(
|
||||
Root<UserEntity> root,
|
||||
CriteriaQuery<?> query,
|
||||
CriteriaBuilder criteriaBuilder) {
|
||||
return criteriaBuilder.and(
|
||||
criteriaBuilder.equal(
|
||||
root.get("organizationId"), organizationId),
|
||||
criteriaBuilder.equal(root.get("orgAdmin"), true));
|
||||
}
|
||||
});
|
||||
|
||||
if (adminCnt == 0) {
|
||||
throw new BizException("组织必须有一个管理员");
|
||||
}
|
||||
}
|
||||
|
||||
public void delete(IdRequest request) {
|
||||
|
||||
this.repository.deleteAllById(request.getIds());
|
||||
request.getIds().forEach(this::clearUserCache);
|
||||
|
||||
this.assertAdmin(Ctx.currentUser().getOrganizationId());
|
||||
}
|
||||
|
||||
public UserDto getById(String id) {
|
||||
@@ -541,7 +567,7 @@ public class UserService extends BaseService<UserEntity, UserRepository> {
|
||||
stopWatch.start("contains");
|
||||
boolean contains = ids.contains(resourceId);
|
||||
stopWatch.stop();
|
||||
// log.info(stopWatch.prettyPrint());
|
||||
// log.info(stopWatch.prettyPrint());
|
||||
return contains;
|
||||
}
|
||||
|
||||
@@ -549,7 +575,5 @@ public class UserService extends BaseService<UserEntity, UserRepository> {
|
||||
Try.run(() -> cacheManager.getCache(Constants.CACHE_USER_RESOURCES).clear());
|
||||
Try.run(() -> cacheManager.getCache(Constants.CACHE_USER_PERMISSIONS).clear());
|
||||
Try.run(() -> cacheManager.getCache(Constants.CACHE_USER_RESOURCE_IDS).clear());
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user