feat: 编辑已过审帖子自动退回审核队列

This commit is contained in:
2026-05-29 04:32:11 +08:00
commit 33a41503f8
4 changed files with 98 additions and 0 deletions

21
LICENSE Normal file
View File

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2026 MetaLab
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

29
composer.json Normal file
View File

@ -0,0 +1,29 @@
{
"name": "metazone/reapprove-on-edit",
"description": "编辑已通过审核的帖子时自动退回审核队列,防止恶意绕过审核。",
"type": "flarum-extension",
"license": "MIT",
"require": {
"flarum/core": "^1.0",
"flarum/approval": "^1.0"
},
"autoload": {
"psr-4": {
"MetaZone\\ReapproveOnEdit\\": "src/"
}
},
"extra": {
"flarum-extension": {
"title": "Reapprove On Edit",
"icon": {
"name": "fas fa-shield-alt",
"backgroundColor": "#e67e22",
"color": "#fff"
}
},
"flarum-locale": {
"code": "en",
"title": "English"
}
}
}

12
extend.php Normal file
View File

@ -0,0 +1,12 @@
<?php
namespace MetaZone\ReapproveOnEdit;
use Flarum\Extend;
use Flarum\Post\Event\Saving;
use MetaZone\ReapproveOnEdit\Listener\ReapproveOnEditListener;
return [
(new Extend\Event)
->listen(Saving::class, ReapproveOnEditListener::class),
];

View File

@ -0,0 +1,36 @@
<?php
namespace MetaZone\ReapproveOnEdit\Listener;
use Flarum\Post\Event\Saving;
class ReapproveOnEditListener
{
public function handle(Saving $event)
{
$post = $event->post;
// 新帖子不处理
if (! $post->exists) {
return;
}
// 帖子未被审核通过
if ($post->is_approved != 1) {
return;
}
// 内容未变动
if (! $post->isDirty('content')) {
return;
}
// 管理员免审
if (isset($event->actor) && $event->actor->isAdmin()) {
return;
}
// 退回审核队列
$post->is_approved = null;
}
}