Skip to content

Commit

Permalink
(Add) New torrent moderator group (#4351)
Browse files Browse the repository at this point in the history
* add: new torrent moderator group

- this group is limited to moderating and editing torrents via is_editor and is_torrent_modo group permissions
  • Loading branch information
HDVinnie authored Nov 27, 2024
1 parent 4540500 commit a56c0cf
Show file tree
Hide file tree
Showing 22 changed files with 843 additions and 593 deletions.
61 changes: 37 additions & 24 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -1,27 +1,40 @@
name: PHP Lint (Pint)
on: [push, pull_request]
jobs:
phplint:
strategy:
matrix:
operating-system:
- ubuntu-22.04
name: ${{ matrix.operating-system }}
runs-on: ${{ matrix.operating-system }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Run Pint
uses: aglipanci/laravel-pint-action@2.0.0
with:
preset: psr12
verboseMode: true
- name: Commit Changes
uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: PHP Style Change (Laravel Pint CI)
commit_user_name: HDVinne
commit_user_email: hdinnovations@protonmail.com
commit_author: HDVinnie <hdinnovations@protonmail.com>
build-assets:
strategy:
matrix:
operating-system:
- ubuntu-22.04
php-version:
- '8.3'
name: ${{ matrix.operating-system }}
runs-on: ${{ matrix.operating-system }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup PHP 8.3
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}
extensions: curl, dom, gd, libxml, mbstring, zip, mysql, xml, intl, bcmath, redis-phpredis/phpredis@6.0.1
ini-values: error_reporting=E_ALL
coverage: pcov
tools: composer:v2
env:
REDIS_CONFIGURE_OPTS: --enable-redis
- name: Install Composer Dependencies
env:
COMPOSER_AUTH: ${{ secrets.COMPOSER_AUTH }}
run: composer install --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist --optimize-autoloader
- name: Run Pint
run: ./vendor/bin/pint
- name: Commit Changes
uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: PHP Style Change (Laravel Pint CI)
commit_user_name: HDVinne
commit_user_email: hdinnovations@protonmail.com
commit_author: HDVinnie <hdinnovations@protonmail.com>
4 changes: 2 additions & 2 deletions .github/workflows/prettier-blade.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ jobs:
- name: Run Prettier
run: bunx prettier -w *
- name: Commit Changes
uses: stefanzweifel/git-auto-commit-action@v4
uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: Blade Style Change (Prettier Blade CI)
commit_user_name: HDVinne
commit_user_email: hdinnovations@protonmail.com
commit_author: HDVinnie <hdinnovations@protonmail.com>
commit_author: HDVinnie <hdinnovations@protonmail.com>
3 changes: 1 addition & 2 deletions app/Http/Controllers/PageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@ public function staff(): \Illuminate\Contracts\View\Factory|\Illuminate\View\Vie
return view('page.staff', [
'staff' => Group::query()
->with('users.group')
->where('is_modo', '=', 1)
->orWhere('is_admin', '=', 1)
->where('is_torrent_modo', '=', 1)
->orderByDesc('position')
->get(),
]);
Expand Down
4 changes: 4 additions & 0 deletions app/Http/Controllers/Staff/ModerationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ public function __construct(private readonly ChatRepository $chatRepository)
*/
public function index(): \Illuminate\Contracts\View\Factory|\Illuminate\View\View
{
abort_unless(auth()->user()->group->is_torrent_modo, 403);

return view('Staff.moderation.index', [
'current' => now(),
'pending' => Torrent::withoutGlobalScope(ApprovedScope::class)
Expand All @@ -65,6 +67,8 @@ public function index(): \Illuminate\Contracts\View\Factory|\Illuminate\View\Vie
*/
public function update(UpdateModerationRequest $request, int $id): \Illuminate\Http\RedirectResponse
{
abort_unless(auth()->user()->group->is_torrent_modo, 403);

$torrent = Torrent::withoutGlobalScope(ApprovedScope::class)->with('user')->findOrFail($id);

if ($request->integer('old_status') !== $torrent->status) {
Expand Down
4 changes: 4 additions & 0 deletions app/Http/Requests/Staff/StoreGroupRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ public function rules(Request $request): array
'required',
'boolean',
],
'is_torrent_modo' => [
'required',
'boolean',
],
'is_modo' => [
'required',
'boolean',
Expand Down
4 changes: 4 additions & 0 deletions app/Http/Requests/Staff/UpdateGroupRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ public function rules(Request $request): array
'required',
'boolean',
],
'is_torrent_modo' => [
'required',
'boolean',
],
'is_modo' => [
'required',
'boolean',
Expand Down
3 changes: 3 additions & 0 deletions app/Models/Group.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
* @property bool $is_uploader
* @property bool $is_internal
* @property bool $is_editor
* @property bool $is_torrent_modo
* @property bool $is_owner
* @property bool $is_admin
* @property bool $is_modo
Expand Down Expand Up @@ -73,6 +74,7 @@ class Group extends Model
* is_uploader: 'bool',
* is_internal: 'bool',
* is_editor: 'bool',
* is_torrent_modo: 'bool',
* is_owner: 'bool',
* is_admin: 'bool',
* is_modo: 'bool',
Expand All @@ -98,6 +100,7 @@ protected function casts(): array
'is_uploader' => 'bool',
'is_internal' => 'bool',
'is_editor' => 'bool',
'is_torrent_modo' => 'bool',
'is_owner' => 'bool',
'is_admin' => 'bool',
'is_modo' => 'bool',
Expand Down
1 change: 1 addition & 0 deletions database/factories/GroupFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public function definition(): array
'is_owner' => false,
'is_admin' => false,
'is_modo' => false,
'is_torrent_modo' => false,
'is_editor' => false,
'is_trusted' => $this->faker->boolean(),
'is_immune' => $this->faker->boolean(),
Expand Down
40 changes: 26 additions & 14 deletions database/migrations/2024_01_15_151522_update_groups_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
* @license https://www.gnu.org/licenses/agpl-3.0.en.html/ GNU Affero General Public License v3.0
*/

use App\Models\Group;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
Expand All @@ -27,27 +26,40 @@ public function up(): void
$table->index(['is_editor']);
});

Group::updateOrCreate(
['slug' => 'editor'],
DB::table('groups')->upsert([
[
'name' => 'Editor',
'slug' => 'editor',
'position' => 17,
'color' => '#15B097',
'icon' => config('other.font-awesome').' fa-user-pen',
'effect' => 'none',
'autogroup' => 0,
'is_owner' => 0,
'is_admin' => 0,
'is_modo' => 0,
'is_editor' => 1,
'is_internal' => 0,
'is_trusted' => 1,
'is_freeleech' => 1,
'is_immune' => 1,
'can_upload' => 0,
'autogroup' => false,
'is_owner' => false,
'is_admin' => false,
'is_modo' => false,
'is_editor' => true,
'is_internal' => false,
'is_trusted' => true,
'is_freeleech' => true,
'is_immune' => true,
'can_upload' => true,
'level' => 0,
]
);
], 'slug');

$group = DB::table('groups')->where('slug', '=', 'editor')->first();

$forumIds = DB::table('forums')->pluck('id');

foreach ($forumIds as $forumId) {
DB::table('forum_permissions')->insert([
'forum_id' => $forumId,
'group_id' => $group->id,
'read_topic' => false,
'reply_topic' => false,
'start_topic' => false,
]);
}
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function up(): void
'cost',
'sender_id',
'receiver_id',
DB::raw('CASE WHEN EXISTS(SELECT * FROM posts WHERE id = post_id) THEN post_id END)'),
DB::raw('CASE WHEN EXISTS(SELECT * FROM posts WHERE id = post_id) THEN post_id END'),
'created_at',
])
->where('name', '=', 'tip')
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php

declare(strict_types=1);

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class () extends Migration {
public function up(): void
{
Schema::table('groups', function (Blueprint $table): void {
$table->boolean('is_torrent_modo')->default(false)->after('is_editor');
$table->index(['is_torrent_modo']);
});

DB::table('groups')->upsert([
[
'name' => 'Torrent Moderator',
'slug' => 'torrent-moderator',
'position' => 17,
'color' => '#15B097',
'icon' => config('other.font-awesome').' fa-badge-check',
'effect' => 'none',
'autogroup' => false,
'is_owner' => false,
'is_admin' => false,
'is_modo' => false,
'is_torrent_modo' => true,
'is_editor' => true,
'is_internal' => false,
'is_trusted' => true,
'is_freeleech' => true,
'is_immune' => true,
'can_upload' => true,
'level' => 0,
]
], 'slug');

$group = DB::table('groups')->where('slug', '=', 'torrent-moderator')->first();

$forumIds = DB::table('forums')->pluck('id');

foreach ($forumIds as $forumId) {
DB::table('forum_permissions')->insert([
'forum_id' => $forumId,
'group_id' => $group->id,
'read_topic' => false,
'reply_topic' => false,
'start_topic' => false,
]);
}

$staffGroups = DB::table('groups')->where('is_modo', '=', true)->get();

foreach ($staffGroups as $staffGroup) {
DB::table('groups')->where('id', $staffGroup->id)->update(['is_torrent_modo' => true]);
}
}
};
Loading

0 comments on commit a56c0cf

Please sign in to comment.