mirror of https://github.com/halo-dev/halo
fix: exclude ghost and anonymous user when counting users (#3370)
#### What type of PR is this? /kind bug #### What this PR does / why we need it: 后台进行用户数量统计时,排除ghost和anonymousUser #### Which issue(s) this PR fixes: Fixes #3349 #### Does this PR introduce a user-facing change? ```release-note 修复仪表盘用户数显示错误问题 ```pull/3366/head^2
parent
adff2a7194
commit
171d4761e6
|
@ -34,6 +34,8 @@ public class User extends AbstractExtension {
|
|||
|
||||
public static final String ROLE_NAMES_ANNO = "rbac.authorization.halo.run/role-names";
|
||||
|
||||
public static final String HIDDEN_USER_LABEL = "halo.run/hidden-user";
|
||||
|
||||
@Schema(required = true)
|
||||
private UserSpec spec;
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package run.halo.app.core.extension.endpoint;
|
||||
|
||||
import static java.lang.Boolean.parseBoolean;
|
||||
import static org.springdoc.core.fn.builders.apiresponse.Builder.responseBuilder;
|
||||
|
||||
import lombok.Data;
|
||||
|
@ -12,6 +13,7 @@ import reactor.core.publisher.Mono;
|
|||
import run.halo.app.core.extension.Counter;
|
||||
import run.halo.app.core.extension.User;
|
||||
import run.halo.app.core.extension.content.Post;
|
||||
import run.halo.app.extension.ExtensionUtil;
|
||||
import run.halo.app.extension.ReactiveExtensionClient;
|
||||
|
||||
/**
|
||||
|
@ -54,7 +56,11 @@ public class StatsEndpoint implements CustomEndpoint {
|
|||
return stats;
|
||||
})
|
||||
.flatMap(stats -> client.list(User.class,
|
||||
user -> user.getMetadata().getDeletionTimestamp() == null,
|
||||
user -> {
|
||||
var labels = ExtensionUtil.nullSafeLabels(user);
|
||||
return user.getMetadata().getDeletionTimestamp() == null
|
||||
&& !parseBoolean(labels.getOrDefault(User.HIDDEN_USER_LABEL, "false"));
|
||||
},
|
||||
null)
|
||||
.count()
|
||||
.map(count -> {
|
||||
|
|
|
@ -2,6 +2,8 @@ apiVersion: v1alpha1
|
|||
kind: User
|
||||
metadata:
|
||||
name: anonymousUser
|
||||
labels:
|
||||
halo.run/hidden-user: "true"
|
||||
finalizers:
|
||||
- system-protection
|
||||
spec:
|
||||
|
@ -14,6 +16,8 @@ apiVersion: v1alpha1
|
|||
kind: User
|
||||
metadata:
|
||||
name: ghost
|
||||
labels:
|
||||
halo.run/hidden-user: "true"
|
||||
finalizers:
|
||||
- system-protection
|
||||
spec:
|
||||
|
|
Loading…
Reference in New Issue