From 6ce513f8c384b6680a5e2542d5c015bb71b6e413 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Thu, 14 Mar 2024 00:06:33 -0600 Subject: [PATCH] Update user_filters, use config_cache --- app/Http/Controllers/AccountController.php | 4 ++-- app/Http/Controllers/Api/ApiV1Controller.php | 4 ++-- app/Http/Controllers/Api/V1/DomainBlockController.php | 2 +- app/Services/ConfigCacheService.php | 3 +++ 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/app/Http/Controllers/AccountController.php b/app/Http/Controllers/AccountController.php index 90810008b..7000ace07 100644 --- a/app/Http/Controllers/AccountController.php +++ b/app/Http/Controllers/AccountController.php @@ -157,7 +157,7 @@ class AccountController extends Controller $pid = $request->user()->profile_id; $count = UserFilterService::muteCount($pid); - $maxLimit = intval(config('instance.user_filters.max_user_mutes')); + $maxLimit = (int) config_cache('instance.user_filters.max_user_mutes'); abort_if($count >= $maxLimit, 422, self::FILTER_LIMIT_MUTE_TEXT . $maxLimit . ' accounts'); if($count == 0) { $filterCount = UserFilter::whereUserId($pid)->count(); @@ -260,7 +260,7 @@ class AccountController extends Controller ]); $pid = $request->user()->profile_id; $count = UserFilterService::blockCount($pid); - $maxLimit = intval(config('instance.user_filters.max_user_blocks')); + $maxLimit = (int) config_cache('instance.user_filters.max_user_blocks'); abort_if($count >= $maxLimit, 422, self::FILTER_LIMIT_BLOCK_TEXT . $maxLimit . ' accounts'); if($count == 0) { $filterCount = UserFilter::whereUserId($pid)->whereFilterType('block')->count(); diff --git a/app/Http/Controllers/Api/ApiV1Controller.php b/app/Http/Controllers/Api/ApiV1Controller.php index 313890c28..fefc85442 100644 --- a/app/Http/Controllers/Api/ApiV1Controller.php +++ b/app/Http/Controllers/Api/ApiV1Controller.php @@ -1103,7 +1103,7 @@ class ApiV1Controller extends Controller } $count = UserFilterService::blockCount($pid); - $maxLimit = intval(config('instance.user_filters.max_user_blocks')); + $maxLimit = (int) config_cache('instance.user_filters.max_user_blocks'); if ($count == 0) { $filterCount = UserFilter::whereUserId($pid) ->whereFilterType('block') @@ -2145,7 +2145,7 @@ class ApiV1Controller extends Controller } $count = UserFilterService::muteCount($pid); - $maxLimit = intval(config('instance.user_filters.max_user_mutes')); + $maxLimit = (int) config_cache('instance.user_filters.max_user_mutes'); if ($count == 0) { $filterCount = UserFilter::whereUserId($pid) ->whereFilterType('mute') diff --git a/app/Http/Controllers/Api/V1/DomainBlockController.php b/app/Http/Controllers/Api/V1/DomainBlockController.php index 5a2698361..3b6730789 100644 --- a/app/Http/Controllers/Api/V1/DomainBlockController.php +++ b/app/Http/Controllers/Api/V1/DomainBlockController.php @@ -72,7 +72,7 @@ class DomainBlockController extends Controller abort_if(config_cache('pixelfed.domain.app') == $domain, 400, 'Cannot ban your own server'); $existingCount = UserDomainBlock::whereProfileId($pid)->count(); - $maxLimit = config('instance.user_filters.max_domain_blocks'); + $maxLimit = (int) config_cache('instance.user_filters.max_domain_blocks'); $errorMsg = __('profile.block.domain.max', ['max' => $maxLimit]); abort_if($existingCount >= $maxLimit, 400, $errorMsg); diff --git a/app/Services/ConfigCacheService.php b/app/Services/ConfigCacheService.php index c17f6375f..25566dcf6 100644 --- a/app/Services/ConfigCacheService.php +++ b/app/Services/ConfigCacheService.php @@ -103,6 +103,9 @@ class ConfigCacheService 'pixelfed.optimize_video', 'pixelfed.max_collection_length', 'media.delete_local_after_cloud', + 'instance.user_filters.max_user_blocks', + 'instance.user_filters.max_user_mutes', + 'instance.user_filters.max_domain_blocks', // 'system.user_mode' ];