🐛 完善用户权限判断

This commit is contained in:
ronger 2024-05-16 20:23:03 +08:00
parent 0d890c302b
commit f6b6ad3f58
3 changed files with 9 additions and 3 deletions

View File

@ -197,4 +197,6 @@ public interface UserService extends Service<User> {
* @return * @return
*/ */
Set<String> findUserPermissions(User user); Set<String> findUserPermissions(User user);
boolean hasAdminPermission(String account);
} }

View File

@ -59,7 +59,6 @@ public class ArticleServiceImpl extends AbstractService<Article> implements Arti
private static final int MAX_PREVIEW = 200; private static final int MAX_PREVIEW = 200;
private static final String DEFAULT_STATUS = "0"; private static final String DEFAULT_STATUS = "0";
private static final String DEFAULT_TOPIC_URI = "news"; private static final String DEFAULT_TOPIC_URI = "news";
private static final int ADMIN_ROLE_WEIGHTS = 2;
@Resource @Resource
private ApplicationEventPublisher applicationEventPublisher; private ApplicationEventPublisher applicationEventPublisher;
@ -116,8 +115,8 @@ public class ArticleServiceImpl extends AbstractService<Article> implements Arti
String reservedTag = checkTags(articleTags); String reservedTag = checkTags(articleTags);
boolean notification = false; boolean notification = false;
if (StringUtils.isNotBlank(reservedTag)) { if (StringUtils.isNotBlank(reservedTag)) {
Integer roleWeights = userService.findRoleWeightsByUser(user.getIdUser()); boolean isAdmin = userService.hasAdminPermission(user.getEmail());
if (roleWeights > ADMIN_ROLE_WEIGHTS) { if (!isAdmin) {
throw new UltraViresException(StringEscapeUtils.unescapeJava(reservedTag) + "标签为系统保留标签!"); throw new UltraViresException(StringEscapeUtils.unescapeJava(reservedTag) + "标签为系统保留标签!");
} else { } else {
notification = true; notification = true;

View File

@ -332,4 +332,9 @@ public class UserServiceImpl extends AbstractService<User> implements UserServic
permissions.add("user"); permissions.add("user");
return permissions; return permissions;
} }
@Override
public boolean hasAdminPermission(String account) {
return userMapper.hasAdminPermission(account);
}
} }