Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into feat/refine-i18n-fo…
Browse files Browse the repository at this point in the history
…r-auth-providers
  • Loading branch information
ruibaby committed Oct 7, 2024
2 parents f760713 + dfbab28 commit 4e99ee7
Show file tree
Hide file tree
Showing 65 changed files with 1,165 additions and 1,015 deletions.
32 changes: 32 additions & 0 deletions api-docs/openapi/v3_0/aggregated.json
Original file line number Diff line number Diff line change
Expand Up @@ -15117,6 +15117,38 @@
]
}
},
"/apis/uc.api.content.halo.run/v1alpha1/posts/{name}/recycle": {
"delete": {
"description": "Move my post to recycle bin.",
"operationId": "RecycleMyPost",
"parameters": [
{
"description": "Post name",
"in": "path",
"name": "name",
"required": true,
"schema": {
"type": "string"
}
}
],
"responses": {
"default": {
"content": {
"*/*": {
"schema": {
"$ref": "#/components/schemas/Post"
}
}
},
"description": "default response"
}
},
"tags": [
"PostV1alpha1Uc"
]
}
},
"/apis/uc.api.content.halo.run/v1alpha1/posts/{name}/unpublish": {
"put": {
"description": "Unpublish my post.",
Expand Down
32 changes: 32 additions & 0 deletions api-docs/openapi/v3_0/apis_uc.api_v1alpha1.json
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,38 @@
]
}
},
"/apis/uc.api.content.halo.run/v1alpha1/posts/{name}/recycle": {
"delete": {
"description": "Move my post to recycle bin.",
"operationId": "RecycleMyPost",
"parameters": [
{
"description": "Post name",
"in": "path",
"name": "name",
"required": true,
"schema": {
"type": "string"
}
}
],
"responses": {
"default": {
"content": {
"*/*": {
"schema": {
"$ref": "#/components/schemas/Post"
}
}
},
"description": "default response"
}
},
"tags": [
"PostV1alpha1Uc"
]
}
},
"/apis/uc.api.content.halo.run/v1alpha1/posts/{name}/unpublish": {
"put": {
"description": "Unpublish my post.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,6 @@ public interface PostService {
Mono<Post> revertToSpecifiedSnapshot(String postName, String snapshotName);

Mono<ContentWrapper> deleteContent(String postName, String snapshotName);

Mono<Post> recycleBy(String postName, String username);
}
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,15 @@ public Mono<ContentWrapper> deleteContent(String postName, String snapshotName)
});
}

@Override
public Mono<Post> recycleBy(String postName, String username) {
return getByUsername(postName, username)
.flatMap(post -> updatePostWithRetry(post, record -> {
record.getSpec().setDeleted(true);
return record;
}));
}

private Mono<Post> updatePostWithRetry(Post post, UnaryOperator<Post> func) {
return client.update(func.apply(post))
.onErrorResume(OptimisticLockingFailureException.class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,27 @@ public RouterFunction<ServerResponse> endpoint() {
.operationId("UnpublishMyPost")
.description("Unpublish my post.")
.parameter(namePathParam)
.response(responseBuilder().implementation(Post.class)))
.response(responseBuilder().implementation(Post.class))
)
.DELETE("/{name}/recycle", this::recycleMyPost, builder -> builder.tag(tag)
.operationId("RecycleMyPost")
.description("Move my post to recycle bin.")
.parameter(namePathParam)
.response(responseBuilder().implementation(Post.class))
)
.build(),
builder -> {
})
.build();
}

private Mono<ServerResponse> recycleMyPost(ServerRequest request) {
final var name = request.pathVariable("name");
return getCurrentUser()
.flatMap(username -> postService.recycleBy(name, username))
.flatMap(post -> ServerResponse.ok().bodyValue(post));
}

private Mono<ServerResponse> getMyPostDraft(ServerRequest request) {
var name = request.pathVariable("name");
var patched = request.queryParam("patched").map(Boolean::valueOf).orElse(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,14 @@ public Mono<Void> restore(Publisher<DataBuffer> content) {
return Mono.usingWhen(
createTempDir("halo-restore-", scheduler),
tempDir -> unpackBackup(content, tempDir)
.then(Mono.defer(() -> restoreExtensions(tempDir)))
.then(Mono.defer(() ->
// This step skips index verification such as unique index.
// In order to avoid index conflicts after recovery or
// OptimisticLockingFailureException when updating the same record,
// so we need to truncate all extension stores before saving(create or update).
repository.deleteAll()
.then(restoreExtensions(tempDir)))
)
.then(Mono.defer(() -> restoreWorkdir(tempDir))),
tempDir -> deleteRecursivelyAndSilently(tempDir, scheduler)
);
Expand Down Expand Up @@ -241,13 +248,9 @@ private Mono<Void> restoreExtensions(Path backupRoot) {
sink.complete();
})
// reset version
.doOnNext(extensionStore -> extensionStore.setVersion(null)).buffer(100)
// We might encounter OptimisticLockingFailureException when saving extension
// store,
// So we have to delete all extension stores before saving.
.flatMap(extensionStores -> repository.deleteAll(extensionStores)
.thenMany(repository.saveAll(extensionStores))
)
.doOnNext(extensionStore -> extensionStore.setVersion(null))
.buffer(100)
.flatMap(repository::saveAll)
.doOnNext(extensionStore -> log.info("Restored extension store: {}",
extensionStore.getName()))
.then(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ metadata:
# Currently, yaml definition does not support i18n, please see https://github.com/halo-dev/halo/issues/3573
rbac.authorization.halo.run/display-name: "Post Author"
rbac.authorization.halo.run/dependencies: |
[ "role-template-post-contributor", "role-template-post-publisher", "role-template-post-attachment-manager" ]
[ "role-template-post-contributor", "role-template-post-publisher", "role-template-recycle-my-post",
"role-template-post-attachment-manager" ]
rules: [ ]

---
Expand Down Expand Up @@ -98,6 +99,23 @@ rules:
resources: [ "posts/publish", "posts/unpublish" ]
verbs: [ "update" ]

---
apiVersion: v1alpha1
kind: Role
metadata:
name: role-template-recycle-my-post
labels:
halo.run/role-template: "true"
annotations:
rbac.authorization.halo.run/module: "Posts Management"
rbac.authorization.halo.run/display-name: "Recycle My Post"
rbac.authorization.halo.run/ui-permissions: |
[ "uc:posts:recycle" ]
rules:
- apiGroups: [ "uc.api.content.halo.run" ]
resources: [ "posts/recycle" ]
verbs: [ "delete" ]

---
apiVersion: v1alpha1
kind: Role
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,35 +8,7 @@
<div th:replace="~{gateway_modules/common_fragments::haloLogo}"></div>
<div class="halo-form-wrapper">
<h1 class="form-title" th:text="#{title}"></h1>
<form
class="halo-form"
th:action="@{/challenges/two-factor/totp}"
name="two-factor-form"
id="two-factor-form"
method="post"
>
<div class="alert alert-error" role="alert" th:if="${param.error.size() > 0}">
<strong th:text="#{messages.invalidError}"></strong>
</div>
<div class="form-item">
<label for="code" th:text="#{form.code.label}"></label>
<div class="form-input">
<input
type="text"
inputmode="numeric"
id="code"
name="code"
autocomplete="one-time-code"
pattern="\d{6}"
autofocus
required
/>
</div>
</div>
<div class="form-item">
<button type="submit" th:text="#{form.submit}"></button>
</div>
</form>
<form th:replace="~{gateway_modules/form_fragments::totp}"></form>
</div>
</div>
</th:block>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
title=两步验证
messages.invalidError=错误的验证码
form.code.label=验证码
form.submit=验证
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
title=Two-Factor Authentication
messages.invalidError=Invalid TOTP code
form.code.label=TOTP Code
form.submit=Verify
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
title=Autenticación en Dos Pasos
messages.invalidError=Código de verificación incorrecto
form.code.label=Código de Verificación
form.submit=Verificar
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
title=兩步驗證
messages.invalidError=錯誤的驗證碼
form.code.label=驗證碼
form.submit=驗證
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
<th:block th:fragment="basicStaticResources">
<link rel="stylesheet" href="/webjars/normalize.css/8.0.1/normalize.css" />
<link rel="stylesheet" th:href="|/styles/main.css?v=${site.version}|" />
<th:block th:replace="~{gateway_modules/common_fragments::basicStyleResources}"></th:block>
<th:block th:replace="~{gateway_modules/common_fragments::basicScriptResources}"></th:block>
</th:block>

<th:block th:fragment="basicScriptResources">
<script th:inline="javascript">
const i18nResources = {
sendVerificationCodeSuccess: `[(#{js.sendVerificationCode.success})]`,
Expand All @@ -12,6 +14,11 @@
<script src="/js/main.js"></script>
</th:block>

<th:block th:fragment="basicStyleResources">
<link rel="stylesheet" href="/webjars/normalize.css/8.0.1/normalize.css" />
<link rel="stylesheet" th:href="|/styles/main.css?v=${site.version}|" />
</th:block>

<div th:remove="tag" th:fragment="languageSwitcher">
<style>
.language-switcher {
Expand Down Expand Up @@ -111,4 +118,4 @@
</li>
</ul>
</th:block>
</div>
</div>
Loading

0 comments on commit 4e99ee7

Please sign in to comment.