Commit Graph

135 Commits (82fb91fc7b31a9f23e71f9dee955b0643b11b769)

Author SHA1 Message Date
guqing 2585636c48
feat: allow users to manage their attachments in uc (#6731)
#### What type of PR is this?
/kind feature
/milestone 2.20.x
/area core

#### What this PR does / why we need it:
支持用户在个人中心管理自己的附件(需要具有对应权限)

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

#### Does this PR introduce a user-facing change?
```release-note
支持用户在个人中心管理自己的附件(需要具有对应权限)
```
2024-10-08 14:56:55 +00:00
John Niang 9829371548
Add Gradle plugin to discover dependency updates (#6761)
#### What type of PR is this?

/kind improvement
/area core
/milestone 2.20.x

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

This PR adds [a Gradle plugin ](https://github.com/ben-manes/gradle-versions-plugin)to discover dependency updates.

```bash
❯ ./gradlew dependencyUpdates -Drevision=release

> Task :api:dependencyUpdates

------------------------------------------------------------
:api Project Dependency Updates (report to plain text file)
------------------------------------------------------------

The following dependencies are using the latest release version:
 - com.github.ben-manes.caffeine:caffeine:3.1.8
 - com.github.java-json-tools:json-patch:1.13
 - com.j256.two-factor-auth:two-factor-auth:1.3
 - io.asyncer:r2dbc-mysql:1.3.0
 - io.github.java-diff-utils:java-diff-utils:4.12
 - io.github.resilience4j:resilience4j-reactor:2.2.0
 - io.github.resilience4j:resilience4j-spring-boot3:2.2.0
 - io.projectreactor:reactor-test:3.7.0-M6
 - io.r2dbc:r2dbc-h2:1.0.0.RELEASE
 - io.seruco.encoding:base62:0.1.3
 - org.apache.commons:commons-lang3:3.17.0
 - org.imgscalr:imgscalr-lib:4.2
 - org.jacoco:org.jacoco.agent:0.8.12
 - org.jacoco:org.jacoco.ant:0.8.12
 - org.mariadb:r2dbc-mariadb:1.2.2
 - org.openapi4j:openapi-schema-validator:1.0.7
 - org.pf4j:pf4j:3.12.0
 - org.postgresql:postgresql:42.7.4
 - org.postgresql:r2dbc-postgresql:1.0.5.RELEASE
 - org.projectlombok:lombok:1.18.30
 - org.springdoc:springdoc-openapi-starter-webflux-ui:2.6.0
 - org.springframework.boot:spring-boot-starter-actuator:3.4.0-M3
 - org.springframework.boot:spring-boot-starter-cache:3.4.0-M3
 - org.springframework.boot:spring-boot-starter-data-jpa:3.4.0-M3
 - org.springframework.boot:spring-boot-starter-data-r2dbc:3.4.0-M3
 - org.springframework.boot:spring-boot-starter-mail:3.4.0-M3
 - org.springframework.boot:spring-boot-starter-security:3.4.0-M3
 - org.springframework.boot:spring-boot-starter-test:3.4.0-M3
 - org.springframework.boot:spring-boot-starter-thymeleaf:3.4.0-M3
 - org.springframework.boot:spring-boot-starter-validation:3.4.0-M3
 - org.springframework.boot:spring-boot-starter-webflux:3.4.0-M3
 - org.springframework.integration:spring-integration-core:6.4.0-M3
 - org.springframework.security:spring-security-oauth2-client:6.4.0-M4
 - org.springframework.security:spring-security-oauth2-jose:6.4.0-M4
 - org.springframework.security:spring-security-oauth2-resource-server:6.4.0-M4
 - org.springframework.security:spring-security-test:6.4.0-M4
 - org.springframework.session:spring-session-core:3.4.0-M2
 - org.thymeleaf.extras:thymeleaf-extras-springsecurity6:3.1.2.RELEASE

The following dependencies have later release versions:
 - com.google.guava:guava [32.0.1-jre -> 33.3.1-jre]
     https://github.com/google/guava
 - net.bytebuddy:byte-buddy [1.15.1 -> 1.15.3]
     https://bytebuddy.net
 - org.apache.lucene:lucene-analysis-common [9.11.1 -> 9.12.0]
     https://lucene.apache.org/
 - org.apache.lucene:lucene-backward-codecs [9.11.1 -> 9.12.0]
     https://lucene.apache.org/
 - org.apache.lucene:lucene-core [9.11.1 -> 9.12.0]
     https://lucene.apache.org/
 - org.apache.lucene:lucene-highlighter [9.11.1 -> 9.12.0]
     https://lucene.apache.org/
 - org.apache.lucene:lucene-queryparser [9.11.1 -> 9.12.0]
     https://lucene.apache.org/
 - org.apache.tika:tika-core [2.9.2 -> 3.0.0-BETA2]
     https://tika.apache.org/
 - org.jsoup:jsoup [1.15.3 -> 1.18.1]
     https://jsoup.org/

Gradle release-candidate updates:
 - Gradle: [8.10.2: UP-TO-DATE]

Generated report file build/dependencyUpdates/report.txt

> Task :application:dependencyUpdates

------------------------------------------------------------
:application Project Dependency Updates (report to plain text file)
------------------------------------------------------------

The following dependencies are using the latest release version:
 - com.puppycrawl.tools:checkstyle:9.3
 - io.projectreactor:reactor-test:3.7.0-M6
 - org.jacoco:org.jacoco.agent:0.8.12
 - org.jacoco:org.jacoco.ant:0.8.12
 - org.springframework:spring-context-indexer:6.2.0-RC1
 - org.springframework.boot:spring-boot-configuration-processor:3.4.0-M3
 - org.springframework.boot:spring-boot-starter-test:3.4.0-M3
 - org.springframework.security:spring-security-test:6.4.0-M4
 - org.webjars.npm:jsencrypt:3.3.2
 - org.webjars.npm:normalize.css:8.0.1

The following dependencies have later release versions:
 - org.projectlombok:lombok [1.18.30 -> 1.18.34]
     https://projectlombok.org

Gradle release-candidate updates:
 - Gradle: [8.10.2: UP-TO-DATE]

Generated report file build/dependencyUpdates/report.txt

Deprecated Gradle features were used in this build, making it incompatible with Gradle 9.0.

You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.

For more on this, please refer to https://docs.gradle.org/8.10.2/userguide/command_line_interface.html#sec:command_line_warnings in the Gradle documentation.

BUILD SUCCESSFUL in 1s
9 actionable tasks: 2 executed, 7 up-to-date
```

#### 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
None
```
2024-10-04 11:46:43 +00:00
John Niang 8a9b954969
Support unbinding OAuth2User from Halo side (#6734)
#### What type of PR is this?

/kind feature
/area core
/milestone 2.20.x

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

This PR provides an endpoint for disconnecting user connection. After the user connection is disconnected, an event `UserConnectionDisconnectedEvent` will be published for plugins.

Now, OAuth2 plugin can simplify the authentication, binding  and unbinding logic, please see the AuthProvider configuration snippet below:

```diff
spec:
  authenticationUrl: /oauth2/authorization/github
- bindingUrl: /apis/api.plugin.halo.run/v1alpha1/plugins/plugin-oauth2/connect/github
+ bindingUrl: /oauth2/authorization/github
- unbindUrl: /apis/api.plugin.halo.run/v1alpha1/plugins/plugin-oauth2/disconnect/github
+ unbindUrl: /apis/uc.api.auth.halo.run/v1alpha1/user-connections/github/disconnect
```

Please note that, OAuth2 plugin can also define binding and unbinding endpoints by self.

#### Special notes for your reviewer:

OAuth2 test plugin: 
[plugin-oauth2-1.0.4-SNAPSHOT.zip](https://github.com/user-attachments/files/17184215/plugin-oauth2-1.0.4-SNAPSHOT.zip)

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

```release-note
None
```
2024-09-30 10:31:53 +00:00
John Niang e77954313d
Support binding OAuth2 user automatically (#6702)
#### What type of PR is this?

/kind improvement
/area core
/milestone 2.20.x

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

This PR add support for binding OAuth2 user automatically. So we can remove the user-binding page.

Please note that those changes may break the OAuth2 and SocialLogin plugins.

#### Special notes for your reviewer:

Build OAuth2 plugin from <https://github.com/halo-sigs/plugin-oauth2/pull/64> or use [plugin-oauth2-1.0.4-SNAPSHOT.zip](https://github.com/user-attachments/files/17177592/plugin-oauth2-1.0.4-SNAPSHOT.zip) I built.

- Bind after logging in

1. Log in Halo with username and password method
2. Try to unbind OAuth2 user
3. Bind OAuth2 user again

- Initially bind without logging in

1. Go to login page
2. Log in with OAuth2 method and you will be redirected to login page
3. Log in with username and password method
4. See the result of binding

- Log in with OAuth2 method after binding

1. Go  to login page
2. Log in with OAuth2 method and you will be redirected to uc page directly

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

```release-note
支持自动绑定 OAuth2 登录用户
```
2024-09-29 10:19:47 +00:00
JohnNiang 1f9610686b Add backend support for customizing login and logout pages
Signed-off-by: JohnNiang <johnniang@foxmail.com>
2024-09-28 17:37:36 +08:00
John Niang 07077f7d0c
Provide ElementTagProcessor to handle element tag in plugin (#6670)
#### What type of PR is this?

/kind feature
/area plugin

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

This PR provides an interface ElementTagProcessor to make plugin handle element tag easily. e.g.:

```java
public class ImgTagProcessor implements ElementTagPostProcessor {

    @Override
    public Mono<Void> process(ITemplateContext context, IProcessableElementTag tag,
        IElementTagStructureHandler structureHandler) {
        var elementName = tag.getElementDefinition().getElementName();
        if (!Objects.equals("img", elementName.getElementName())) {
            return Mono.empty();
        }
        var srcAttr = tag.getAttribute("src");
        if (srcAttr == null) {
            return Mono.empty();
        }
        var newSrc = srcAttr.getValue();
        // TODO rewrite src
        structureHandler.setAttribute("src", newSrc);
        return Mono.empty();
    }
    
}
```

After PR merged, plugins https://github.com/webp-sh/halo-plugin-webp-cloud and https://github.com/guqing/plugin-cloudinary can be refined with new method.

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

```release-note
支持在插件中操作渲染结果
```
2024-09-19 02:56:53 +00:00
guqing 07d200b45b
Trigger attachment status update on storage policy config change (#6639) 2024-09-12 17:13:19 +08:00
John Niang a36822c861
Expose CryptoService and RateLimiterRegistry to plugins (#6638)
#### What type of PR is this?

/kind feature
/area core
/area plugin
/milestone 2.20.x

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

Currently, we are refactoring login and logout pages to make them extensible. If plugins want to realize a new authentication method, the CryptoService and RateLimiterRegistry may be used to authenticate.

So this PR exposes the two beans to plugins. No side effect will be introduced.

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

```release-note
【开发相关】允许在插件使用 CryptoService 和 RateLimiterRegistry
```
2024-09-12 02:34:20 +00:00
guqing ba49dcab35
refactor: optimize key comparator for indicates key sort (#6555)
#### What type of PR is this?
/kind improvement
/area core
/milestone 2.19.x

#### What this PR does / why we need it:
重构 KeyComparator 并通过更多的测试用例来确保排序功能的正确性

同时修复了可能存在溢出导致比较结果不正确的问题,目前:
1. 字符串长度比较:在 compareStrings 方法中,字符串的长度比较使用 Integer.compare,这部分代码不会产生整数溢出问题。
2. 数字部分的比较:在 compareNumbers 方法中,数字的比较是基于字符比较的(即逐位比较每个数字字符),没有涉及到将数3. 字字符串转化为 int 或 long 类型的操作,所以不会存在整数溢出问题。
4. 处理小数部分的比较:在 compareDecimalNumbers 方法中,类似地,比较操作也是基于字符的,不涉及到数值转换,因此也不存在整数溢出问题

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

#### Does this PR introduce a user-facing change?
```release-note
修复由于索引比较时可能出现整数溢出导致文章偶尔无法访问的问题
```
2024-08-30 09:39:28 +00:00
John Niang f61f846a7f
Cleanup code with SortableRequest (#6540)
#### What type of PR is this?

/kind cleanup
/kind improvement
/area core
/milestone 2.19.0

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

This PR refactors some requests with sort parameter by reusing SortableRequest, and refactors some queries with indexer.

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

```release-note
None
```
2024-08-29 02:39:24 +00:00
guqing ef37aa794b
feat: implement new mechanisms for generating and managing attachment thumbnails (#6454)
#### What type of PR is this?
/kind feature
/area core
/milestone 2.19.x

#### What this PR does / why we need it:
实现了图片类型的附件缩略图生成和管理的新机制

实现依据 RFC:https://github.com/halo-dev/rfcs/pull/24

使用缩略图前需要配置 externalUrl 才能生成

**How to test it?**
1. 测试本地缩略图的文件是否正确,每个图片对应到相应 size 的目录如 thumbnails/w400 应该是一对一
2. 每个图片生成缩略图的只会在 `http://localhost:8090/apis/storage.halo.run/v1alpha1/thumbnails` 中存在一份记录
3. 测试删除附件会删除对应的缩略图文件和 [thumbnails](http://localhost:8090/apis/storage.halo.run/v1alpha1/thumbnails) 
记录
4. 修改 externalUrl 以上功能均不会受到影响

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

#### Does this PR introduce a user-facing change?
```release-note
附件图片支持生成多尺寸图片,文章支持响应式图片。
```
2024-08-26 10:27:14 +00:00
Takagi e5bbbb3b7b
feat: API to save external links as attachments (#6364)
#### What type of PR is this?

/kind api-change
/kind feature
/area core

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

see #2335 

增加将第三方资源转存为附件资源的接口。

`/apis/api.console.halo.run/v1alpha1/attachments/-/upload-from-url`

UC:

`/apis/uc.api.content.halo.run/v1alpha1/attachments/-/upload-from-url`

其中参数为

```json
{
  "url": "string",
  "filename": "string",
  "groupName": "string",
  "policyName": "string"
}
```

#### How to test it?

测试能否将第三方接口的资源保存至附件中。
测试各类附件,例如图片、视频、文本等。

#### Does this PR introduce a user-facing change?
```release-note
增加通过链接转存第三方资源至附件库的接口
```
2024-08-26 06:31:14 +00:00
John Niang 3a782be607
Fix the problem that roles could not be granted sometimes (#6471)
#### What type of PR is this?

/kind improvement
/area core

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

This PR refactors searching roles by using index mechanism to speed up every request and fix the problem of not being able to grant roles to users sometimes.

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

Fixes #5807 
Fixes https://github.com/halo-dev/halo/issues/4954
Fixes https://github.com/halo-dev/halo/issues/5057

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

```release-note
修复有时无法给用户赋权限的问题
```
2024-08-21 03:22:50 +00:00
John Niang 40386557a7
Support filtering search result by types, ownerNames, categoryNames and tagNames (#6442)
#### What type of PR is this?

/kind improvement
/area core

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

This PR allows users to filter search result by types, owner names, category names and tag names.

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

```release-note
完善搜索引擎过滤功能
```
2024-08-08 04:58:37 +00:00
guqing 58fe872844
feat: add file size and type restriction for local file uploads (#6390)
#### What type of PR is this?
/kind feature
/area core

#### What this PR does / why we need it:
本次 PR 为本地附件存储策略增加了对上传单文件大小和文件类型限制的功能,具体包括:

1. 单文件大小限制:
实现了对单个文件上传大小的验证功能,确保上传文件不超过设定的最大值。
2. 文件类型限制:
添加了文件类型限制功能,使用 Apache Tika 读取上传文件的 magic numbers 得到文件 mime type 并根据用户配置来决定是否允许上传

参考链接:
- [List of file signatures](https://en.wikipedia.org/wiki/List_of_file_signatures)
- [File Magic Numbers: The Easy way to Identify File Extensions](https://library.mosse-institute.com/articles/2022/04/file-magic-numbers-the-easy-way-to-identify-file-extensions/file-magic-numbers-the-easy-way-to-identify-file-extensions.html)

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

#### Does this PR introduce a user-facing change?
```release-note
为本地附件存储策略增加了对上传单文件大小和文件类型限制的功能
```
2024-08-01 01:58:12 +00:00
guqing 39ff455178
feat: add extension point for excerpt generation (#6348)
#### What type of PR is this?
/kind feature
/area core
/milestone 2.18.x

#### What this PR does / why we need it:
新增文章摘要生成扩展点用于扩展自动生成摘要的方式

#### Does this PR introduce a user-facing change?
```release-note
新增文章摘要生成扩展点用于扩展自动生成摘要的方式
```
2024-07-31 09:22:04 +00:00
guqing 687de1c550
chore: compatibility for deprecated buildParametersFromType method with deprecation log (#6379)
#### What type of PR is this?
/kind improvement
/area core
/milestone 2.18.x

#### What this PR does / why we need it:
在 https://github.com/halo-dev/halo/pull/6244 中移除了过时的 `QueryParamBuildUtil.buildParametersFromType` 方法,但是由于留给插件适配的时间不够,很多官方提供的插件也要和 2.18 一起发版这样会导致使用了此方法的插件无法启动,因此留下方法声明并输出日志等到后续版本在删除,这样可以给出一些时间给用户先升级插件而不是挂掉。

#### Does this PR introduce a user-facing change?
```release-note
None
```
2024-07-25 09:01:38 +00:00
Takagi 1d3ba46a14
feat: share ExtensionGetter Bean with plugins for extension retrieval (#6365)
#### What type of PR is this?

/kind improvement
/area core
/milestone 2.18.x

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

通过将 ExtensionGetter Bean 共享到给插件的 ApplicationContext,插件能够方便地使用该 Bean 来获取扩展。此更改确保插件具有可靠的扩展访问方式,从而促进系统内更好的模块化和可扩展性。

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

Fixes #6357 

#### Does this PR introduce a user-facing change?
```release-note
将 ExtensionGetter Bean 共享给插件使用,以便插件可以通过它来获取扩展
```
2024-07-25 03:01:36 +00:00
John Niang 9cdd8a5301
Add before and after security web filters (#6297)
#### What type of PR is this?

/kind feature
/kind api-change
/area core
/area plugin

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

This PR adds `BeforeSecurityWebFilter` and `AfterSecurityWebFilter` extension points. See https://github.com/halo-sigs/plugin-page-cache/issues/4#issuecomment-2216677891 for more.

Now, we can do something before and after authenticating.

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

```release-note
添加认证授权的前置和后置处理器扩展点
```
2024-07-09 14:05:24 +00:00
guqing 104bd3e44e
chore: mark deprecated constructor for base plugin (#6277)
#### What type of PR is this?
/milestone 2.18.x

#### What this PR does / why we need it:
将 BasePlugin 的 PluginWrapper 构造函数标记为过时并输出警告日志提示

#### Does this PR introduce a user-facing change?
```release-note
在 BasePlugin 的 PluginWrapper 构造函数输出过时警告日志以提醒开发者尽快适配
```
2024-07-05 10:05:07 +00:00
guqing 138d52e731
chore: keep the pluginWrapper bean for compatibility (#6271)
#### What type of PR is this?
/area core
/milestone 2.18.x

#### What this PR does / why we need it:
为了平滑升级先保留 PluginWrapper 的 Bean

#### Does this PR introduce a user-facing change?
```release-note
None
```
2024-07-05 04:08:37 +00:00
John Niang ad66247872
Support obtaining plugins root in plugins (#6269)
#### What type of PR is this?

/kind feature
/kind api-change
/area core
/area plugin

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

This PR supports obtaining plugins root in plugins. Below is an example in plugin:

```java
@Component
class PluginsRootGetterDemo {

    private final PluginsRootGetter pluginsRootGetter;

    PluginsRootGetterDemo(PluginsRootGetter pluginsRootGetter) {
        this.pluginsRootGetter = pluginsRootGetter;
    }

}
```

Meanwhile, I remove the `PluginProperties#pluginsRoot` for a clear way to obtain plugins root.

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

```release-note
支持在插件中获取插件根目录
```
2024-07-04 13:36:33 +00:00
guqing b964c7bb00
chore: cleanup deprecated constructor for base plugin (#6243)
#### What type of PR is this?
/kind cleanup
/area plugin
/milestone 2.17.x

#### What this PR does / why we need it:
移除 BasePlugin 中已经过时的构造方法

在 2.6.1 版本中将 `BasePlugin(PluginWrapper wrapper)` 标记为过时并使用 `BasePlugin(PluginContext pluginContext)` 代替,现在已经过了很多版本,是时候移除它了。

see also #4023
#### Does this PR introduce a user-facing change?
```release-note
开发者相关:移除 BasePlugin 中已经过时的构造方法
```
2024-07-03 03:49:34 +00:00
guqing 3dadd07986
chore: cleanup buildParametersFromType for QueryParamBuildUtil (#6244)
#### What type of PR is this?
/kind cleanup
/area core
/milestone 2.18.x

#### What this PR does / why we need it:
移除 `QueryParamBuildUtil.buildParametersFromType` 方法使用手动构建代替,参考:
f5ebd9fe43/application/src/main/java/run/halo/app/content/PostQuery.java (L135)

#### Does this PR introduce a user-facing change?
```release-note
移除 `QueryParamBuildUtil.buildParametersFromType` 方法使用手动构建代替
```
2024-07-03 02:51:29 +00:00
guqing f5ebd9fe43
feat: add TemplateFooterProcessor extension point for extending footer tag content in theme (#6191)
#### What type of PR is this?
/kind feature
/area core
/milestone 2.17.x

#### What this PR does / why we need it:
提供对模板中 halo footer 标签内容的扩展点以支持扩展页脚内容

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

#### Does this PR introduce a user-facing change?
```release-note
提供对模板中 halo footer 标签内容的扩展点以支持扩展页脚内容
```
2024-07-01 09:49:17 +00:00
John Niang 4ea4bdf8b5
Expose search service for plugin (#6239)
#### What type of PR is this?

/kind feature
/kind api-change
/area core
/area plugin
/milestone 2.17.0

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

This PR creates a SearchService and makes it invokable for plugins.

#### Special notes for your reviewer:

1. Create a plugin
2. Publish all publication into Maven local repository by executing `./gradlew publishAllPublicationsToMavenLocalRepository`
3. Use `2.17.0-SNAPSHOT` as dependency version and refresh dependencies
4. Try to use the SearchService to search something.

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

```release-note
为插件提供全文搜索服务
```
2024-07-01 09:11:17 +00:00
John Niang 3875251d97
Allow plugin to listen the event the plugin has started (#6234)
#### What type of PR is this?

/kind feature
/area core
/milestone 2.17.x

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

This PR add support for allowing plugin to listen the event that the plugin has started. Below is an example of listening the event in plugin:

```java
    @EventListener
    void onPluginStartedEvent(PluginStartedEvent event) {
        // do something.
    }
```

See https://github.com/halo-dev/halo/issues/5339#issuecomment-2199220068 for more.

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

Fixes https://github.com/halo-dev/halo/issues/5339#issuecomment-2199220068

#### Special notes for your reviewer:

1. Create a plugin, add the listener above and write some logs
2. Build and install the plugin
3. Start plugin and see the logs you wrote

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

```release-note
支持在插件中监听已启动事件
```
2024-07-01 07:31:17 +00:00
guqing 967eaa21e1
feat: add LoginHandlerEnhancer for enhanced login processing (#6176)
#### What type of PR is this?
/kind improvement
/area core
/milestone 2.17.x

#### What this PR does / why we need it:
新增 LoginHandlerEnhancer 用于 Halo 扩展登录成功或失败后的处理逻辑如 RememberMe 和设备管理等

#### Does this PR introduce a user-facing change?
```release-note
None
```
2024-07-01 06:49:16 +00:00
Ryan Wang ceb97458d4
fix: correct the kind definition in the Device extension (#6222)
#### What type of PR is this?

/area core
/kind bug
/milestone 2.17.x

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

修复 Device 模型中,Kind 定义错误的问题。

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

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

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

```release-note
None 
```
2024-07-01 03:05:16 +00:00
Ryan Wang f0445f4e51
refactor: remove page cache feature (#6108)
#### What type of PR is this?

/area core
/kind api-change
/milestone 2.17.x

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

移除内置的页面静态缓存功能,后续将由 https://github.com/halo-sigs/plugin-page-cache 插件提供。

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

Fixes #5639 

#### Special notes for your reviewer:

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

```release-note
移除内置的页面静态缓存功能,后续由 https://github.com/halo-sigs/plugin-page-cache 插件提供。
```
2024-06-28 10:08:59 +00:00
John Niang 632bb69dfe
Refactor search engine and improve document extensibility (#6082)
#### What type of PR is this?

/kind improvement
/kind api-change
/area core

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

See https://github.com/JohnNiang/halo/blob/refactor/search/docs/extension-points/search-engine.md for more

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

Fixes https://github.com/halo-dev/halo/issues/5202
Fixes https://github.com/halo-dev/halo/issues/5339
Fixes https://github.com/halo-dev/halo/issues/5613
Fixes https://github.com/halo-dev/halo/issues/5172
Fixes https://github.com/halo-dev/halo/issues/4796
Fixes https://github.com/halo-dev/halo/issues/5625
Fixes https://github.com/halo-dev/halo/issues/5805

#### Special notes for your reviewer:

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

```release-note
重构搜索引擎并提高可扩展性。
```
2024-06-26 15:22:51 +00:00
Ryan Wang bc1033611e Refine UI for categories hiden 2024-06-26 19:25:10 +08:00
guqing 68d428aa29
refactor: enhance cache management in plugin setting config (#6141)
#### What type of PR is this?
/kind feature
/area plugin
/area core
/milestone 2.17.x

#### What this PR does / why we need it:
增强插件配置的缓存管理

1. 通过 SettingFetcher/ReactiveSettingFetcher 获取插件配置可以不在考虑获取数据的性能问题,当数据变更后会自动更新缓存
2. 现在你可以通过在插件中监听 `PluginConfigUpdatedEvent` 事件来做一些处理,它会在用户更改插件配置后被触发

#### Does this PR introduce a user-facing change?
```release-note
增强插件配置的缓存管理并支持通过监听 `PluginConfigUpdatedEvent` 事件做一些特殊处理
```
2024-06-26 11:20:51 +00:00
Ryan Wang 2c9d94f034 Refine UI for device managment 2024-06-26 18:53:24 +08:00
guqing ae6724a2b6
feat: implement persistent token based remember me mechanism (#6131)
#### What type of PR is this?
/kind feature
/area core
/milestone 2.17.x

#### What this PR does / why we need it:
新增基于持久化 Token 的 RememberMe 机制

本次更新引入了一种新的 RememberMe 机制,该机制基于持久化 Token,以增强安全性和管理灵活性。在此之前,RememberMe 功能通过以下方式生成 Token,并将其作为 cookie 发送回客户端:
```
 username + ":" + expiryTime + ":" + algorithmName + ":"
   + algorithmHex(username + ":" + expiryTime + ":" + password + ":" + key)
```
此方法的优点在于无需存储 Token 就可以进行验证,并且用户密码的更改会自动使 Token 失效。然而,它的主要缺点是缺乏管理能力,例如无法手动撤销 Token。

鉴于最新的设备管理需求(见 PR #6100),我们需要一种支持设备撤销(revoke)的机制。因此,我们采用了持久化 Token 的方式,并通过随机生成的方法来提高安全性,而不将用户名和密码直接签名在 Token 中。新的 Token 格式如下:
```
base64(tokenValue:series)
```
此更改将为系统带来更高的安全保障和更灵活的管理选项,特别是在需要高度控制和监管设备访问时。

#### Does this PR introduce a user-facing change?
```release-note
引入基于持久化 Token 的新 RememberMe 机制以增强安全性和管理灵活性,升级后需要重新登录
```
2024-06-26 08:40:49 +00:00
guqing 3f94cfc9a8
refactor: add list options for sync all synchronizer (#6145)
#### What type of PR is this?
/kind improvement
/area core
/milestone 2.17.x

#### What this PR does / why we need it:
为启动时同步添加 ListOptions 选项为后续保持 ExtensionMatcher 的纯粹做准备,后续将移除 ExtensionMatcher 中多余的方法声明,只保留 match 方法,最终的结果希望是
```java
@FunctionalInterface
public interface ExtensionMatcher {
    boolean match(Extension extension);
}
```
以前构建 Controller 的写法
```java
public Controller setupWith(ControllerBuilder builder) {
         return builder
            .extension(new Post())
            .onAddMatcher(DefaultExtensionMatcher.builder(client, Post.GVK)
                .fieldSelector(FieldSelector.of(
                    equal(Post.REQUIRE_SYNC_ON_STARTUP_INDEX_NAME, TRUE))
                )
                .build()
            )
           .build();
}
```
现在的写法
```java
public Controller setupWith(ControllerBuilder builder) {
        var post = new Post();
        return builder
            .extension(post)
            // 当有新数据添加时
            .onAddMatcher(extension -> "fake-post".equals(extension.getMetadata().getName()))
            // 使用 syncAllListOptions 作为启动时同步的查询条件过滤不需要的数据
            .syncAllListOptions(ListOptions.builder()
                .fieldQuery(equal(Post.REQUIRE_SYNC_ON_STARTUP_INDEX_NAME, TRUE))
                .build()
            )
            .build();
    }
```

#### Does this PR introduce a user-facing change?
```release-note
开发者相关:重构 ControllerBuilder 的匹配条件并增加 syncAllListOptions 作为启动时同步的查询条件
```
2024-06-26 06:50:50 +00:00
guqing 50f751dda2
refactor: add builder for list options (#6148)
#### What type of PR is this?
/kind improvement
/area core
/milestone 2.17.x

#### What this PR does / why we need it:
为 ListOptions 增加 Builder 以方便构建 ListOptions 对象,可以通过以下形式创建
```java
var listOptions = ListOptions.builder()
                .labelSelector()// 构建 LabelSelector
                .eq("key-1", "value-1")
                .notEq("key-2", "value-1")
                .exists("key-3")
                .end()// 结束构建 LabelSelector
                .fieldQuery(equal("spec.title", "fake-title"))  // 构建 FieldSelector
                .andQuery(equal("spec.slug", "fake-slug"))
                .orQuery(equal("spec.slug", "test"))
                .build();
```

#### Does this PR introduce a user-facing change?
```release-note
开发者相关:支持通过 Builder 来简化 ListOptions 的构建
```
2024-06-26 06:44:49 +00:00
John Niang e4cce918f7
Refactor ExtensionGetter for enabling or disabling extensions (#6134)
#### What type of PR is this?

/kind improvement
/kind api-change
/area core

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

This PR refactors ExtensionGetter implementation to add a support of enabling extension point(s). Here is an example of data field of `system` config map:

```json
{
  "data": {
    "extensionPointEnabled": "{  \"search-engine\": [\"search-engine-algolia\"]}"
  },
```

> 1. The `search-engine` is a name of extension point definition.
> 2. The `search-engine-algolia` is a name of extension definition.

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

```release-note
None
```
2024-06-25 07:46:45 +00:00
guqing c10862d6fe
refactor: index mechanism to enhance overall performance (#6039)
#### What type of PR is this?
/kind improvement
/area core
/milestone 2.17.x

#### What this PR does / why we need it:
重构索引机制的查询和排序以提升整体性能

**how to test it?**
使用 postgre 数据库,初始化 Halo ,然后执行以下脚本创建 30w 文章数据进行测试:
<details>
<summary>点击展开查看 SQL</summary>

```sql
DO $$
DECLARE
    i integer;
    postNameIndex integer;
    snapshotName varchar;
    totalRecords integer;
BEGIN
    postNameIndex := 1;
    totalRecords := 300000;

    FOR i IN 1..3 LOOP
      INSERT INTO "public"."extensions" ("name", "data", "version")
      VALUES (
          '/registry/content.halo.run/categories/category-'||i,
          convert_to(
              jsonb_build_object(
                  'spec', jsonb_build_object(
                      'displayName', '分类-'||i,
                      'slug', 'category-'||i,
                      'description', '测试分类',
                      'cover', '',
                      'template', '',
                      'priority', 0,
                      'children', '[]'::jsonb
                  ),
                  'status', jsonb_build_object(
                      'permalink', '/categories/category-'||i,
                      'postCount', totalRecords,
                      'visiblePostCount', totalRecords
                  ),
                  'apiVersion', 'content.halo.run/v1alpha1',
                  'kind', 'Category',
                  'metadata', jsonb_build_object(
                      'finalizers', jsonb_build_array('category-protection'),
                      'name', 'category-' || i,
                      'annotations', jsonb_build_object(
                          'content.halo.run/permalink-pattern', 'categories'
                      ),
                      'version', 0,
                      'creationTimestamp', '2024-06-12T03:56:40.315592Z'
                  )
          )::text, 'UTF8'),
          0
      );
    END LOOP;


    FOR i IN 1..3 LOOP
      INSERT INTO "public"."extensions" ("name", "data", "version")
        VALUES (
            '/registry/content.halo.run/tags/tag-' || i,
            convert_to(
               jsonb_build_object(
               'spec', jsonb_build_object(
                   'displayName', 'Halo tag ' || i,
                   'slug', 'tag-'||i,
                   'color', '#ffffff',
                   'cover', ''
               ),
               'status', jsonb_build_object(
                   'permalink', '/tags/tag-' || i,
                   'visiblePostCount', totalRecords,
                   'postCount', totalRecords,
                   'observedVersion', 0
               ),
               'apiVersion', 'content.halo.run/v1alpha1',
               'kind', 'Tag',
               'metadata', jsonb_build_object(
                   'finalizers', jsonb_build_array('tag-protection'),
                   'name', 'tag-'||i,
                   'annotations', jsonb_build_object(
                       'content.halo.run/permalink-pattern', 'tags'
                   ),
                   'version', 0,
                   'creationTimestamp', '2024-06-12T03:56:40.406407Z'
               )
       )::text, 'UTF8'),
       0);
    END LOOP;

    FOR i IN postNameIndex..totalRecords LOOP
        -- Generate snapshotName
        snapshotName := 'snapshot-' || i;

        -- Insert post data
        INSERT INTO "public"."extensions" ("name", "data", "version")
        VALUES (
            '/registry/content.halo.run/posts/post-' || postNameIndex,
            convert_to(
                jsonb_build_object(
                    'spec', jsonb_build_object(
                        'title', 'title-' || postNameIndex,
                        'slug', 'slug-' || postNameIndex,
                        'releaseSnapshot', snapshotName,
                        'headSnapshot', snapshotName,
                        'baseSnapshot', snapshotName,
                        'owner', 'admin',
                        'template', '',
                        'cover', '',
                        'deleted', false,
                        'publish', true,
                        'pinned', false,
                        'allowComment', true,
                        'visible', 'PUBLIC',
                        'priority', 0,
                        'excerpt', jsonb_build_object(
                            'autoGenerate', true,
                            'raw', ''
                        ),
                        'categories', ARRAY['category-kEvDb', 'category-XcRVk', 'category-adca'],
                        'tags', ARRAY['tag-RtKos', 'tag-vEsTR', 'tag-UBKCc'],
                        'htmlMetas', '[]'::jsonb
                    ),
                    'status', jsonb_build_object(
                        'phase', 'PUBLISHED',
                        'conditions', ARRAY[
                            jsonb_build_object(
                                'type', 'PUBLISHED',
                                'status', 'TRUE',
                                'lastTransitionTime', '2024-06-11T10:16:15.617748Z',
                                'message', 'Post published successfully.',
                                'reason', 'Published'
                            ),
                            jsonb_build_object(
                                'type', 'DRAFT',
                                'status', 'TRUE',
                                'lastTransitionTime', '2024-06-11T10:16:15.457668Z',
                                'message', 'Drafted post successfully.',
                                'reason', 'DraftedSuccessfully'
                            )
                        ],
                        'permalink', '/archives/slug-' || postNameIndex,
                        'excerpt', '如果你看到了这一篇文章,那么证明你已经安装成功了,感谢使用 Halo 进行创作,希望能够使用愉快。',
                        'inProgress', false,
                        'contributors', ARRAY['admin'],
                        'lastModifyTime', '2024-06-11T10:16:15.421467Z',
                        'observedVersion', 0
                    ),
                    'apiVersion', 'content.halo.run/v1alpha1',
                    'kind', 'Post',
                    'metadata', jsonb_build_object(
                        'finalizers', ARRAY['post-protection'],
                        'name', 'post-' || postNameIndex,
                        'labels', jsonb_build_object(
                            'content.halo.run/published', 'true',
                            'content.halo.run/deleted', 'false',
                            'content.halo.run/owner', 'admin',
                            'content.halo.run/visible', 'PUBLIC',
                            'content.halo.run/archive-year', '2024',
                            'content.halo.run/archive-month', '06',
                            'content.halo.run/archive-day', '11'
                        ),
                        'annotations', jsonb_build_object(
                            'content.halo.run/permalink-pattern', '/archives/{slug}',
                            'content.halo.run/last-released-snapshot', snapshotName,
                            'checksum/config', '73e40d4115f5a7d1e74fcc9228861c53d2ef60468e1e606e367b01efef339309'
                        ),
                        'version', 0,
                        'creationTimestamp', '2024-06-11T05:51:46.059292Z'
                    )
                )::text, 'UTF8'),
            1
        );

        -- Insert content data
        INSERT INTO "public"."extensions" ("name", "data", "version")
        VALUES (
            '/registry/content.halo.run/snapshots/' || snapshotName,
            convert_to(
                jsonb_build_object(
                    'spec', jsonb_build_object(
                        'subjectRef', jsonb_build_object(
                            'group', 'content.halo.run',
                            'version', 'v1alpha1',
                            'kind', 'Post',
                            'name', 'post-' || postNameIndex
                        ),
                        'rawType', 'HTML',
                        'rawPatch', '<p style=\"\">测试内容</p>',
                        'contentPatch', '<p style=\"\">测试内容</p>',
                        'lastModifyTime', '2024-06-11T06:01:25.748755Z',
                        'owner', 'admin',
                        'contributors', ARRAY['admin']
                    ),
                    'apiVersion', 'content.halo.run/v1alpha1',
                    'kind', 'Snapshot',
                    'metadata', jsonb_build_object(
                        'name', snapshotName,
                        'annotations', jsonb_build_object(
                            'content.halo.run/keep-raw', 'true'
                        ),
                        'creationTimestamp', '2024-06-11T06:01:25.748925Z'
                    )
                )::text, 'UTF8'),
            1
        );

        postNameIndex := postNameIndex + 1;
    END LOOP;
END $$;
```

</details>

使用以下 API 查询文章
```
curl 'http://localhost:8090/apis/api.console.halo.run/v1alpha1/posts?page=1&size=20&labelSelector=content.halo.run%2Fdeleted%3Dfalse&labelSelector=content.halo.run%2Fpublished%3Dtrue&fieldSelector=spec.categories%3Dcategory-1&fieldSelector=spec.tags%3Dc33ceabb-d8f1-4711-8991-bb8f5c92ad7c&fieldSelector=status.contributors%3Dadmin&fieldSelector=spec.visible%3DPUBLIC' \
--header 'Authorization: Basic YWRtaW46YWRtaW4='
```
Before:

![SCR-20240612-o20](https://github.com/halo-dev/halo/assets/38999863/fc27a265-6571-4361-a707-a683ea040837)
After:

![SCR-20240612-q1c](https://github.com/halo-dev/halo/assets/38999863/c0a241b8-5ed4-4973-8dfc-c260ffccd727)

#### Does this PR introduce a user-facing change?
```release-note
重构索引机制的查询和排序使整体性能提升 50% 以上
```
2024-06-21 08:04:11 +00:00
guqing 8bdde317e5
feat: add preventParentPostCascadeQuery option to control visibility of child category posts (#6083)
#### What type of PR is this?
/kind feature
/area core
/milestone 2.17.x

#### What this PR does / why we need it:
此次变更为文章分类引入了一个新的 `preventParentPostCascadeQuery` 布尔属性,用于控制分类及其子分类下的文章显示方式。具体变更包括:

- 在分类结构中增加了 `preventParentPostCascadeQuery` 属性。
- 当分类的 `preventParentPostCascadeQuery` 属性设置为 `true` 时,该分类的文章数量不会汇总到父分类中。
- 更新了树结构遍历逻辑,以支持对 `preventParentPostCascadeQuery` 属性的处理。
- 确保独立分类中的文章显示受控,不向上级分类进行聚合。
- 增加了相应的测试用例,以验证在不同树结构中 `preventParentPostCascadeQuery` 属性的功能性。

#### Which issue(s) this PR fixes:
Fixes #5663 
Fixes #4923
Fixes https://github.com/halo-dev/halo/issues/3418

#### Does this PR introduce a user-facing change?
```release-note
新增独立分类选项用于控制关联的子分类下的文章显示以提供更灵活的内容管理方式
```
2024-06-21 04:08:10 +00:00
John Niang c0ac2f37d7
Add support for patching extensions (#6031)
#### What type of PR is this?

/kind feature
/area core
/milestone 2.17.x

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

This PR adds patch method for all extensions API.

Patch example:

```bash
http -a admin:admin PATCH http://localhost:8090/apis/plugin.halo.run/v1alpha1/plugins/app-store-integration \
  Content-Type:application/json-patch+json \
  --raw='[{"op": "replace", "path": "/spec/enabled", "value": false}]'
```

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

Fixes #2311 

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

```release-note
None
```
2024-06-20 09:32:06 +00:00
guqing b5f9010e60
feat: support setting rendering templates for related posts on category (#6106)
#### What type of PR is this?
/kind feature
/area core
/milestone 2.17.x

#### What this PR does / why we need it:
支持在分类上为关联的文章统一设置渲染模板

现在文章的模板生效顺序为:
1. 文章关联的分类上设置的文章模板,如果有多个则选择第一个
2. 文章上设置的自定义模板
3. 文章的默认模板

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

#### Does this PR introduce a user-facing change?
```release-note
支持在分类上为关联的文章统一设置渲染模板
```
2024-06-20 08:12:07 +00:00
John Niang b692db1f57
Move post events into api modules (#6052)
Signed-off-by: JohnNiang <johnniang@foxmail.com>
2024-06-07 18:34:09 +08:00
John Niang 5df51bb715
Refactor plugin reconciliation for dependency mechanism (#5900)
#### What type of PR is this?

/kind improvement
/area core
/area plugin

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

This PR wholly refactors plugin reconciliation to implement dependency mechanism.

Currently,
- If we disable plugin which has dependents, the plugin must wait for dependents to be disabled.
- If we enable plugin which has dependencies , the plugin must wait for dependencies to be enabled.
- If we upgrade plugin which has dependents, the plugin must request dependents to be unloaded. After the plugin is unloaded, the plugin must cancel unload request for dependents.

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

Fixes #5872 

#### Special notes for your reviewer:

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

```release-note
优化被依赖的插件的升级,启用和禁用
```
2024-05-27 08:16:56 +00:00
guqing cb2138580c
chore: provide post content retrieval bean for plugins (#5981)
#### What type of PR is this?
/kind improvement
/area core
/area plugin
/milestone 2.16.x

#### What this PR does / why we need it:
为插件提供文章内容获取的 bean 以简化文章内容获取

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

#### Does this PR introduce a user-facing change?
```release-note
为插件提供文章内容获取的 Bean
```
2024-05-24 06:46:51 +00:00
guqing c1e8bdb568
feat: add scheduled post publishing feature (#5940)
#### What type of PR is this?
/kind feature
/area core
/milestone 2.16.x

#### What this PR does / why we need it:
新增文章定时发布功能

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

#### Does this PR introduce a user-facing change?
```release-note
新增文章定时发布功能
```
2024-05-24 04:58:51 +00:00
guqing 2a7900cca9
refactor: add default sort for extension listing (#5937)
#### What type of PR is this?
/kind improvement
/area core
/milestone 2.16.x

#### What this PR does / why we need it:
为自定义模型 List API 添加默认排序

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

#### Does this PR introduce a user-facing change?
```release-note
为自定义模型 List API 添加默认排序
```
2024-05-20 08:34:42 +00:00
guqing c22b4e9ef4
refactor: optimize auth provider sorting with drag-and-drop support (#5914)
#### What type of PR is this?
/kind feature
/area core
/area ui
/milestone 2.16.x

#### What this PR does / why we need it:
优化认证方式的排序并支持拖动

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

#### Does this PR introduce a user-facing change?
```release-note
优化认证方式的排序并支持拖动
```
2024-05-20 08:30:42 +00:00
guqing dc451e2629
fix: changes to Unstructured metadata do not take effect (#5880)
#### What type of PR is this?
/kind bug
/area core
/milestone 2.16.x

#### What this PR does / why we need it:
修复对 Unstructured 的 metadata 进行更改不会被应用的问题

#### Does this PR introduce a user-facing change?
```release-note
修复插件定义的权限没有在插件详情页显示的问题
```
2024-05-10 04:32:24 +00:00
guqing 0e17d53ede
feat: subscription support for expression-based subscribing (#5705)
#### What type of PR is this?
/kind feature
/area core
/milestone 2.15.x

#### What this PR does / why we need it:
通知订阅支持基于表达式订阅

see #5632 for more details

how to test it?
1. 测试系统通知功能的文章、页面有新评论通知和评论有新回复通知的功能是否正常
2. 测试 2.14 创建的文章、评论和回复升级到此版本后是否能继续收到相应通知,如文章有新评论

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

#### Does this PR introduce a user-facing change?
```release-note
通知订阅支持基于表达式订阅避免订阅随数据量增长同时自动优化之前的订阅数据
```
2024-04-26 10:26:41 +00:00