Commit Graph

2445 Commits (9dee9b0409de1357da5bfa0b185a1469d032975f)

Author SHA1 Message Date
longjuan 9dee9b0409
fix: incorrect number of comments (#3295)
<!--  Thanks for sending a pull request!  Here are some tips for you:
1. 如果这是你的第一次,请阅读我们的贡献指南:<https://github.com/halo-dev/halo/blob/master/CONTRIBUTING.md>。
1. If this is your first time, please read our contributor guidelines: <https://github.com/halo-dev/halo/blob/master/CONTRIBUTING.md>.
2. 请根据你解决问题的类型为 Pull Request 添加合适的标签。
2. Please label this pull request according to what type of issue you are addressing, especially if this is a release targeted pull request.
3. 请确保你已经添加并运行了适当的测试。
3. Ensure you have added or ran the appropriate tests for your PR.
-->

#### What type of PR is this?
/kind bug
/area core
<!--
添加其中一个类别:
Add one of the following kinds:

/kind bug
/kind cleanup
/kind documentation
/kind feature
/kind improvement

适当添加其中一个或多个类别(可选):
Optionally add one or more of the following kinds if applicable:

/kind api-change
/kind deprecation
/kind failing-test
/kind flake
/kind regression
-->

#### What this PR does / why we need it:
Fixed incorrect number of comments after comment deletion.
#### Which issue(s) this PR fixes:

<!--
PR 合并时自动关闭 issue。
Automatically closes linked issue when PR is merged.

用法:`Fixes #<issue 号>`,或者 `Fixes (粘贴 issue 完整链接)`
Usage: `Fixes #<issue number>`, or `Fixes (paste link of issue)`.
-->
Fixes https://github.com/halo-dev/halo/issues/3287

#### Special notes for your reviewer:
为一篇文章添加多个评论,期望评论数量正确。
删除评论,期望评论数量正常减少。
删除全部评论,期望评论数量归零。
#### Does this PR introduce a user-facing change?

<!--
如果当前 Pull Request 的修改不会造成用户侧的任何变更,在 `release-note` 代码块儿中填写 `NONE`。
否则请填写用户侧能够理解的 Release Note。如果当前 Pull Request 包含破坏性更新(Break Change),
Release Note 需要以 `action required` 开头。
If no, just write "NONE" in the release-note block below.
If yes, a release note is required:
Enter your extended release note in the block below. If the PR requires additional action from users switching to the new release, include the string "action required".
-->

```release-note
修复删除评论后Console端文章和单页评论数量不正确
```
2023-02-15 06:52:12 +00:00
John Niang 5f7ea18f7c
Auto rename attachment if it exists (#3305)
#### What type of PR is this?

/kind improvement
/area core
/milestone 2.3.x

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

Before this PR, halo will throw an FileAlreadyExists exception if users upload file which already exists.

But now, we will rename the attachment automatically on filename conflict. e.g.:

```bash
halo.run -> halo-xyz.run
.run -> xyz.run
halo -> halo-xyz
```

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

Fixes https://github.com/halo-dev/halo/issues/3218

#### Special notes for your reviewer:

![image](https://user-images.githubusercontent.com/16865714/218670068-87389289-1248-48e8-82a4-1bcf939e64e3.png)

#### Does this PR introduce a user-facing change?

```release-note
附件已存在时自动重命名
```
2023-02-15 05:38:12 +00:00
e485acef66
perf: associate ghost user with posts on user deletion. (#3293)
#### What type of PR is this?

/kind bug

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

文章发布用户被删除后,设置这篇文章的发布人为Ghost

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

Fixes #3265

```release-note
NONE
```
2023-02-15 05:36:14 +00:00
Ryan Wang 26f29b20c7
chore: add @LIlGG to reviewers list (#3292)
#### What type of PR is this?

/kind improvement

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

将 @LIlGG 添加到 Reviewer 列表。

#### Does this PR introduce a user-facing change?

```release-note
None
```
2023-02-13 01:48:18 +00:00
Ryan Wang 3de9f7f80e
perf: refine display name of system default role (#3280)
#### What type of PR is this?

/kind improvement

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

为系统初始化的角色添加显示名称

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


Fixes https://github.com/halo-dev/halo/issues/3257

#### Screenshots:

<img width="1668" alt="image" src="https://user-images.githubusercontent.com/21301288/218020794-696420c4-69bb-4422-9409-482bb2aff708.png">


#### Special notes for your reviewer:

see 

#### Does this PR introduce a user-facing change?

```release-note
为系统初始化的角色添加显示名称
```
2023-02-10 08:38:16 +00:00
guqing e9389ac1d8
refactor: lru cache key for template engine manager (#3243)
#### What type of PR is this?
/kind improvement
/area core
/milestone 2.3.x

#### What this PR does / why we need it:
修改 TemplateEngineManager 中 LRU cache 的缓存 key
see #3242 for more details.

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

#### Special notes for your reviewer:
how to test it?
1. 安装几个主题测试预览功能是否正常
2. 特别关注激活主题的预览,激活主题的预览和激活主题直接访问使用的不同的 TemplateEngine

/cc @halo-dev/sig-halo 
#### Does this PR introduce a user-facing change?
```release-note
None
```
2023-02-10 07:40:15 +00:00
Ryan Wang 2aa80cfffd
docs: update readme (#3256)
#### What type of PR is this?

/kind documentation

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

更新产品的一句话定位。

```release-note
None
```
2023-02-10 02:46:14 +00:00
findwinds 56aa7de85a
Fix random list problem of tags and categories (#3261)
<!--  Thanks for sending a pull request!  Here are some tips for you:
1. 如果这是你的第一次,请阅读我们的贡献指南:<https://github.com/halo-dev/halo/blob/master/CONTRIBUTING.md>。
1. If this is your first time, please read our contributor guidelines: <https://github.com/halo-dev/halo/blob/master/CONTRIBUTING.md>.
2. 请根据你解决问题的类型为 Pull Request 添加合适的标签。
2. Please label this pull request according to what type of issue you are addressing, especially if this is a release targeted pull request.
3. 请确保你已经添加并运行了适当的测试。
3. Ensure you have added or ran the appropriate tests for your PR.
-->

#### What type of PR is this?
/kind bug

<!--
添加其中一个类别:
Add one of the following kinds:

/kind bug
/kind cleanup
/kind documentation
/kind feature
/kind improvement

适当添加其中一个或多个类别(可选):
Optionally add one or more of the following kinds if applicable:

/kind api-change
/kind deprecation
/kind failing-test
/kind flake
/kind regression
-->

#### What this PR does / why we need it:
replaced flatMap with flatMapSequential to ensure that the list of tags and categories shown in console post order is not random

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

<!--
PR 合并时自动关闭 issue。
Automatically closes linked issue when PR is merged.

用法:`Fixes #<issue 号>`,或者 `Fixes (粘贴 issue 完整链接)`
Usage: `Fixes #<issue number>`, or `Fixes (paste link of issue)`.
-->
Fixes #3139

#### Special notes for your reviewer:
/cherrypick release-2.0
/cherrypick release-2.1

#### Does this PR introduce a user-facing change?

<!--
如果当前 Pull Request 的修改不会造成用户侧的任何变更,在 `release-note` 代码块儿中填写 `NONE`。
否则请填写用户侧能够理解的 Release Note。如果当前 Pull Request 包含破坏性更新(Break Change),
Release Note 需要以 `action required` 开头。
If no, just write "NONE" in the release-note block below.
If yes, a release note is required:
Enter your extended release note in the block below. If the PR requires additional action from users switching to the new release, include the string "action required".
-->

```release-note
修复控制台文章列表中,标签和分类顺序随机的问题
```
2023-02-09 04:24:13 +00:00
guqing 7453b93b1d
fix: default value cannot be read when the setting is not created because of asynchrony (#3236)
#### What type of PR is this?
/kind improvement
/area core
/milestone 2.2.x
/cherry-pick release-2.2
#### What this PR does / why we need it:
修复插件安装时有几率出现设置没有默认值导致无法保存的问题

see https://github.com/halo-dev/halo/issues/3224#issuecomment-1418825809 for more details

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

Fixes #3224

#### Special notes for your reviewer:
how to test it?
1. 安装 https://github.com/halo-sigs/plugin-feed 插件并立即启用(或以开发模式)
2. 到此插件设置**始终**能查询到默认值并且能保存

/cc @halo-dev/sig-halo 
#### Does this PR introduce a user-facing change?

```release-note
修复插件安装时有几率出现设置没有默认值导致无法保存的问题
```
2023-02-08 07:16:13 +00:00
guqing 6809dbb251
fix: plugin status check to prevent inconsistent status (#3235)
#### What type of PR is this?
/kind improvement
/area core
/milestone 2.3.x
#### What this PR does / why we need it:
当开发模式启动时上传 JAR 运行插件会出现插件不存在的异常,但由于 PluginReconciler 中检查状态不一致后 return 在 optional 语句中只是让当前 optional 后面的代码停止执行,还会继续执行 optional 外面的代码导致 status 的异常信息不一致,进而 object equals 始终为 false 而无法让 reconciler 终止运行导致循环。

此 PR 调整了一下代码位置,进入 reconciler 时先进行检查,如果不满足则不执行后面的代码同时将信息写入 plugin.status 让用户知晓。

此问题是修改了 Reconciler 判断逻辑后出现的 https://github.com/halo-dev/halo/pull/3210 ,因此不影响之前的代码只针对当前 2.3.x

#### Special notes for your reviewer:
how to test it?
1. 模拟一个插件找不到的错误场景例如以生产模式启动插件但配置 fixed-plugin 指定为插件项目目录
2. 启动 Halo 看 Reconciler 是否会一直在控制台输出日志
3. 卸载它能成功

/cc @halo-dev/sig-halo 
#### Does this PR introduce a user-facing change?

```release-note
None
```
2023-02-07 07:10:14 +00:00
John Niang df9b04c4d5
Reduce the number of queries to resolve theme (#3238)
#### What type of PR is this?

/kind improvement
/area core

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

Save ThemeContext into ServerWebExchange to reduce the number of queries to resolve theme from 2(or 3) to 1.

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

Fixes https://github.com/halo-dev/halo/issues/3162

#### Does this PR introduce a user-facing change?

```release-note
优化查询主题的查询次数
```
2023-02-07 06:40:12 +00:00
John Niang df97ee8629
Refine exception message of duplicate key (#3219)
#### What type of PR is this?

/kind improvement
/area core
/milestone 2.3.x

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

I create another exception `DuplicateNameException` to map `org.springframework.dao.DuplicateKeyException` when creating extensions.

See https://github.com/halo-dev/halo/issues/3180 for more.

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

Fixes https://github.com/halo-dev/halo/issues/3180

#### Special notes for your reviewer:

1. Try to create an user which name has already exist
2. See the error

#### Does this PR introduce a user-facing change?

```release-note
优化名称重复的错误提示
```
2023-02-03 09:50:11 +00:00
John Niang 4636990d5c
Fix the problem that publishing post always fails (#3210)
#### What type of PR is this?

/kind improvement
/area core
/milestone 2.3.x

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

1. Refactor Queue in Controller. I add dirty set of request to avoid lost of new request from other places instead of reconciler.
2. Enhance equals and hashcode methods to ensure we can ignore updates of same extensions.

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

Fixes https://github.com/halo-dev/halo/issues/2860

#### Special notes for your reviewer:

Please take some time to test publishing posts.

#### Does this PR introduce a user-facing change?

```release-note
修复发布文章时经常出现错误的问题
```
2023-02-02 12:16:10 +00:00
guqing 0fd023b8f6
fix: plugin disappeared after plugin with same name reinstalled (#3198)
#### What type of PR is this?
/kind bug
/area core
/milestone 2.2.x

#### What this PR does / why we need it:
修复重复安装插件时 JAR 文件被删除的问题

需要注意的场景:
prod 模式下,假如安装一个 sitemap 插件,版本为 1.0.0 ,而此时 plugins 目录已经存在同名文件 sitemap-1.0.0.jar 文件但 sitemap 的 plugin.yaml 没有被持久化过,则能正常安装,旧的 JAR 文件被覆盖。

see #3159 for more details
#### Which issue(s) this PR fixes:

Fixes #3159

#### Special notes for your reviewer:
/cc @halo-dev/sig-halo
#### Does this PR introduce a user-facing change?

```release-note
修复重复安装插件时 JAR 文件被删除的问题
```
2023-02-02 02:44:11 +00:00
John Niang 764b664fd8
Bump Halo version to 2.3.0-SNAPSHOT for main branch (#3201)
#### What type of PR is this?

/kind cleanup
/area core

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

Bump Halo version to 2.3.0-SNAPSHOT and update README.md

#### Does this PR introduce a user-facing change?

```release-note
None
```
2023-02-01 08:04:09 +00:00
John Niang 0c18fb3ec4
Fix the problem of not initializing default theme correctly (#3194)
#### What type of PR is this?

/kind bug
/area core
/milestone 2.2.x

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

Make requires field of Theme not required.

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

Fixes https://github.com/halo-dev/halo/issues/3177

#### Special notes for your reviewer:

1. Clear Halo working directory
2. Start Halo freshly

#### Does this PR introduce a user-facing change?

```release-note
None
```
2023-01-31 14:18:10 +00:00
John Niang c079762f65
Upgrade Lucene to 9.5.0 (#3190)
#### What type of PR is this?

/kind improvement
/area core
/milestone 2.2.x

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

See https://lucene.apache.org/core/9_5_0/MIGRATE.html for more.

#### Special notes for your reviewer:

Please confirm that the search widget is working fine.

#### Does this PR introduce a user-facing change?

```release-note
升级依赖 Lucene 至 9.5.0
```
2023-01-31 07:14:09 +00:00
John Niang f851b1ba53
Upgrade pf4j to 3.9.0 (#3191)
#### What type of PR is this?

/kind imporvement
/area core
/milestone 2.2.x

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

See 2d3cf24fed/CHANGELOG.md (390---2023-01-30) for more.

#### Special notes for your reviewer:

Please confirm that the plugin module is working fine.

#### Does this PR introduce a user-facing change?

```release-note
升级依赖 PF4J 至 3.9.0
```
2023-01-31 06:10:10 +00:00
John Niang b0be55cfad
Upgrade jasync-sql to 2.1.23 (#3192)
#### What type of PR is this?

/kind improvement
/area core
/milestone 2.2.x

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

See https://github.com/jasync-sql/jasync-sql/releases/tag/2.1.23 for more.

#### Does this PR introduce a user-facing change?

```release-note
升级依赖 jasync-sql 至 2.1.13
```
2023-01-31 05:54:09 +00:00
John Niang ef45f396d8
Upgrade SpringDoc to 2.0.2 (#3186)
#### What type of PR is this?

/kind improvement
/area core
/milestone 2.2.x

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

See <https://github.com/springdoc/springdoc-openapi/releases/tag/v2.0.2> and <https://github.com/springdoc/springdoc-openapi/releases/tag/v2.0.1> for more.

#### Does this PR introduce a user-facing change?

```release-note
升级依赖 SpringDoc 至 2.0.2
```
2023-01-31 03:04:09 +00:00
John Niang bb7fe81343
Add spring-context-indexer to speed up startup (#3185)
#### What type of PR is this?

/kind improvement
/area core
/milestone 2.2.x

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

See https://docs.spring.io/spring-framework/docs/current/reference/html/core.html#beans-scanning-index for more.

#### Special notes for your reviewer:

This might help a little, bu we have to.

#### Does this PR introduce a user-facing change?

```release-note
None
```
2023-01-31 02:58:09 +00:00
John Niang 1810255aea
Provide system config endpoint (#3182)
#### What type of PR is this?

/kind feature
/area core
/milestone 2.2.x

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

Provide `globalconfig` actuator endpoint to let console and theme know how to do according various system configuration. The endpoint allows anonymous users to access, but other actuator endpoints can be accessed by admin users.

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

Fixes https://github.com/halo-dev/halo/issues/3055

#### Special notes for your reviewer:

Try to request <http://localhost:8090/actuator/globalinfo> and see the result.

```json
{
   "externalUrl":"http://localhost:8090",
   "timeZone":"Asia/Shanghai",
   "locale":"en_US",
   "allowComments":true,
   "allowRegistration":false
}
```

You can request <http://localhost:8090/actuator/info> to see more detail as well.

```json
{
  "git": {
    "branch": "feat/system-info",
    "commit": {
      "id": "ca4e93d",
      "time": "2023-01-19T08:56:15Z"
    }
  },
  "build": {
    "artifact": "halo",
    "name": "halo",
    "time": "2023-01-29T15:04:42.151Z",
    "version": "2.2.0-SNAPSHOT",
    "group": "run.halo.app"
  },
  "java": {
    "version": "17.0.6",
    "vendor": {
      "name": "Amazon.com Inc.",
      "version": "Corretto-17.0.6.10.1"
    },
    "runtime": {
      "name": "OpenJDK Runtime Environment",
      "version": "17.0.6+10-LTS"
    },
    "jvm": {
      "name": "OpenJDK 64-Bit Server VM",
      "vendor": "Amazon.com Inc.",
      "version": "17.0.6+10-LTS"
    }
  },
  "os": {
    "name": "Windows 11",
    "version": "10.0",
    "arch": "amd64"
  }
}
```

#### Does this PR introduce a user-facing change?

```release-note
提供系统配置详情端口
```
2023-01-30 07:20:11 +00:00
guqing 3bd0a09764
perf: optimize snapshot queries for post and single page (#3168)
#### What type of PR is this?
/kind improvement
/area core
/milestone 2.2.x
/kind api-change

#### What this PR does / why we need it:
优化文章和自定义页面的内容查询

- 文章新增 `GET /posts/{name}/release-content` 和 `GET /posts/{name}/head-content` 自定义 APIs
- 自定义页面新增 `GET /posts/{name}/release-content` 和 `GET /posts/{name}/head-content` 自定义 APIs

⚠️ 移除了 ContentEndpoint,如果 Console 调用过 `/apis/api.console.halo.run/contents/{name}` 查询内容则需要用文章或自定义页面的自定义APIs 替代

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

Fixes #3140
Fixes https://github.com/halo-dev/halo/issues/3026

#### Special notes for your reviewer:
/cc @halo-dev/sig-halo 
#### Does this PR introduce a user-facing change?

```release-note
优化文章和自定义页面的内容查询
```
2023-01-30 07:18:15 +00:00
guqing 1d4f65c0cf
feat: add some APIs to separate plugin-related Setting and ConfigMap permissions (#3142)
#### What type of PR is this?
/kind improvement
/area core
/kind api-change
/milestone 2.2.x

#### What this PR does / why we need it:
添加自定义 APIs 以分离插件对 Setting 和 ConfigMap 权限的依赖

⚠️ 此 PR 新增了 APIs,需要 Console 对其进行适配,插件查询 Setting、ConfigMap 的 APIs 需要更改。

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

A part of https://github.com/halo-dev/halo/issues/3069

Fixes https://github.com/halo-dev/halo/issues/3069

#### Special notes for your reviewer:
how to test it?
- 测试 GET /plugins/{name}/setting 是否能正确获取到插件名称对应的主题的 Setting。
- 测试 GET /plugins/{name}/config 是否能正确获取到插件名称对应的主题的 ConfigMap。
- 测试 PUT /plugins/{name}/config 是否能更新插件的 ConfigMap,如果名称不匹配则抛出异常。
切换用户为其分配主题的查看权限可以有权限调用以上描述的 GET 请求的 endpoints,管理权限可以调用 PUT /plugins/{name}/config。
/cc @halo-dev/sig-halo 
#### Does this PR introduce a user-facing change?

```release-note
添加自定义 APIs 以分离插件对 Setting 和 ConfigMap 权限的依赖
```
2023-01-30 06:28:11 +00:00
guqing 7f4b3a1330
feat: add some APIs to separate theme-related Setting and ConfigMap permissions (#3135)
#### What type of PR is this?
/kind feature
/milestone 2.2.x
/area core
/kind api-change

#### What this PR does / why we need it:
添加自定义 APIs 以分离主题对 Setting 和 ConfigMap 权限的依赖

⚠️ 此 PR 新增了 APIs,需要 Console 对其进行适配,主题菜单下获取激活主题的 API 以及查询主题 Setting、ConfigMap 的 APIs 需要更改。

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

A part of #3069

Fixes https://github.com/halo-dev/halo/issues/3069

#### Special notes for your reviewer:
how to test it?
- 测试 `GET /themes/-/activation` 此 endpoint 是否能正确获取到激活主题信息
- 测试 `GET /themes/{name}/setting` 是否能正确获取到主题名称对应的主题的 Setting,如果 name 为 `-` 表示查询当前激活主题的 Setting
- 测试 `GET /themes/{name}/config` 是否能正确获取到主题名称对应的主题的 ConfigMap, 如果 name 为 `-` 表示查询当前激活主题的 ConfigMap。
- 测试 `PUT themes/{name}/config` 是否能更新主题的 ConfigMap,如果名称不匹配则抛出异常。
切换用户为其分配主题的查看权限可以有权限调用以上描述的 GET 请求的 endpoints,管理权限可以调用 `PUT themes/{name}/config`。
- 测试 `PUT /themes/{name}/activation` 是否能设置激活主题。

/cc @halo-dev/sig-halo 
#### Does this PR introduce a user-facing change?

```release-note
添加自定义 APIs 以分离主题对 Setting 和 ConfigMap 权限的依赖
```
2023-01-30 06:26:12 +00:00
John Niang 536218d702
Upgrade Spring Boot to 3.0.2 (#3176)
#### What type of PR is this?

/kind improvement
/area core
/milestone 2.2.x

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

Upgrade Spring Boot to 3.0.2. 

See https://github.com/spring-projects/spring-boot/releases/tag/v3.0.2 for more.

#### Does this PR introduce a user-facing change?

```release-note
升级依赖 Spring Boot 至 3.0.2
```
2023-01-30 03:44:12 +00:00
John Niang 7188464bc1
Fix the problem of slug name with percent sign when publishing post (#3179)
#### What type of PR is this?

/kind bug
/area core
/milestone 2.2.x

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

Remove URI decode operation while inserting key into RadixRouterTree to avoid repeat decode.

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

Fixes #3178 

#### Special notes for your reviewer:

1. Set slug name to `1%1` when creating a post
2. Publish it
3. Browse the post

#### Does this PR introduce a user-facing change?

```release-note
修复因别名包含百分号导致无法正常访问的问题
```
2023-01-30 03:16:11 +00:00
guqing ca4e93d4bb
refactor: initialize default config value by settings after plugin installation (#3161)
#### What type of PR is this?
/kind improvement
/area core
/milestone 2.2.x

#### What this PR does / why we need it:
插件安装后根据配置的 settingName 读取默认值创建 ConfigMap
如果配置了 settingName 而没有配置 configMapName 则会自动填充为 uuid 并创建一个 ConfigMap
#### Which issue(s) this PR fixes:

Fixes #3160

#### Special notes for your reviewer:
/cc @halo-dev/sig-halo 
#### Does this PR introduce a user-facing change?

```release-note
插件安装后自动初始化 Setting 的默认值
```
2023-01-19 08:56:15 +00:00
John Niang 2241c08371
Fix the problem of not using error template in theme (#3166)
#### What type of PR is this?

/kind bug
/area core

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

Currently, if there is no `error.html` error template in theme, but there is a `404.html` error template, this will not work correctly.

We always get rendering result from global error template `error.html`.

This PR mainly provides a `ThemeTemplateAvailabilityProvider` to check if the template is available in theme instead of in globally predefined templates.

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

Fixes https://github.com/halo-dev/halo/issues/3062

#### Special notes for your reviewer:

1. Download and install any theme
2. Check the theme folder
3. Check folder `templates/error`
4. Try to remove `templates/error/error.html` template file
5. Create `templates/error/404.html`
6. Request a page which does not exist
7. See the result

#### Does this PR introduce a user-facing change?

```release-note
解决主题自定义错误模板不生效的问题。
```
2023-01-19 07:46:14 +00:00
guqing da07d75df3
feat: support validate requires version for theme (#3150)
#### What type of PR is this?
/kind feature
/milestone 2.2.x
/kind api-change

#### What this PR does / why we need it:
主题支持 requires 版本验证
- 主题安装和更新时会校验 requires,如果不通过则抛出异常。
- 主题重载或者 halo 升级后导致主题 requires 不满足条件,则会在 status 中将 phase 标记为 failed

⚠️ 特别说明:
- 由于之前主题的 require 字段沿用了 1.x 版本,并没有发现与插件的 requires 属性命名不相同,因此添加了一个 requires 属性,并将 require 标记为过时,后续移除它,这个改动不算是破坏性,但如果主题需要版本校验则需要更改 theme.yaml 为 requires
- 校验后如果有错误则 console 端应该提示主题升级,这样可以避免用户不知情导致很长时间主题端模板都渲染错误问题。可以通过判断 status.phase 是否为 FAILED 来展示 conditions 的第一个 item 的信息。
- 例如 halo 升级后 requires 不满足条件这种情况,并且这个主题被启用,也不会去取消激活(requires 不满足条件不会导致主题无法激活)。

**Console 需要做适配**
综上,console 应该需要:
- 修改 `Halo 版本要求` 的字段取值,从 *require* -> *requires*
- 提供错误信息展示,让用户知道主题不适配应该升级等错误。

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

#### Special notes for your reviewer:
how to test it?
- 测试安装、升级在 requires 满足条件和不满足时的状况是否符合描述中所述情况。
- 主题重载时加载了一个新的 requires 值触发不满足系统要求条件会在 status 中有错误信息,但不影响主题激活

/cc @halo-dev/sig-halo 
#### Does this PR introduce a user-facing change?

```release-note
主题支持 requires 版本验证,原 Halo 版本要求属性从 require 更名为 requires
```
2023-01-18 07:40:15 +00:00
longjuan cb850a85c9
improve the sorting rules of archives by using reverse year order (#3158)
<!--  Thanks for sending a pull request!  Here are some tips for you:
1. 如果这是你的第一次,请阅读我们的贡献指南:<https://github.com/halo-dev/halo/blob/master/CONTRIBUTING.md>。
1. If this is your first time, please read our contributor guidelines: <https://github.com/halo-dev/halo/blob/master/CONTRIBUTING.md>.
2. 请根据你解决问题的类型为 Pull Request 添加合适的标签。
2. Please label this pull request according to what type of issue you are addressing, especially if this is a release targeted pull request.
3. 请确保你已经添加并运行了适当的测试。
3. Ensure you have added or ran the appropriate tests for your PR.
-->

#### What type of PR is this?
/kind improvement
/area core
<!--
添加其中一个类别:
Add one of the following kinds:

/kind bug
/kind cleanup
/kind documentation
/kind feature
/kind improvement

适当添加其中一个或多个类别(可选):
Optionally add one or more of the following kinds if applicable:

/kind api-change
/kind deprecation
/kind failing-test
/kind flake
/kind regression
-->

#### What this PR does / why we need it:
Display archives in reverse chronological order.
#### Which issue(s) this PR fixes:

<!--
PR 合并时自动关闭 issue。
Automatically closes linked issue when PR is merged.

用法:`Fixes #<issue 号>`,或者 `Fixes (粘贴 issue 完整链接)`
Usage: `Fixes #<issue number>`, or `Fixes (paste link of issue)`.
-->
Fixes https://github.com/halo-dev/halo/issues/3157

#### Special notes for your reviewer:
改进前:
![image](https://user-images.githubusercontent.com/28662535/212591149-68683249-76a4-4cba-8b02-9a58901709ec.png)

改进后:
![image](https://user-images.githubusercontent.com/28662535/212591100-2c155cb7-832f-4c19-96bd-b783810138ce.png)

#### Does this PR introduce a user-facing change?

<!--
如果当前 Pull Request 的修改不会造成用户侧的任何变更,在 `release-note` 代码块儿中填写 `NONE`。
否则请填写用户侧能够理解的 Release Note。如果当前 Pull Request 包含破坏性更新(Break Change),
Release Note 需要以 `action required` 开头。
If no, just write "NONE" in the release-note block below.
If yes, a release note is required:
Enter your extended release note in the block below. If the PR requires additional action from users switching to the new release, include the string "action required".
-->

```release-note
归档以年份降序排序
```
2023-01-17 01:44:14 +00:00
John Niang a81380ef8e
Fix the problem of getting authentication while rendering error page (#3152)
#### What type of PR is this?

/kind bug
/area core
/milestone 2.2.x

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

This PR mainly customizes AnonymousAuthenticationWebFilter and SpringSecurityDialect to make authentication visible in exception web handler. So that we can get SecurityContext while rendering error page.

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

Fixes https://github.com/halo-dev/halo/issues/3133

#### Test steps

1. Start Halo
2. Request a page which is not found
3. See upper right corner icon
    ![image](https://user-images.githubusercontent.com/16865714/212372504-b489507a-2d85-4f1a-a210-9653ad2fa8c2.png)

#### Does this PR introduce a user-facing change?

```release-note
修复错误模板渲染无法获取登录信息的问题
```
2023-01-16 06:10:12 +00:00
vayci e03aa4ef72
feat: update default comment sorter (#3149)
#### What type of PR is this?

/kind feature
/kind improvement

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

Update comments default sorter for console

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

Fixes #3138 

#### Special notes for your reviewer:

#### Does this PR introduce a user-facing change?

```release-note
修改评论列表默认排序规则:依据最后回复时间及评论创建时间进行排序
```
2023-01-16 02:58:13 +00:00
longjuan 575fc95876
improve the sorting rules for themes side posts using publishTime (#3148)
<!--  Thanks for sending a pull request!  Here are some tips for you:
1. 如果这是你的第一次,请阅读我们的贡献指南:<https://github.com/halo-dev/halo/blob/master/CONTRIBUTING.md>。
1. If this is your first time, please read our contributor guidelines: <https://github.com/halo-dev/halo/blob/master/CONTRIBUTING.md>.
2. 请根据你解决问题的类型为 Pull Request 添加合适的标签。
2. Please label this pull request according to what type of issue you are addressing, especially if this is a release targeted pull request.
3. 请确保你已经添加并运行了适当的测试。
3. Ensure you have added or ran the appropriate tests for your PR.
-->

#### What type of PR is this?
/kind improvement
/area core
<!--
添加其中一个类别:
Add one of the following kinds:

/kind bug
/kind cleanup
/kind documentation
/kind feature
/kind improvement

适当添加其中一个或多个类别(可选):
Optionally add one or more of the following kinds if applicable:

/kind api-change
/kind deprecation
/kind failing-test
/kind flake
/kind regression
-->

#### What this PR does / why we need it:
Provide administrators with the ability to adjust the order of articles by modifying the publish time.

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

<!--
PR 合并时自动关闭 issue。
Automatically closes linked issue when PR is merged.

用法:`Fixes #<issue 号>`,或者 `Fixes (粘贴 issue 完整链接)`
Usage: `Fixes #<issue number>`, or `Fixes (paste link of issue)`.
-->
Fixes https://github.com/halo-dev/halo/issues/3143

#### Special notes for your reviewer:
修改前:
![image](https://user-images.githubusercontent.com/28662535/212074405-e0a351fe-9293-4a4f-af9c-41f720512f9b.png)
修改后:
![image](https://user-images.githubusercontent.com/28662535/212074498-1091bb62-700e-4e1f-872a-46687cdbd81c.png)

#### Does this PR introduce a user-facing change?

<!--
如果当前 Pull Request 的修改不会造成用户侧的任何变更,在 `release-note` 代码块儿中填写 `NONE`。
否则请填写用户侧能够理解的 Release Note。如果当前 Pull Request 包含破坏性更新(Break Change),
Release Note 需要以 `action required` 开头。
If no, just write "NONE" in the release-note block below.
If yes, a release note is required:
Enter your extended release note in the block below. If the PR requires additional action from users switching to the new release, include the string "action required".
-->

```release-note
主题侧文章以发布时间排序
```
2023-01-16 02:54:13 +00:00
John Niang d6ff0fd83c
Simplify TemplateEngine due to upgrade of thymeleaf (#3146)
#### What type of PR is this?

/kind improvement
/area core

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

When we [implemented theme mechanism](https://github.com/halo-dev/halo/pull/2280), some problems of thymeleaf came up in front of us, especially TemplateEngine. So we copied full code of SpringTemplateEngine and SpringWebFluxTemplateEngine and made minor changes to adapt our requirements.

Fortunately, issue https://github.com/thymeleaf/thymeleaf/issues/901 I fired has been fixed, and we have a chance to optimize this part of the code.

See https://github.com/halo-dev/halo/issues/3070 for more.

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

Fixes https://github.com/halo-dev/halo/issues/3070

#### Special notes for your reviewer:

Hope reviewers test various endpoints.

#### Does this PR introduce a user-facing change?

```release-note
None
```
2023-01-14 07:22:13 +00:00
guqing 5c29ab5750
feat: support validate requires version for plugin (#3114)
#### What type of PR is this?
/kind feature
/area core
/milestone 2.2.x

#### What this PR does / why we need it:
插件安装和升级支持版本校验

BTW: 此 PR 中 PluginReconciler 有一些异常提示是没有加 i18n 的,主要是考虑 Reconciler 与请求不挂钩,无法获取到 request 上下文的 Locale,如果用 Locale.getDefault() 那么后续用户切换语言时也更改不到已经持久化到数据库中的错误信息,可能得靠客户端翻译异常。

参考文档:
- [semver-expressions-api-ranges](https://github.com/zafarkhaja/jsemver#semver-expressions-api-ranges)
- [integrating-with-actuator.build-info](https://docs.spring.io/spring-boot/docs/current/gradle-plugin/reference/htmlsingle/#integrating-with-actuator.build-info)
- [BuildInfoContributor](https://github.com/spring-projects/spring-boot/blob/v3.0.1/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/info/BuildInfoContributor.java)

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

#### Special notes for your reviewer:
how to test it?
- 开发模式下不会校验插件填写的 requires,但通过接口安装和升级都会统一校验。
- 在 deployment 模式下安装插件和升级插件会根据 halo 的版本校验插件的 spec.requires 是否符合要求,参考 [semver-expressions-api-ranges](https://github.com/zafarkhaja/jsemver#semver-expressions-api-ranges)。
- 如果 spec.requires 为 `*` 则表示允许所有,如果填写为具体的版本号,例如 requires: "2.2.0" 则隐式表示为 `>=2.2.0`。

可以测试这几种情况是否符合期望。

/cc @halo-dev/sig-halo 
#### Does this PR introduce a user-facing change?
```release-note
插件安装和升级支持版本校验
```
2023-01-13 02:50:12 +00:00
John Niang 2a70d59350
Adapt spring.web.resources.cache configuration (#3130)
#### What type of PR is this?

/kind improvement
/area core

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

This PR adapt web properties to control cache of static resources.

Users who want to disable cache can configure like this:

```yaml
spring:
  web:
    resources:
      cache:
        cachecontrol:
          no-cache: true
        use-last-modified: false
```

By default, we have disabled cache in development environment.

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

Fixes https://github.com/halo-dev/halo/issues/3127

#### Does this PR introduce a user-facing change?

```release-note
None
```
2023-01-11 02:38:40 +00:00
guqing 92e57b056b
feat: display unapproved comments created by the current user (#3102)
#### What type of PR is this?
/kind improvement
/area core
/milestone 2.2.x
#### What this PR does / why we need it:
主题端显示当前用户创建的未审核通过的评论/回复

在开启了评论审核功能的前提下:
- 如果非匿名用户在主题端创建的评论或回复必须审核通过才能显示。
- 如果用户登录后评论或回复会被立即展示在列表,但仅限创建者可见,审核通过后对所有人可见。
#### Which issue(s) this PR fixes:

Fixes #2731

#### Special notes for your reviewer:
/cc @halo-dev/sig-halo 
#### Does this PR introduce a user-facing change?
```release-note
主题端支持显示当前用户创建的未审核的评论
```
2023-01-09 08:20:39 +00:00
guqing 64ed793efd
refactor: support extending jar directories for plugin class loader (#3108)
#### What type of PR is this?
/kind improvement
/area core
/milestone 2.2.x

#### What this PR does / why we need it:
修复引入外部依赖的插件以开发模式启动时会出现 NoClassDefFoundError 的问题
see #3107 for more detail.

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

#### Special notes for your reviewer:
how to test it?
以插件 development 模式启动以下两个插件观察是否正常启动:
- https://github.com/halo-sigs/plugin-s3
- https://github.com/halo-sigs/plugin-alioss

期望没有 `Caused by: java. lang. NoClassDefFoundEenon` 错误,且插件正确启动。

/cc @halo-dev/sig-halo 
#### Does this PR introduce a user-facing change?
```release-note
修复引入外部依赖的插件以开发模式启动时会出现 NoClassDefFoundError 的问题
```
2023-01-09 08:16:39 +00:00
guqing 9740de8d4a
feat: add the lastModifyTime attribute for post and single page (#3101)
#### What type of PR is this?
/kind improvement
/milestone 2.2.x

#### What this PR does / why we need it:
文章和自定义页面支持展示最后修改时间
- 文章发布后会同步 post.spec.releasedSnapshot 记录的最后修改时间到 post.status.lastModifyTime,自定义页面亦如是。
- 主题端可以通过 `${item.status.lastModifyTime}` 获取(item表示文章或自定义页面 Vo)。
#### Which issue(s) this PR fixes:

Fixes #3090 

#### Special notes for your reviewer:
/cc @halo-dev/sig-halo 
#### Does this PR introduce a user-facing change?

```release-note
文章和自定义页面支持展示最后修改时间
```
2023-01-05 02:40:36 +00:00
John Niang 4533a83c0a
Refine docker-run command in README.md (#3098)
#### What type of PR is this?

/kind documentation

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

- Use arguments instead of environments.
- Change Docker image halo:2.0 into halo:2.1

#### Does this PR introduce a user-facing change?

```release-note
None
```
2023-01-03 07:34:35 +00:00
John Niang 9676ccee0e
Bump version to 2.2.0-SNAPSHOT for next iteration (#3087)
#### What type of PR is this?

/kind cleanup
/area core

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

Bump version to 2.2.0-SNAPSHOT for next iteration.

#### Does this PR introduce a user-facing change?

```release-note
None
```
2022-12-30 04:52:37 +00:00
Ryan Wang 9245e8e7c9
chore: bump theme-earth to 1.1.1 (#3082)
#### What type of PR is this?

/kind improvement

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

将 theme-earth 默认主题升级到 1.1.1

#### Does this PR introduce a user-facing change?


```release-note
None
```
2022-12-30 02:36:34 +00:00
guqing cc891d6655
feat: add annotations expression object for thymeleaf (#3076)
#### What type of PR is this?
/kind feature
/area core
/milestone 2.1.x
#### What this PR does / why we need it:
新增操作 annotations 的表达式对象
在 thymeleaf 模板中使用示例:
```html
<p th:text="${#annotations.get(user, 'background')}"></p>
<p th:text="${#annotations.getOrDefault(user, 'background', 'default-value')}"></p>
<p th:text="${#annotations.contains(user, 'background')}"></p>
```
#### Which issue(s) this PR fixes:

Fixes #3073

#### Special notes for your reviewer:
/cc @halo-dev/sig-halo 
#### Does this PR introduce a user-facing change?
```release-note
新增 Annotations 表达式对象用于在 thymeleaf 中操作自定义模型的 annotations
```
2022-12-29 13:30:34 +00:00
John Niang 77dd5b24dd
Cache static resources, including plugin, theme, console, attachment (#3074)
#### What type of PR is this?

/kind improvement
/area core
/milestone 2.1.x

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

Add cache control and last modified headers for responses of static resources.

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

Fixes https://github.com/halo-dev/halo/issues/2966

#### Special notes for your reviewer:

We can check the response header of statis resources to know if the cache control is working correctly.

#### Does this PR introduce a user-facing change?

```release-note
完善静态资源的缓存策略
```
2022-12-29 10:14:32 +00:00
guqing 9d0ad5de26
refactor: remove finalizer when resources deleted completely (#3065)
#### What type of PR is this?
/kind improvement
/area core

#### What this PR does / why we need it:
主题卸载时等待删除关联资源后再清除 Finalizer
see #2967 for more detail.
https://github.com/halo-dev/halo/issues/2967#issuecomment-1354384978

#### Which issue(s) this PR fixes:
how to test it?
- 在主题中多添加一个 AnnotationSetting 资源 yaml,测试主题删除是否正常。
- 对包 `org.springframework.retry` 开启 debug 日志后能在删除主题时看到类似如下日志:
```
16:33:02.822 [Test worker] DEBUG org.springframework.retry.support.RetryTemplate - Retry: count=0
16:33:03.128 [Test worker] DEBUG org.springframework.retry.support.RetryTemplate - Checking for rethrow: count=1
```
Fixes #2967
#### Special notes for your reviewer:
/cc @halo-dev/sig-halo 
#### Does this PR introduce a user-facing change?

```release-note
主题卸载时等待删除关联资源后再清除 Finalizer
```
2022-12-29 10:12:36 +00:00
Ryan Wang b667e988df
feat: add target attribute for menu item (#3072)
#### What type of PR is this?

/kind feature

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

为 MenuItem 模型添加 a 标签的 target 属性设置。

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

Fixes https://github.com/halo-dev/halo/issues/3063

#### Special notes for your reviewer:

测试方式请看:https://github.com/halo-dev/console/pull/805

#### Does this PR introduce a user-facing change?

```release-note
菜单项支持设置打开方式
```
2022-12-29 10:10:33 +00:00
guqing 5dbd5a06ed
Avoid NPE problems when querying the list of posts in the console (#3068)
#### What type of PR is this?
/kind improvement
/area core
/milestone 2.1.x

#### What this PR does / why we need it:
迁移后文章过多,当文章的 Reconciler 还没有执行完时访问 Console 端文章列表会因为 post.status  为 Null 出现 NPE 问题
使用文章的 status 时需要对其进行判空

/cherry-pick release-2.0
#### Which issue(s) this PR fixes:

Fixes #3066

#### Special notes for your reviewer:
/cc @halo-dev/sig-halo 
#### Does this PR introduce a user-facing change?

```release-note
None
```
2022-12-29 09:42:33 +00:00
John Niang 313605d52c
Provide an endpoint to update user profile (#3067)
#### What type of PR is this?

/kind feature
/area core
/milestone 2.1.x

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

Provide an endpoint to update current user profile instead of whole user data.

##### Request example

```bash
curl -X 'PUT' \
  'http://localhost:8090/apis/api.console.halo.run/v1alpha1/users/-' \
  -H 'accept: */*' \
  -H 'Content-Type: */*' \
  -d '{
  "spec": {
    "displayName": "JohnNiang",
    "email": "johnniang@halo.run",
    "password": "xxx",
    "registeredAt": "2022-12-19T03:46:54.809770900Z",
    "twoFactorAuthEnabled": false,
    "disabled": false
  },
  "status": {
    "permalink": "http://localhost:8090/authors/admin"
  },
  "apiVersion": "v1alpha1",
  "kind": "User",
  "metadata": {
    "finalizers": [
      "user-protection"
    ],
    "name": "admin",
    "annotations": {
      "rbac.authorization.halo.run/role-names": "[\"super-role\"]"
    },
    "version": 3,
    "creationTimestamp": "2022-12-19T03:46:54.911951800Z"
  }
}'
```

##### Response example

```json
{
  "spec": {
    "displayName": "JohnNiang",
    "email": "johnniang@halo.run",
    "password": "{bcrypt}$2a$10$IBV8/q7Q6Fj78Ls5AG1eBO0bCQ.rM6vli5pAVexf/gqu.hNfjJxaq",
    "registeredAt": "2022-12-19T03:46:54.809770900Z",
    "twoFactorAuthEnabled": false,
    "disabled": false
  },
  "status": {
    "permalink": "http://localhost:8090/authors/admin"
  },
  "apiVersion": "v1alpha1",
  "kind": "User",
  "metadata": {
    "finalizers": [
      "user-protection"
    ],
    "name": "admin",
    "annotations": {
      "rbac.authorization.halo.run/role-names": "[\"super-role\"]"
    },
    "version": 5,
    "creationTimestamp": "2022-12-19T03:46:54.911951800Z"
  }
}
```

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

Fixes https://github.com/halo-dev/halo/issues/3035

#### Does this PR introduce a user-facing change?

```release-note
提供更新当前登录用户信息功能
```
2022-12-29 03:16:33 +00:00
John Niang da55532777
Refine exception detail with i18n (#3042)
#### What type of PR is this?

/kind feature
/kind api-change
/area core
/milestone 2.1.x

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

- Configuring message source location and name enables i18n message resolution.
- Simple global error handler.
- Refactor some exceptions with `ResponseStatusException` to control what HTTP status and problem detail need to be returned.

**TODO**

- [x] Add more UTs.
#### Which issue(s) this PR fixes:

Fixes https://github.com/halo-dev/halo/issues/3020

#### Special notes for your reviewer:

Steps to test:

1. Try to refine `src/main/resources/config/i18n/messages_zh.properties` and switch Browser language with Chinese.
2. Delibrately make a mistake as you wish and see the error tips in console.
3. Try to access one page which doesn't exist and see the rendered result.

#### Does this PR introduce a user-facing change?

```release-note
完成系统异常的国际化
```
2022-12-26 14:10:31 +00:00