first commit
Some checks failed
Approval After Edit JS / run (push) Has been cancelled
Approval After Edit PHP / run (push) Has been cancelled

This commit is contained in:
Fang_Zhijian 2025-09-20 00:20:14 +08:00
commit 01eff63c14
28 changed files with 5793 additions and 0 deletions

19
.editorconfig Normal file
View File

@ -0,0 +1,19 @@
# EditorConfig helps developers define and maintain consistent
# coding styles between different editors and IDEs
# editorconfig.org
root = true
[*]
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
indent_style = space
indent_size = 2
[*.{diff,md}]
trim_trailing_whitespace = false
[*.{php,xml,json}]
indent_size = 4

20
.gitattributes vendored Normal file
View File

@ -0,0 +1,20 @@
**/.gitattributes export-ignore
**/.gitignore export-ignore
**/.gitmodules export-ignore
**/.github export-ignore
**/.travis export-ignore
**/.travis.yml export-ignore
**/.editorconfig export-ignore
**/.styleci.yml export-ignore
**/phpunit.xml export-ignore
**/tests export-ignore
**/js/dist/**/* -diff
**/js/dist/**/* linguist-generated
**/js/dist-typings/**/* -diff
**/js/dist-typings/**/* linguist-generated
**/js/yarn.lock -diff
**/js/package-lock.json -diff
* text=auto eol=lf

11
.github/workflows/backend.yml vendored Normal file
View File

@ -0,0 +1,11 @@
name: Approval After Edit PHP
on: [workflow_dispatch, push, pull_request]
jobs:
run:
uses: flarum/framework/.github/workflows/REUSABLE_backend.yml@main
with:
enable_backend_testing: true
backend_directory: .

18
.github/workflows/frontend.yml vendored Normal file
View File

@ -0,0 +1,18 @@
name: Approval After Edit JS
on: [workflow_dispatch, push, pull_request]
jobs:
run:
uses: flarum/framework/.github/workflows/REUSABLE_frontend.yml@main
with:
enable_bundlewatch: false
enable_prettier: true
enable_typescript: true
frontend_directory: ./js
backend_directory: .
js_package_manager: npm
main_git_branch: master
secrets:
bundlewatch_github_token: ${{ secrets.BUNDLEWATCH_GITHUB_TOKEN }}

12
.gitignore vendored Normal file
View File

@ -0,0 +1,12 @@
/vendor
composer.lock
composer.phar
.DS_Store
Thumbs.db
tests/.phpunit.result.cache
/tests/integration/tmp
.vagrant
.idea/*
.vscode
js/coverage-ts

14
.styleci.yml Normal file
View File

@ -0,0 +1,14 @@
preset: recommended
enabled:
- logical_not_operators_with_successor_space
disabled:
- align_double_arrow
- blank_line_after_opening_tag
- multiline_array_trailing_comma
- new_with_braces
- phpdoc_align
- phpdoc_order
- phpdoc_separation
- phpdoc_types

18
LICENSE.md Normal file
View File

@ -0,0 +1,18 @@
MIT License
Copyright (c) <year> <copyright holders>
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.

27
README.md Normal file
View File

@ -0,0 +1,27 @@
# Approval After Edit
![License](https://img.shields.io/badge/license-MIT-blue.svg) [![Latest Stable Version](https://img.shields.io/packagist/v/klxf/approval-after-edit.svg)](https://packagist.org/packages/klxf/approval-after-edit) [![Total Downloads](https://img.shields.io/packagist/dt/klxf/approval-after-edit.svg)](https://packagist.org/packages/klxf/approval-after-edit)
A [Flarum](https://flarum.org) extension. Approval after edit
## Installation
Install with composer:
```sh
composer require klxf/approval-after-edit:"*"
```
## Updating
```sh
composer update klxf/approval-after-edit:"*"
php flarum migrate
php flarum cache:clear
```
## Links
- [Packagist](https://packagist.org/packages/klxf/approval-after-edit)
- [GitHub](https://github.com/klxf/approval-after-edit)
- [Discuss](https://discuss.flarum.org/d/PUT_DISCUSS_SLUG_HERE)

36
composer.json Normal file
View File

@ -0,0 +1,36 @@
{
"name": "klxf/approval-after-edit",
"description": "Approval after edit",
"keywords": [
"flarum"
],
"type": "flarum-extension",
"license": "MIT",
"require": {
"flarum/core": "^1.8.0",
"flarum/approval": "*"
},
"authors": [
{
"name": "Fang_Zhijian",
"email": "klxf@vip.qq.com",
"role": "Developer"
}
],
"autoload": {
"psr-4": {
"Klxf\\ApprovalAfterEdit\\": "src/"
}
},
"extra": {
"flarum-extension": {
"title": "Approval After Edit",
"category": "moderation",
"icon": {
"name": "fas fa-check-double",
"color": "#fff",
"backgroundColor": "#881415"
}
}
}
}

24
extend.php Normal file
View File

@ -0,0 +1,24 @@
<?php
/*
* This file is part of klxf/approval-after-edit.
*
* Copyright (c) 2025 Fang_Zhijian.
*
* For the full copyright and license information, please view the LICENSE.md
* file that was distributed with this source code.
*/
namespace Klxf\ApprovalAfterEdit;
use Flarum\Extend;
use Flarum\Post\Event\Saving;
return [
(new Extend\Frontend('admin'))
->js(__DIR__.'/js/dist/admin.js'),
new Extend\Locales(__DIR__.'/locale'),
(new Extend\Event)
->listen(Saving::class, Listeners\UnapproveNewPosts::class),
];

9
js/.gitignore vendored Normal file
View File

@ -0,0 +1,9 @@
.pnp.*
.yarn/*
!.yarn/patches
!.yarn/plugins
!.yarn/releases
!.yarn/sdks
!.yarn/versions
node_modules

1
js/admin.ts Normal file
View File

@ -0,0 +1 @@
export * from './src/admin';

2
js/dist/admin.js generated vendored Normal file
View File

@ -0,0 +1,2 @@
(()=>{var e={n:a=>{var r=a&&a.__esModule?()=>a.default:()=>a;return e.d(r,{a:r}),r},d:(a,r)=>{for(var t in r)e.o(r,t)&&!e.o(a,t)&&Object.defineProperty(a,t,{enumerable:!0,get:r[t]})},o:(e,a)=>Object.prototype.hasOwnProperty.call(e,a)};(()=>{"use strict";const a=flarum.core.compat["admin/app"];var r=e.n(a);r().initializers.add("klxf-approval-after-edit",function(){r().extensionData.for("klxf-approval-after-edit").registerPermission({icon:"fas fa-check-double",label:r().translator.trans("klxf-approval-after-edit.admin.permissions.bypass"),permission:"klxf-approval-after-edit.bypass"},"reply",85)})})(),module.exports={}})();
//# sourceMappingURL=admin.js.map

1
js/dist/admin.js.map generated vendored Normal file
View File

@ -0,0 +1 @@
{"version":3,"file":"admin.js","mappings":"MACA,IAAIA,EAAsB,CCA1BA,EAAyBC,IACxB,IAAIC,EAASD,GAAUA,EAAOE,WAC7B,IAAOF,EAAiB,QACxB,IAAM,EAEP,OADAD,EAAoBI,EAAEF,EAAQ,CAAEG,EAAGH,IAC5BA,GCLRF,EAAwB,CAACM,EAASC,KACjC,IAAI,IAAIC,KAAOD,EACXP,EAAoBS,EAAEF,EAAYC,KAASR,EAAoBS,EAAEH,EAASE,IAC5EE,OAAOC,eAAeL,EAASE,EAAK,CAAEI,YAAY,EAAMC,IAAKN,EAAWC,MCJ3ER,EAAwB,CAACc,EAAKC,IAAUL,OAAOM,UAAUC,eAAeC,KAAKJ,EAAKC,I,mBCAlF,MAAM,EAA+BI,OAAOC,KAAKC,OAAO,a,aCExDC,IAAAA,aAAiBC,IAAI,2BAA4B,WAC/CD,IAAAA,cAAiB,IACV,4BACJE,mBACC,CACEC,KAAM,sBACNC,MAAOJ,IAAAA,WAAeK,MAAM,qDAC5BC,WAAY,mCAEd,QACA,GAEN,E","sources":["webpack://@klxf/approval-after-edit/webpack/bootstrap","webpack://@klxf/approval-after-edit/webpack/runtime/compat get default export","webpack://@klxf/approval-after-edit/webpack/runtime/define property getters","webpack://@klxf/approval-after-edit/webpack/runtime/hasOwnProperty shorthand","webpack://@klxf/approval-after-edit/external root \"flarum.core.compat['admin/app']\"","webpack://@klxf/approval-after-edit/./src/admin/index.ts"],"sourcesContent":["// The require scope\nvar __webpack_require__ = {};\n\n","// getDefaultExport function for compatibility with non-harmony modules\n__webpack_require__.n = (module) => {\n\tvar getter = module && module.__esModule ?\n\t\t() => (module['default']) :\n\t\t() => (module);\n\t__webpack_require__.d(getter, { a: getter });\n\treturn getter;\n};","// define getter functions for harmony exports\n__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n\t\tif(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n\t\t\tObject.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n\t\t}\n\t}\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","const __WEBPACK_NAMESPACE_OBJECT__ = flarum.core.compat['admin/app'];","import app from 'flarum/admin/app';\n\napp.initializers.add('klxf-approval-after-edit', () => {\n app.extensionData\n .for(\"klxf-approval-after-edit\")\n .registerPermission(\n {\n icon: \"fas fa-check-double\",\n label: app.translator.trans(\"klxf-approval-after-edit.admin.permissions.bypass\"),\n permission: \"klxf-approval-after-edit.bypass\",\n },\n \"reply\",\n 85\n )\n});\n"],"names":["__webpack_require__","module","getter","__esModule","d","a","exports","definition","key","o","Object","defineProperty","enumerable","get","obj","prop","prototype","hasOwnProperty","call","flarum","core","compat","app","add","registerPermission","icon","label","trans","permission"],"sourceRoot":""}

2
js/dist/forum.js generated vendored Normal file
View File

@ -0,0 +1,2 @@
(()=>{var e={n:r=>{var t=r&&r.__esModule?()=>r.default:()=>r;return e.d(t,{a:t}),t},d:(r,t)=>{for(var o in t)e.o(t,o)&&!e.o(r,o)&&Object.defineProperty(r,o,{enumerable:!0,get:t[o]})},o:(e,r)=>Object.prototype.hasOwnProperty.call(e,r)};(()=>{"use strict";const r=flarum.core.compat["forum/app"];e.n(r)().initializers.add("klxf/approval-after-edit",function(){})})(),module.exports={}})();
//# sourceMappingURL=forum.js.map

1
js/dist/forum.js.map generated vendored Normal file
View File

@ -0,0 +1 @@
{"version":3,"file":"forum.js","mappings":"MACA,IAAIA,EAAsB,CCA1BA,EAAyBC,IACxB,IAAIC,EAASD,GAAUA,EAAOE,WAC7B,IAAOF,EAAiB,QACxB,IAAM,EAEP,OADAD,EAAoBI,EAAEF,EAAQ,CAAEG,EAAGH,IAC5BA,GCLRF,EAAwB,CAACM,EAASC,KACjC,IAAI,IAAIC,KAAOD,EACXP,EAAoBS,EAAEF,EAAYC,KAASR,EAAoBS,EAAEH,EAASE,IAC5EE,OAAOC,eAAeL,EAASE,EAAK,CAAEI,YAAY,EAAMC,IAAKN,EAAWC,MCJ3ER,EAAwB,CAACc,EAAKC,IAAUL,OAAOM,UAAUC,eAAeC,KAAKJ,EAAKC,I,mBCAlF,MAAM,EAA+BI,OAAOC,KAAKC,OAAO,a,MCExDC,GAAAA,aAAiBC,IAAI,2BAA4B,WAC/C,E","sources":["webpack://@klxf/approval-after-edit/webpack/bootstrap","webpack://@klxf/approval-after-edit/webpack/runtime/compat get default export","webpack://@klxf/approval-after-edit/webpack/runtime/define property getters","webpack://@klxf/approval-after-edit/webpack/runtime/hasOwnProperty shorthand","webpack://@klxf/approval-after-edit/external root \"flarum.core.compat['forum/app']\"","webpack://@klxf/approval-after-edit/./src/forum/index.ts"],"sourcesContent":["// The require scope\nvar __webpack_require__ = {};\n\n","// getDefaultExport function for compatibility with non-harmony modules\n__webpack_require__.n = (module) => {\n\tvar getter = module && module.__esModule ?\n\t\t() => (module['default']) :\n\t\t() => (module);\n\t__webpack_require__.d(getter, { a: getter });\n\treturn getter;\n};","// define getter functions for harmony exports\n__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n\t\tif(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n\t\t\tObject.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n\t\t}\n\t}\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","const __WEBPACK_NAMESPACE_OBJECT__ = flarum.core.compat['forum/app'];","import app from 'flarum/forum/app';\n\napp.initializers.add('klxf/approval-after-edit', () => {\n // ...\n});\n"],"names":["__webpack_require__","module","getter","__esModule","d","a","exports","definition","key","o","Object","defineProperty","enumerable","get","obj","prop","prototype","hasOwnProperty","call","flarum","core","compat","app","add"],"sourceRoot":""}

1
js/forum.ts Normal file
View File

@ -0,0 +1 @@
export * from './src/forum';

5441
js/package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

28
js/package.json Normal file
View File

@ -0,0 +1,28 @@
{
"name": "@klxf/approval-after-edit",
"private": true,
"version": "0.0.0",
"devDependencies": {
"flarum-webpack-config": "^2.0.0",
"webpack": "^5.65.0",
"webpack-cli": "^4.9.1",
"prettier": "^2.5.1",
"@flarum/prettier-config": "^1.0.0",
"flarum-tsconfig": "^1.0.2",
"typescript": "^4.5.4",
"typescript-coverage-report": "^0.6.1"
},
"scripts": {
"dev": "webpack --mode development --watch",
"build": "webpack --mode production",
"analyze": "cross-env ANALYZER=true npm run build",
"format": "prettier --write src",
"format-check": "prettier --check src",
"clean-typings": "npx rimraf dist-typings && mkdir dist-typings",
"build-typings": "npm run clean-typings && ([ -e src/@types ] && cp -r src/@types dist-typings/@types || true) && tsc && npm run post-build-typings",
"post-build-typings": "find dist-typings -type f -name '*.d.ts' -print0 | xargs -0 sed -i 's,../src/@types,@types,g'",
"check-typings": "tsc --noEmit --emitDeclarationOnly false",
"check-typings-coverage": "typescript-coverage-report"
},
"prettier": "@flarum/prettier-config"
}

15
js/src/admin/index.ts Normal file
View File

@ -0,0 +1,15 @@
import app from 'flarum/admin/app';
app.initializers.add('klxf-approval-after-edit', () => {
app.extensionData
.for("klxf-approval-after-edit")
.registerPermission(
{
icon: "fas fa-check-double",
label: app.translator.trans("klxf-approval-after-edit.admin.permissions.bypass"),
permission: "klxf-approval-after-edit.bypass",
},
"reply",
85
)
});

5
js/src/forum/index.ts Normal file
View File

@ -0,0 +1,5 @@
import app from 'flarum/forum/app';
app.initializers.add('klxf/approval-after-edit', () => {
// ...
});

24
js/tsconfig.json Normal file
View File

@ -0,0 +1,24 @@
{
// Use Flarum's tsconfig as a starting point
"extends": "flarum-tsconfig",
// This will match all .ts, .tsx, .d.ts, .js, .jsx files in your `src` folder
// and also tells your Typescript server to read core's global typings for
// access to `dayjs` and `$` in the global namespace.
"include": [
"src/**/*",
"../vendor/*/*/js/dist-typings/@types/**/*",
// <CUSTOM-1>
// </CUSTOM-1>
"@types/**/*"
],
"compilerOptions": {
// This will output typings to `dist-typings`
"declarationDir": "./dist-typings",
"baseUrl": ".",
"paths": {
"flarum/*": ["../vendor/flarum/core/js/dist-typings/*"],
// <CUSTOM-2>
// </CUSTOM-2>
}
}
}

1
js/webpack.config.js Normal file
View File

@ -0,0 +1 @@
module.exports = require('flarum-webpack-config')();

0
less/admin.less Normal file
View File

0
less/forum.less Normal file
View File

6
locale/en.yml Normal file
View File

@ -0,0 +1,6 @@
klxf-approval-after-edit:
admin:
permissions:
bypass: No approval edit posts
forum:

6
locale/zh.yml Normal file
View File

@ -0,0 +1,6 @@
klxf-approval-after-edit:
admin:
permissions:
bypass: 编辑帖子无需审核
forum:

View File

@ -0,0 +1,51 @@
<?php
namespace Klxf\ApprovalAfterEdit\Listeners;
use Carbon\Carbon;
use Flarum\Flags\Flag;
use Flarum\Post\Event\Saving;
use Flarum\Settings\SettingsRepositoryInterface;
class UnapproveNewPosts
{
protected $settings;
public function __construct(SettingsRepositoryInterface $settings)
{
$this->settings = $settings;
}
public function handle(Saving $event)
{
$post = $event->post;
if ($event->actor->hasPermission('klxf-approval-after-edit.bypass')) {
return;
}
if ($post->exists) {
if (!$post->isDirty('content')) {
return;
}
$post->is_approved = false;
$post->afterSave(function ($post) {
if ($post->number == 1) {
$post->discussion->is_approved = false;
$post->discussion->save();
}
$flag = new Flag;
$flag->post_id = $post->id;
$flag->type = 'approval';
$flag->reason = 'Post edited, needs re-approval';
$flag->created_at = Carbon::now();
$flag->save();
});
}
}
}