Skip to content

Commit 6bfc30b

Browse files
committed
fix: some user group permissions
These permissions were never meant to be directly edited by staff. They should never have been added to the staff user edit page as it just caused confusion when the settings reset at the daily group change. I've now added these settings to the group directly and allow the settings on the user edit page to override the group settings. I refrained from fixing the can_download permission for now, because so many different things affect it and it will need at 3 separate permissions to control everything it does. Trying to fix it will take much more effort than what can be fixed today. Because of this, I removed the setting from the user edit page to reduce confusion from staff who don't realize it is controlled by the scheduler every hour. Relevant issue: HDInnovations#1820.
1 parent b0ed026 commit 6bfc30b

33 files changed

+582
-125
lines changed

app/Console/Commands/AutoBanDisposableUsers.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,7 @@ final public function handle(): void
7070
if ($v->fails()) {
7171
// If User Is Using A Disposable Email Set The Users Group To Banned
7272
$user->group_id = $bannedGroup[0];
73-
$user->can_upload = 0;
7473
$user->can_download = 0;
75-
$user->can_comment = 0;
76-
$user->can_invite = 0;
77-
$user->can_request = 0;
78-
$user->can_chat = 0;
7974
$user->save();
8075

8176
// Log The Ban To Ban Log

app/Console/Commands/AutoDisableInactiveUsers.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,7 @@ final public function handle(): void
6262
foreach ($users as $user) {
6363
if ($user->seedingTorrents()->doesntExist()) {
6464
$user->group_id = $disabledGroup[0];
65-
$user->can_upload = false;
6665
$user->can_download = false;
67-
$user->can_comment = false;
68-
$user->can_invite = false;
69-
$user->can_request = false;
70-
$user->can_chat = false;
7166
$user->disabled_at = Carbon::now();
7267
$user->save();
7368

app/Console/Commands/AutoGroup.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,8 @@ final public function handle(): void
7777
if ($user->group_id === UserGroup::LEECH->value) {
7878
// Keep these as 0/1 instead of false/true
7979
// because it reduces 6% custom casting overhead
80-
$user->can_request = 0;
81-
$user->can_invite = 0;
8280
$user->can_download = 0;
8381
} else {
84-
$user->can_request = 1;
85-
$user->can_invite = 1;
8682
$user->can_download = 1;
8783
}
8884

app/Console/Commands/AutoSoftDeleteDisabledUsers.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,7 @@ final public function handle(): void
7171

7272
foreach ($users as $user) {
7373
$user->update([
74-
'can_upload' => false,
7574
'can_download' => false,
76-
'can_comment' => false,
77-
'can_invite' => false,
78-
'can_request' => false,
79-
'can_chat' => false,
8075
'group_id' => UserGroup::PRUNED->value,
8176
'deleted_by' => User::SYSTEM_USER_ID,
8277
]);

app/Http/Controllers/API/ChatController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ public function createMessage(Request $request): \Illuminate\Contracts\Routing\R
142142
$targeted = $request->input('targeted');
143143
$save = $request->get('save');
144144

145-
if ($user->can_chat === false) {
145+
if (!($user->can_chat ?? $user->group->can_chat)) {
146146
return response('error', 401);
147147
}
148148

app/Http/Controllers/Staff/BanController.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,7 @@ public function store(StoreBanRequest $request): \Illuminate\Http\RedirectRespon
5555

5656
$user->update([
5757
'group_id' => $bannedGroup[0],
58-
'can_upload' => 0,
5958
'can_download' => 0,
60-
'can_comment' => 0,
61-
'can_invite' => 0,
62-
'can_request' => 0,
63-
'can_chat' => 0,
6459
]);
6560

6661
$ban = Ban::create(['created_by' => $staff->id] + $request->validated());

app/Http/Controllers/Staff/MassActionController.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,7 @@ public function update(): \Illuminate\Http\RedirectResponse
7272
$user->update([
7373
'group_id' => $memberGroup[0],
7474
'active' => 1,
75-
'can_upload' => 1,
7675
'can_download' => 1,
77-
'can_request' => 1,
78-
'can_comment' => 1,
79-
'can_invite' => 1,
8076
'email_verified_at' => now(),
8177
]);
8278

app/Http/Controllers/Staff/UnbanController.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,7 @@ public function store(StoreUnbanRequest $request): \Illuminate\Http\RedirectResp
4141

4242
$user->update([
4343
'group_id' => $request->group_id,
44-
'can_upload' => 1,
4544
'can_download' => 1,
46-
'can_comment' => 1,
47-
'can_invite' => 1,
48-
'can_request' => 1,
49-
'can_chat' => 1,
5045
]);
5146

5247
Ban::create([

app/Http/Controllers/Staff/UserController.php

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -93,12 +93,12 @@ public function update(UpdateUserRequest $request, User $user): \Illuminate\Http
9393
public function permissions(Request $request, User $user): \Illuminate\Http\RedirectResponse
9494
{
9595
$user->update([
96-
'can_upload' => $request->boolean('can_upload'),
96+
'can_chat' => $request->filled('can_chat') ? $request->boolean('can_chat') : null,
97+
'can_comment' => $request->filled('can_comment') ? $request->boolean('can_comment') : null,
9798
'can_download' => $request->boolean('can_download'),
98-
'can_comment' => $request->boolean('can_comment'),
99-
'can_invite' => $request->boolean('can_invite'),
100-
'can_request' => $request->boolean('can_request'),
101-
'can_chat' => $request->boolean('can_chat'),
99+
'can_invite' => $request->filled('can_invite') ? $request->boolean('can_invite') : null,
100+
'can_request' => $request->filled('can_request') ? $request->boolean('can_request') : null,
101+
'can_upload' => $request->filled('can_upload') ? $request->boolean('can_upload') : null,
102102
]);
103103

104104
cache()->forget('user:'.$user->passkey);
@@ -117,12 +117,7 @@ protected function destroy(Request $request, User $user): \Illuminate\Http\Redir
117117
abort_if($user->group->is_modo || $request->user()->is($user), 403);
118118

119119
$user->update([
120-
'can_upload' => false,
121120
'can_download' => false,
122-
'can_comment' => false,
123-
'can_invite' => false,
124-
'can_request' => false,
125-
'can_chat' => false,
126121
'group_id' => UserGroup::PRUNED->value,
127122
'deleted_by' => auth()->id(),
128123
]);

app/Http/Controllers/TorrentController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ public function create(Request $request): \Illuminate\Contracts\View\Factory|\Il
377377
public function store(StoreTorrentRequest $request): \Illuminate\Http\RedirectResponse
378378
{
379379
$user = $request->user();
380-
abort_if($user->can_upload === false || $user->group->can_upload == 0, 403, __('torrent.cant-upload').' '.__('torrent.cant-upload-desc'));
380+
abort_unless($user->can_upload ?? $user->group->can_upload, 403, __('torrent.cant-upload').' '.__('torrent.cant-upload-desc'));
381381

382382
abort_if(\is_array($request->file('torrent')), 400);
383383

app/Http/Controllers/User/InviteController.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public function create(Request $request, User $user): \Illuminate\Contracts\View
5757
->withErrors(trans('user.invites-disabled'));
5858
}
5959

60-
if ($user->can_invite == 0) {
60+
if (!($user->can_invite ?? $user->group->can_invite)) {
6161
return to_route('home.index')
6262
->withErrors(trans('user.invites-banned'));
6363
}
@@ -82,7 +82,7 @@ public function create(Request $request, User $user): \Illuminate\Contracts\View
8282
*/
8383
public function store(Request $request, User $user): \Illuminate\Http\RedirectResponse
8484
{
85-
abort_unless($request->user()->is($user) && $user->can_invite, 403);
85+
abort_unless($request->user()->is($user) && ($user->can_invite ?? $user->group->can_invite), 403);
8686

8787
if (config('other.invites_restriced') && !\in_array($user->group->name, config('other.invite_groups'), true)) {
8888
return to_route('home.index')
@@ -135,7 +135,7 @@ public function store(Request $request, User $user): \Illuminate\Http\RedirectRe
135135
*/
136136
public function destroy(Request $request, User $user, Invite $sentInvite): \Illuminate\Http\RedirectResponse
137137
{
138-
abort_unless($request->user()->group->is_modo || ($request->user()->is($user) && $user->can_invite), 403);
138+
abort_unless($request->user()->group->is_modo || ($request->user()->is($user) && ($user->can_invite ?? $user->group->can_invite)), 403);
139139

140140
if ($sentInvite->accepted_by !== null) {
141141
return to_route('users.invites.index', ['user' => $user])
@@ -158,7 +158,7 @@ public function destroy(Request $request, User $user, Invite $sentInvite): \Illu
158158
*/
159159
public function send(Request $request, User $user, Invite $sentInvite): \Illuminate\Http\RedirectResponse
160160
{
161-
abort_unless($request->user()->group->is_modo || ($request->user()->is($user) && $user->can_invite), 403);
161+
abort_unless($request->user()->group->is_modo || ($request->user()->is($user) && ($user->can_invite ?? $user->group->can_invite)), 403);
162162

163163
if ($sentInvite->accepted_by !== null) {
164164
return to_route('users.invites.index', ['user' => $user])

app/Http/Livewire/Comment.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ final public function deleteComment(): void
131131

132132
final public function postReply(): void
133133
{
134-
abort_if(!$this->model instanceof Ticket && auth()->user()->can_comment === false, 403, __('comment.rights-revoked'));
134+
abort_unles($this->model instanceof Ticket || (auth()->user()->can_comment ?? auth()->user()->group->can_comment), 403, __('comment.rights-revoked'));
135135

136136
abort_if($this->model instanceof Torrent && $this->model->status !== Torrent::APPROVED, 403, __('comment.torrent-status'));
137137

app/Http/Livewire/Comments.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ final public function loadMore(): void
112112
final public function postComment(): void
113113
{
114114
// Authorization
115-
abort_if(!$this->model instanceof Ticket && $this->user->can_comment === false, 403, __('comment.rights-revoked'));
115+
abort_unless($this->model instanceof Ticket || ($this->user->can_comment ?? $this->user->group->can_comment), 403, __('comment.rights-revoked'));
116116

117117
abort_if($this->model instanceof Torrent && $this->model->status !== Torrent::APPROVED, 403, __('comment.torrent-status'));
118118

app/Http/Requests/Staff/StoreGroupRequest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,22 @@ public function rules(Request $request): array
111111
'required',
112112
'boolean',
113113
],
114+
'can_chat' => [
115+
'required',
116+
'boolean',
117+
],
118+
'can_comment' => [
119+
'required',
120+
'boolean',
121+
],
122+
'can_invite' => [
123+
'required',
124+
'boolean',
125+
],
126+
'can_request' => [
127+
'required',
128+
'boolean',
129+
],
114130
'can_upload' => [
115131
'required',
116132
'boolean',

app/Http/Requests/Staff/UpdateGroupRequest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,22 @@ public function rules(Request $request): array
117117
'required',
118118
'boolean',
119119
],
120+
'can_chat' => [
121+
'required',
122+
'boolean',
123+
],
124+
'can_comment' => [
125+
'required',
126+
'boolean',
127+
],
128+
'can_invite' => [
129+
'required',
130+
'boolean',
131+
],
132+
'can_request' => [
133+
'required',
134+
'boolean',
135+
],
120136
'can_upload' => [
121137
'required',
122138
'boolean',

app/Models/Group.php

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@
4444
* @property bool $is_freeleech
4545
* @property bool $is_double_upload
4646
* @property bool $is_refundable
47+
* @property bool $can_chat
48+
* @property bool $can_comment
49+
* @property bool $can_invite
50+
* @property bool $can_request
4751
* @property bool $can_upload
4852
* @property bool $is_incognito
4953
* @property bool $autogroup
@@ -65,7 +69,28 @@ class Group extends Model
6569
/**
6670
* Get the attributes that should be cast.
6771
*
68-
* @return array{is_uploader: 'bool', is_internal: 'bool', is_editor: 'bool', is_owner: 'bool', is_admin: 'bool', is_modo: 'bool', is_trusted: 'bool', is_immune: 'bool', is_freeleech: 'bool', is_double_upload: 'bool', is_refundable: 'bool', can_upload: 'bool', is_incognito: 'bool', autogroup: 'bool', system_required: 'bool', min_ratio: 'decimal:2'}
72+
* @return array{
73+
* is_uploader: 'bool',
74+
* is_internal: 'bool',
75+
* is_editor: 'bool',
76+
* is_owner: 'bool',
77+
* is_admin: 'bool',
78+
* is_modo: 'bool',
79+
* is_trusted: 'bool',
80+
* is_immune: 'bool',
81+
* is_freeleech: 'bool',
82+
* is_double_upload: 'bool',
83+
* is_refundable: 'bool',
84+
* can_chat: 'bool',
85+
* can_comment: 'bool',
86+
* can_invite: 'bool',
87+
* can_request: 'bool',
88+
* can_upload: 'bool',
89+
* is_incognito: 'bool',
90+
* autogroup: 'bool',
91+
* system_required: 'bool',
92+
* min_ratio: 'decimal:2',
93+
* }
6994
*/
7095
protected function casts(): array
7196
{
@@ -81,6 +106,10 @@ protected function casts(): array
81106
'is_freeleech' => 'bool',
82107
'is_double_upload' => 'bool',
83108
'is_refundable' => 'bool',
109+
'can_chat' => 'bool',
110+
'can_comment' => 'bool',
111+
'can_invite' => 'bool',
112+
'can_request' => 'bool',
84113
'can_upload' => 'bool',
85114
'is_incognito' => 'bool',
86115
'autogroup' => 'bool',

app/Providers/FortifyServiceProvider.php

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,7 @@ public function toResponse($request): \Illuminate\Http\RedirectResponse
5959

6060
if ($user->group_id == $disabledGroup[0]) {
6161
$user->group_id = $memberGroup[0];
62-
$user->can_upload = 1;
6362
$user->can_download = 1;
64-
$user->can_comment = 1;
65-
$user->can_invite = 1;
66-
$user->can_request = 1;
67-
$user->can_chat = 1;
6863
$user->disabled_at = null;
6964
$user->save();
7065

@@ -123,11 +118,7 @@ public function toResponse($request): \Illuminate\Http\RedirectResponse|\Illumin
123118

124119
if ($user->group_id !== $bannedGroup[0]) {
125120
if ($user->group_id === $validatingGroup[0]) {
126-
$user->can_upload = 1;
127121
$user->can_download = 1;
128-
$user->can_request = 1;
129-
$user->can_comment = 1;
130-
$user->can_invite = 1;
131122
$user->group_id = $memberGroup[0];
132123
$user->active = true;
133124
$user->save();

database/factories/GroupFactory.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ public function definition(): array
5252
'is_freeleech' => $this->faker->boolean(),
5353
'is_double_upload' => $this->faker->boolean(),
5454
'is_refundable' => $this->faker->boolean(),
55+
'can_chat' => $this->faker->boolean(),
56+
'can_comment' => $this->faker->boolean(),
57+
'can_invite' => $this->faker->boolean(),
58+
'can_request' => $this->faker->boolean(),
5559
'can_upload' => $this->faker->boolean(),
5660
'is_incognito' => $this->faker->boolean(),
5761
'autogroup' => $this->faker->boolean(),
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* NOTICE OF LICENSE.
7+
*
8+
* UNIT3D Community Edition is open-sourced software licensed under the GNU Affero General Public License v3.0
9+
* The details is bundled with this project in the file LICENSE.txt.
10+
*
11+
* @project UNIT3D Community Edition
12+
*
13+
* @author Roardom <roardom@protonmail.com>
14+
* @license https://www.gnu.org/licenses/agpl-3.0.en.html/ GNU Affero General Public License v3.0
15+
*/
16+
17+
use Illuminate\Database\Migrations\Migration;
18+
use Illuminate\Database\Schema\Blueprint;
19+
use Illuminate\Support\Facades\Schema;
20+
21+
return new class () extends Migration {
22+
/**
23+
* Run the migrations.
24+
*/
25+
public function up(): void
26+
{
27+
Schema::table('users', function (Blueprint $table): void {
28+
$table->boolean('can_chat')->nullable()->change();
29+
$table->boolean('can_comment')->nullable()->change();
30+
$table->boolean('can_invite')->nullable()->change();
31+
$table->boolean('can_request')->nullable()->after('can_invite')->change();
32+
$table->boolean('can_upload')->nullable()->change();
33+
});
34+
35+
Schema::table('groups', function (Blueprint $table): void {
36+
$table->boolean('can_chat')->after('is_refundable');
37+
$table->boolean('can_comment')->after('can_chat');
38+
$table->boolean('can_invite')->after('can_comment');
39+
$table->boolean('can_request')->after('can_invite');
40+
});
41+
42+
DB::table('users')->update([
43+
'can_chat' => null,
44+
'can_comment' => null,
45+
'can_invite' => null,
46+
'can_request' => null,
47+
'can_upload' => null,
48+
]);
49+
50+
DB::table('groups')
51+
->whereNotIn('slug', [
52+
'validating',
53+
'guest',
54+
'banned',
55+
'bot',
56+
'leech',
57+
'disabled',
58+
'pruned',
59+
])
60+
->update([
61+
'can_comment' => true,
62+
'can_chat' => true,
63+
'can_request' => true,
64+
'can_invite' => true,
65+
]);
66+
}
67+
};

0 commit comments

Comments
 (0)