Skip to content

Commit f1b36ca

Browse files
committed
Initial commit
0 parents  commit f1b36ca

File tree

16 files changed

+378
-0
lines changed

16 files changed

+378
-0
lines changed

.editorconfig

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# EditorConfig helps developers define and maintain consistent
2+
# coding styles between different editors and IDEs
3+
# editorconfig.org
4+
5+
root = true
6+
7+
[*]
8+
end_of_line = lf
9+
charset = utf-8
10+
trim_trailing_whitespace = true
11+
insert_final_newline = true
12+
indent_style = space
13+
indent_size = 2
14+
15+
[*.{diff,md}]
16+
trim_trailing_whitespace = false
17+
18+
[*.{php,xml,json}]
19+
indent_size = 4

.gitattributes

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
**/.gitattributes export-ignore
2+
**/.gitignore export-ignore
3+
**/.gitmodules export-ignore
4+
**/.github export-ignore
5+
**/.travis export-ignore
6+
**/.travis.yml export-ignore
7+
**/.editorconfig export-ignore
8+
**/.styleci.yml export-ignore
9+
10+
**/phpunit.xml export-ignore
11+
**/tests export-ignore
12+
13+
**/js/dist/**/* -diff
14+
**/js/dist/**/* linguist-generated
15+
**/js/dist-typings/**/* -diff
16+
**/js/dist-typings/**/* linguist-generated
17+
**/js/yarn.lock -diff
18+
**/js/package-lock.json -diff
19+
20+
* text=auto eol=lf

.github/workflows/backend.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
name: Fix Discussion Rename PHP
2+
3+
on: [workflow_dispatch, push, pull_request]
4+
5+
jobs:
6+
run:
7+
uses: flarum/framework/.github/workflows/REUSABLE_backend.yml@main
8+
with:
9+
enable_backend_testing: true
10+
11+
backend_directory: .

.gitignore

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/vendor
2+
composer.lock
3+
composer.phar
4+
5+
.DS_Store
6+
Thumbs.db
7+
tests/.phpunit.result.cache
8+
/tests/integration/tmp
9+
.vagrant
10+
.idea/*
11+
.vscode
12+
js/coverage-ts

.styleci.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
preset: recommended
2+
3+
enabled:
4+
- logical_not_operators_with_successor_space
5+
6+
disabled:
7+
- align_double_arrow
8+
- blank_line_after_opening_tag
9+
- multiline_array_trailing_comma
10+
- new_with_braces
11+
- phpdoc_align
12+
- phpdoc_order
13+
- phpdoc_separation
14+
- phpdoc_types

LICENSE.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
MIT License
2+
3+
Copyright (c) <year> <copyright holders>
4+
5+
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:
6+
7+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8+
9+
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.

README.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Allow Own Discussion Rename
2+
[English](README.md) | [简体中文](README.zh-CN.md)
3+
4+
![License](https://img.shields.io/badge/license-MIT-blue.svg) [![Latest Stable Version](https://img.shields.io/packagist/v/huoxin/allow-own-discussion-rename.svg)](https://packagist.org/packages/huoxin/allow-own-discussion-rename) [![Total Downloads](https://img.shields.io/packagist/dt/huoxin/allow-own-discussion-rename.svg)](https://packagist.org/packages/huoxin/allow-own-discussion-rename)
5+
6+
This extension is a temporary workaround for [flarum/framework#3692](https://github.com/flarum/framework/issues/3692). Code logic is taken directly from [Flarum Core](https://github.com/flarum/framework/blob/a46ce07255219093fb6f77e16ea7c7108a5f61aa/framework/core/src/Discussion/Access/DiscussionPolicy.php#L33C1-L33C73). It allows discussion authors to rename their own discussions even when they do not have the `discussion.rename` permission specify by the tag restrictions.
7+
8+
> [!WARNING]
9+
> This extension use `forceAllow()` to override the permission from Tags policy. This is intentional but may conflict with other permission-altering extensions.
10+
>
11+
> Test fully before use.
12+
>
13+
> Remove/disable this extension once you upgrade to a version that includes an official fix of the stated issue.
14+
15+
## What it does
16+
17+
If the user is the **discussion author** and **can reply**. It will follow the permission set here:
18+
19+
If not it will follow to other policy such as the tag policy:
20+
21+
## Installation
22+
23+
Install with composer:
24+
25+
```sh
26+
composer require huoxin/allow-own-discussion-rename:"*"
27+
```
28+
29+
## Updating
30+
31+
```sh
32+
composer update huoxin/allow-own-discussion-rename:"*"
33+
php flarum migrate
34+
php flarum cache:clear
35+
```
36+
37+
## Links
38+
39+
- [Packagist](https://packagist.org/packages/huoxin/allow-own-discussion-rename)
40+
- [GitHub](https://github.com/huoxin233/allow-own-discussion-rename)
41+
- [Discuss](https://discuss.flarum.org/d/38239-allow-own-discussion-rename)

README.zh-CN.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Allow Own Discussion Rename
2+
[English](README.md) | [简体中文](README.zh-CN.md)
3+
4+
![License](https://img.shields.io/badge/license-MIT-blue.svg) [![Latest Stable Version](https://img.shields.io/packagist/v/huoxin/allow-own-discussion-rename.svg)](https://packagist.org/packages/huoxin/allow-own-discussion-rename) [![Total Downloads](https://img.shields.io/packagist/dt/huoxin/allow-own-discussion-rename.svg)](https://packagist.org/packages/huoxin/allow-own-discussion-rename)
5+
6+
本扩展是 [flarum/framework#3692](https://github.com/flarum/framework/issues/3692) 的临时修复方案。功能逻辑代码完全照搬 [Flarum Core](https://github.com/flarum/framework/blob/a46ce07255219093fb6f77e16ea7c7108a5f61aa/framework/core/src/Discussion/Access/DiscussionPolicy.php#L33C1-L33C73)。即便在标签权限限制导致没有 `discussion.rename` 权限时,它也允许用户重命名自己创建的讨论。
7+
8+
> [!WARNING]
9+
> 本扩展通过 `forceAllow()` 覆盖来自 Tags 策略的权限。这是有意为之,但可能与其他更改权限的扩展产生冲突。
10+
>
11+
> 在使用前请充分测试。
12+
>
13+
> 在该问题得到官方修复后,建议移除/禁用本扩展。
14+
15+
## 功能说明
16+
17+
当用户是该 **讨论的创建者** 并且 **有权限进行回复** 时,将依据以下设置判断是否允许重命名:
18+
19+
若不满足上述条件,则仍遵循其他策略(例如 Tag 策略)的权限设置:
20+
21+
## 安装
22+
23+
使用 Composer 安装:
24+
25+
```sh
26+
composer require huoxin/allow-own-discussion-rename:"*"
27+
```
28+
29+
## 更新
30+
31+
```sh
32+
composer update huoxin/allow-own-discussion-rename:"*"
33+
php flarum migrate
34+
php flarum cache:clear
35+
```
36+
37+
## 链接
38+
39+
- [Packagist](https://packagist.org/packages/huoxin/allow-own-discussion-rename)
40+
- [GitHub](https://github.com/huoxin233/allow-own-discussion-rename)
41+
- [Discuss](https://discuss.flarum.org/d/38239-allow-own-discussion-rename)
42+
43+

composer.json

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
{
2+
"name": "huoxin/allow-own-discussion-rename",
3+
"description": "Force allow renaming of own discussion",
4+
"keywords": [
5+
"flarum"
6+
],
7+
"type": "flarum-extension",
8+
"license": "MIT",
9+
"require": {
10+
"flarum/core": "^1.2.0"
11+
},
12+
"authors": [
13+
{
14+
"name": "huoxin",
15+
"email": "23447157+huoxin233@users.noreply.github.com",
16+
"role": "Developer"
17+
}
18+
],
19+
"autoload": {
20+
"psr-4": {
21+
"Huoxin\\AllowOwnDiscussionRename\\": "src/"
22+
}
23+
},
24+
"extra": {
25+
"flarum-extension": {
26+
"title": "Allow Own Discussion Rename",
27+
"category": "",
28+
"icon": {
29+
"name": "fas fa-user-edit",
30+
"color": "#000000",
31+
"backgroundColor": "#ffffff"
32+
}
33+
},
34+
"flarum-cli": {
35+
"modules": {
36+
"admin": false,
37+
"forum": false,
38+
"js": false,
39+
"jsCommon": false,
40+
"css": false,
41+
"locale": false,
42+
"gitConf": true,
43+
"githubActions": true,
44+
"prettier": false,
45+
"typescript": false,
46+
"bundlewatch": false,
47+
"backendTesting": true,
48+
"editorConfig": true,
49+
"styleci": true
50+
}
51+
}
52+
},
53+
"minimum-stability": "dev",
54+
"prefer-stable": true,
55+
"autoload-dev": {
56+
"psr-4": {
57+
"Huoxin\\AllowOwnDiscussionRename\\Tests\\": "tests/"
58+
}
59+
},
60+
"scripts": {
61+
"test": [
62+
"@test:unit",
63+
"@test:integration"
64+
],
65+
"test:unit": "phpunit -c tests/phpunit.unit.xml",
66+
"test:integration": "phpunit -c tests/phpunit.integration.xml",
67+
"test:setup": "@php tests/integration/setup.php"
68+
},
69+
"scripts-descriptions": {
70+
"test": "Runs all tests.",
71+
"test:unit": "Runs all unit tests.",
72+
"test:integration": "Runs all integration tests.",
73+
"test:setup": "Sets up a database for use with integration tests. Execute this only once."
74+
},
75+
"require-dev": {
76+
"flarum/testing": "^1.0.0"
77+
}
78+
}

extend.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
/*
4+
* This file is part of huoxin/allow-own-discussion-rename.
5+
*
6+
* Copyright (c) 2025 huoxin.
7+
*
8+
* For the full copyright and license information, please view the LICENSE.md
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Huoxin\AllowOwnDiscussionRename;
13+
14+
use Flarum\Extend;
15+
use Flarum\Discussion\Discussion;
16+
use Huoxin\AllowOwnDiscussionRename\CustomDiscussionPolicy;
17+
18+
return [
19+
(new Extend\Policy())
20+
->modelPolicy(Discussion::class, CustomDiscussionPolicy::class),
21+
];

0 commit comments

Comments
 (0)