fix: initializes a ghost user by default to replace that the users that has been deleted (#3344)

#### What type of PR is this?

/kind bug

#### What this PR does / why we need it:

系统默认初始化一个 ghost 用户,用于表示用户已删除。

#### Which issue(s) this PR fixes:

Fixes #3317

```release-note
NONE
```
pull/3341/head^2
2023-02-21 17:14:11 +08:00 committed by GitHub
parent e49baa1cf8
commit 2139244a62
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 10 deletions

View File

@ -13,11 +13,4 @@ public class Contributor {
private String displayName;
private String avatar;
private String name;
public static Contributor getGhost() {
Contributor contributor = new Contributor();
contributor.setName("ghost");
contributor.setDisplayName("已删除用户");
return contributor;
}
}

View File

@ -224,15 +224,15 @@ public class PostServiceImpl extends AbstractContentService implements PostServi
return Flux.empty();
}
return Flux.fromIterable(usernames)
.flatMap(username -> client.fetch(User.class, username))
.flatMap(username -> client.fetch(User.class, username)
.switchIfEmpty(Mono.defer(() -> client.fetch(User.class, "ghost"))))
.map(user -> {
Contributor contributor = new Contributor();
contributor.setName(user.getMetadata().getName());
contributor.setDisplayName(user.getSpec().getDisplayName());
contributor.setAvatar(user.getSpec().getAvatar());
return contributor;
})
.defaultIfEmpty(Contributor.getGhost());
});
}
@Override

View File

@ -6,3 +6,15 @@ spec:
displayName: Anonymous User
email: anonymous@example.com
disabled: true
---
apiVersion: v1alpha1
kind: User
metadata:
name: ghost
spec:
displayName: 已删除用户
email: ghost@example.com
disabled: true
bio: 该用户已被删除。