Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: hide essential notifications to prevent accidental disabling #6972

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions api/src/main/java/run/halo/app/extension/MetadataUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ public enum MetadataUtil {
;

public static final String SYSTEM_FINALIZER = "system-protection";
public static final String HIDDEN_LABEL = "halo.run/hidden";

/**
* Gets extension metadata labels null safe.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@
import run.halo.app.core.extension.notification.NotifierDescriptor;
import run.halo.app.core.extension.notification.ReasonType;
import run.halo.app.extension.Comparators;
import run.halo.app.extension.ExtensionUtil;
import run.halo.app.extension.GroupVersion;
import run.halo.app.extension.ListOptions;
import run.halo.app.extension.MetadataUtil;
import run.halo.app.extension.ReactiveExtensionClient;
import run.halo.app.infra.utils.JsonUtils;
Expand Down Expand Up @@ -140,7 +142,12 @@ private static <T> Map<String, Integer> toNameIndexMap(List<T> collection,
}

Mono<ReasonTypeNotifierMatrix> listReasonTypeNotifierMatrix(String username) {
return client.list(ReasonType.class, null, Comparators.defaultComparator())
var listOptions = ListOptions.builder()
.labelSelector()
.notExists(MetadataUtil.HIDDEN_LABEL)
.end()
.build();
return client.listAll(ReasonType.class, listOptions, ExtensionUtil.defaultSort())
.map(ReasonTypeInfo::from)
.collectList()
.flatMap(reasonTypes -> client.list(NotifierDescriptor.class, null,
Expand Down
4 changes: 2 additions & 2 deletions application/src/main/resources/extensions/notification.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ kind: ReasonType
metadata:
name: email-verification
labels:
halo.run/hide: "true"
halo.run/hidden: "true"
spec:
displayName: "邮箱验证"
description: "当你的邮箱被用于注册账户时,会收到一条带有验证码的邮件,你需要点击邮件中的链接来验证邮箱是否属于你。"
Expand All @@ -191,7 +191,7 @@ kind: ReasonType
metadata:
name: reset-password-by-email
labels:
halo.run/hide: "true"
halo.run/hidden: "true"
spec:
displayName: "根据邮件地址重置密码"
description: "当你通过邮件地址找回密码时,会收到一条带密码重置链接的邮件,你需要点击邮件中的链接来重置密码。"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package run.halo.app.notification.endpoint;

import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.assertArg;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.when;

Expand All @@ -15,6 +17,7 @@
import reactor.core.publisher.Mono;
import run.halo.app.core.extension.notification.NotifierDescriptor;
import run.halo.app.core.extension.notification.ReasonType;
import run.halo.app.extension.ExtensionUtil;
import run.halo.app.extension.ReactiveExtensionClient;
import run.halo.app.notification.UserNotificationPreferenceService;

Expand Down Expand Up @@ -43,11 +46,16 @@ void setUp() {
webTestClient = WebTestClient
.bindToRouterFunction(userNotificationPreferencesEndpoint.endpoint())
.build();

when(client.listAll(eq(ReasonType.class), assertArg(option ->
assertThat(option.toString())
.isEqualTo("labelSelector: (halo.run/hidden NOT_EXISTS)")),
eq(ExtensionUtil.defaultSort()))
).thenReturn(Flux.empty());
}

@Test
void listNotificationPreferences() {
when(client.list(eq(ReasonType.class), eq(null), any())).thenReturn(Flux.empty());
when(client.list(eq(NotifierDescriptor.class), eq(null), any())).thenReturn(Flux.empty());
when(userNotificationPreferenceService.getByUser(any())).thenReturn(Mono.empty());
webTestClient.post()
Expand All @@ -59,7 +67,6 @@ void listNotificationPreferences() {

@Test
void saveNotificationPreferences() {
when(client.list(eq(ReasonType.class), eq(null), any())).thenReturn(Flux.empty());
when(client.list(eq(NotifierDescriptor.class), eq(null), any())).thenReturn(Flux.empty());
when(userNotificationPreferenceService.getByUser(any())).thenReturn(Mono.empty());
webTestClient.post()
Expand Down
Loading