(Update) Improve readability of user groups with enums (#2120)

Co-authored-by: HDVinnie <hdinnovations@protonmail.com>
Co-authored-by: lokithor <lokithor@protonmail.com>
This commit is contained in:
Loki
2022-02-14 02:58:02 +01:00
committed by GitHub
parent 1eac22a541
commit ee9a9b811c
8 changed files with 61 additions and 25 deletions
+1 -1
View File
@@ -11,7 +11,7 @@ jobs:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.0'
php-version: '8.1'
tools: phplint
- name: Check syntax
run: phplint .
+1 -1
View File
@@ -8,7 +8,7 @@ jobs:
operating-system:
- ubuntu-latest
php-version:
- '8.0'
- '8.1'
name: php ${{ matrix.php-version }} on ${{ matrix.operating-system }}
services:
mysql:
+2 -2
View File
@@ -1,7 +1,7 @@
php:
preset: recommended
risky: true
version: 8
version: 8.1
enabled:
- method_argument_space
- not_operator_with_successor_space
@@ -27,4 +27,4 @@ js:
not-name:
- webpack.mix.js
css: true
vue: true
vue: true
+2 -1
View File
@@ -135,7 +135,8 @@ Use this command to generate demo users and torrents for testing purposes:
## <a name="versions"></a> 🚨 Version Support Information
Version | Status | PHP Version Required
:------------|:-------------------------|:------------
5.x.x | Active Support :rocket: | >= 8.0
6.x.x | Active Support :rocket: | >= 8.1
5.x.x | End Of Life :skull: | >= 8.0
4.x.x | End Of Life :skull: | >= 7.4
3.x.x | End Of Life :skull: | >= 7.4
2.3.0 to 2.7.0| End Of Life :skull: | >= 7.4
+2 -1
View File
@@ -4,7 +4,8 @@
Version | Status | PHP Version Required
:------------|:-------------------------|:------------
5.x.x | Active Support :rocket: | >= 8.0
6.x.x | Active Support :rocket: | >= 8.1
5.x.x | End Of Life :skull: | >= 8.0
4.x.x | End Of Life :skull: | >= 7.4
3.x.x | End Of Life :skull: | >= 7.4
2.3.0 to 2.7.0| End Of Life :skull: | >= 7.4
+19 -18
View File
@@ -13,6 +13,7 @@
namespace App\Console\Commands;
use App\Enums\UserGroups;
use App\Helpers\ByteUnits;
use App\Models\Group;
use App\Models\History;
@@ -53,8 +54,8 @@ class AutoGroup extends Command
// Temp Hard Coding of Group Requirements (Config Files To Come) (Upload in Bytes!) (Seedtime in Seconds!)
// Leech ratio dropped below sites minimum
if ($user->getRatio() < \config('other.ratio') && $user->group_id != 15) {
$user->group_id = 15;
if ($user->getRatio() < \config('other.ratio') && $user->group_id != UserGroups::LEECH) {
$user->group_id = UserGroups::LEECH;
$user->can_request = 0;
$user->can_invite = 0;
$user->can_download = 0;
@@ -62,8 +63,8 @@ class AutoGroup extends Command
}
// User >= 0 and ratio above sites minimum
if ($user->uploaded >= 0 && $user->getRatio() >= \config('other.ratio') && $user->group_id != 3) {
$user->group_id = 3;
if ($user->uploaded >= 0 && $user->getRatio() >= \config('other.ratio') && $user->group_id != UserGroups::USER) {
$user->group_id = UserGroups::USER;
$user->can_request = 1;
$user->can_invite = 1;
$user->can_download = 1;
@@ -71,44 +72,44 @@ class AutoGroup extends Command
}
// PowerUser >= 1TiB and account 1 month old
if ($user->uploaded >= $byteUnits->bytesFromUnit('1TiB') && $user->getRatio() >= \config('other.ratio') && $user->created_at < $current->copy()->subDays(30)->toDateTimeString() && $user->group_id != 11) {
$user->group_id = 11;
if ($user->uploaded >= $byteUnits->bytesFromUnit('1TiB') && $user->getRatio() >= \config('other.ratio') && $user->created_at < $current->copy()->subDays(30)->toDateTimeString() && $user->group_id != UserGroups::POWERUSER) {
$user->group_id = UserGroups::POWERUSER;
$user->save();
}
// SuperUser >= 5TiB and account 2 month old
if ($user->uploaded >= $byteUnits->bytesFromUnit('5TiB') && $user->getRatio() >= \config('other.ratio') && $user->created_at < $current->copy()->subDays(60)->toDateTimeString() && $user->group_id != 12) {
$user->group_id = 12;
if ($user->uploaded >= $byteUnits->bytesFromUnit('5TiB') && $user->getRatio() >= \config('other.ratio') && $user->created_at < $current->copy()->subDays(60)->toDateTimeString() && $user->group_id != UserGroups::SUPERUSER) {
$user->group_id = UserGroups::SUPERUSER;
$user->save();
}
// ExtremeUser >= 20TiB and account 3 month old
if ($user->uploaded >= $byteUnits->bytesFromUnit('20TiB') && $user->getRatio() >= \config('other.ratio') && $user->created_at < $current->copy()->subDays(90)->toDateTimeString() && $user->group_id != 13) {
$user->group_id = 13;
if ($user->uploaded >= $byteUnits->bytesFromUnit('20TiB') && $user->getRatio() >= \config('other.ratio') && $user->created_at < $current->copy()->subDays(90)->toDateTimeString() && $user->group_id != UserGroups::EXTREMEUSER) {
$user->group_id = UserGroups::EXTREMEUSER;
$user->save();
}
// InsaneUser >= 50TiB and account 6 month old
if ($user->uploaded >= $byteUnits->bytesFromUnit('50TiB') && $user->getRatio() >= \config('other.ratio') && $user->created_at < $current->copy()->subDays(180)->toDateTimeString() && $user->group_id != 14) {
$user->group_id = 14;
if ($user->uploaded >= $byteUnits->bytesFromUnit('50TiB') && $user->getRatio() >= \config('other.ratio') && $user->created_at < $current->copy()->subDays(180)->toDateTimeString() && $user->group_id != UserGroups::INSANEUSER) {
$user->group_id = UserGroups::INSANEUSER;
$user->save();
}
// Seeder Seedsize >= 5TiB and account 1 month old and seedtime average 30 days or better
if ($user->getTotalSeedSize() >= $byteUnits->bytesFromUnit('5TiB') && $user->getRatio() >= \config('other.ratio') && \round($user->getTotalSeedTime() / \max(1, $hiscount)) > 2_592_000 && $user->created_at < $current->copy()->subDays(30)->toDateTimeString() && $user->group_id != 17) {
$user->group_id = 17;
if ($user->getTotalSeedSize() >= $byteUnits->bytesFromUnit('5TiB') && $user->getRatio() >= \config('other.ratio') && \round($user->getTotalSeedTime() / \max(1, $hiscount)) > 2_592_000 && $user->created_at < $current->copy()->subDays(30)->toDateTimeString() && $user->group_id != UserGroups::SEEDER) {
$user->group_id = UserGroups::SEEDER;
$user->save();
}
// Veteran >= 100TiB and account 1 year old
if ($user->uploaded >= $byteUnits->bytesFromUnit('100TiB') && $user->getRatio() >= \config('other.ratio') && $user->created_at < $current->copy()->subDays(365)->toDateTimeString() && $user->group_id != 16) {
$user->group_id = 16;
if ($user->uploaded >= $byteUnits->bytesFromUnit('100TiB') && $user->getRatio() >= \config('other.ratio') && $user->created_at < $current->copy()->subDays(365)->toDateTimeString() && $user->group_id != UserGroups::VETERAN) {
$user->group_id = UserGroups::VETERAN;
$user->save();
}
// Archivist Seedsize >= 10TiB and account 3 month old and seedtime average 60 days or better
if ($user->getTotalSeedSize() >= $byteUnits->bytesFromUnit('10TiB') && $user->getRatio() >= \config('other.ratio') && \round($user->getTotalSeedTime() / \max(1, $hiscount)) > 2_592_000 * 2 && $user->created_at < $current->copy()->subDays(90)->toDateTimeString() && $user->group_id != 18) {
$user->group_id = 18;
if ($user->getTotalSeedSize() >= $byteUnits->bytesFromUnit('10TiB') && $user->getRatio() >= \config('other.ratio') && \round($user->getTotalSeedTime() / \max(1, $hiscount)) > 2_592_000 * 2 && $user->created_at < $current->copy()->subDays(90)->toDateTimeString() && $user->group_id != UserGroups::ARCHIVIST) {
$user->group_id = UserGroups::ARCHIVIST;
$user->save();
}
}
+31
View File
@@ -0,0 +1,31 @@
<?php
declare(strict_types=1);
namespace App\Enums;
enum UserGroups: int
{
case VALIDATING = 1;
case GUEST = 2;
case USER = 3;
case ADMINISTRATOR = 4;
case BANNED = 5;
case MODERATOR = 6;
case UPLOADER = 7;
case TRUSTEE = 8;
case BOT = 9;
case OWNER = 10;
case POWERUSER = 11;
case SUPERUSER = 12;
case EXTREMEUSER = 13;
case INSANEUSER = 14;
case LEECH = 15;
case VETERAN = 16;
case SEEDER = 17;
case ARCHIVIST = 18;
case INTERNAL = 19;
case DISABLED = 20;
case PRUNED = 21;
}
+3 -1
View File
@@ -11,6 +11,8 @@
* @license https://www.gnu.org/licenses/agpl-3.0.en.html/ GNU Affero General Public License v3.0
*/
use App\Enums\UserGroups;
return [
/*
@@ -26,5 +28,5 @@ return [
'account_age' => 90,
'last_login' => 90,
'soft_delete' => 120,
'group_ids' => [3, 11, 12, 15],
'group_ids' => [UserGroups::USER, UserGroups::POWERUSER, UserGroups::SUPERUSER, UserGroups::LEECH],
];