From a4efbb75d8dd1285e74369da330d298b33991629 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Thu, 13 May 2021 23:45:36 -0600 Subject: [PATCH 1/4] Update admin settings, add rules --- .../Admin/AdminSettingsController.php | 29 +++++++- app/Http/Controllers/Api/ApiV1Controller.php | 72 +++++++++++-------- resources/views/admin/settings/home.blade.php | 47 ++++++++++++ 3 files changed, 117 insertions(+), 31 deletions(-) diff --git a/app/Http/Controllers/Admin/AdminSettingsController.php b/app/Http/Controllers/Admin/AdminSettingsController.php index 0dbf02e83..138a32f7f 100644 --- a/app/Http/Controllers/Admin/AdminSettingsController.php +++ b/app/Http/Controllers/Admin/AdminSettingsController.php @@ -19,6 +19,7 @@ trait AdminSettingsController $short_description = ConfigCacheService::get('app.short_description'); $description = ConfigCacheService::get('app.description'); $types = explode(',', ConfigCacheService::get('pixelfed.media_types')); + $rules = ConfigCacheService::get('app.rules') ? json_decode(ConfigCacheService::get('app.rules'), true) : null; $jpeg = in_array('image/jpg', $types) ? true : in_array('image/jpeg', $types); $png = in_array('image/png', $types); $gif = in_array('image/gif', $types); @@ -31,7 +32,8 @@ trait AdminSettingsController 'jpeg', 'png', 'gif', - 'mp4' + 'mp4', + 'rules' )); } @@ -50,6 +52,19 @@ trait AdminSettingsController 'type_mp4' => 'nullable', ]); + if($request->filled('rule_delete')) { + $index = (int) $request->input('rule_delete'); + $rules = ConfigCacheService::get('app.rules'); + $json = json_decode($rules, true); + if(!$rules || empty($json)) { + return; + } + unset($json[$index]); + $json = json_encode(array_values($json)); + ConfigCacheService::put('app.rules', $json); + return 200; + } + $media_types = explode(',', config_cache('pixelfed.media_types')); $media_types_original = $media_types; @@ -115,6 +130,18 @@ trait AdminSettingsController } } + if($request->filled('new_rule')) { + $rules = ConfigCacheService::get('app.rules'); + $val = $request->input('new_rule'); + if(!$rules) { + ConfigCacheService::put('app.rules', json_encode([$val])); + } else { + $json = json_decode($rules, true); + $json[] = $val; + ConfigCacheService::put('app.rules', json_encode(array_values($json))); + } + } + Cache::forget('api:site:configuration:_v0.2'); return redirect('/i/admin/settings'); diff --git a/app/Http/Controllers/Api/ApiV1Controller.php b/app/Http/Controllers/Api/ApiV1Controller.php index ddc02cdc4..8837e4f56 100644 --- a/app/Http/Controllers/Api/ApiV1Controller.php +++ b/app/Http/Controllers/Api/ApiV1Controller.php @@ -957,37 +957,49 @@ class ApiV1Controller extends Controller */ public function instance(Request $request) { - $res = [ - 'approval_required' => false, - 'contact_account' => null, - 'description' => config_cache('app.description'), - 'email' => config('instance.email'), - 'invites_enabled' => false, - 'rules' => [], - 'short_description' => 'Pixelfed - Photo sharing for everyone', - 'languages' => ['en'], - 'max_toot_chars' => (int) config('pixelfed.max_caption_length'), - 'registrations' => config_cache('pixelfed.open_registration'), - 'stats' => [ - 'user_count' => 0, - 'status_count' => 0, - 'domain_count' => 0 - ], - 'thumbnail' => config('app.url') . '/img/pixelfed-icon-color.png', - 'title' => config_cache('app.name'), - 'uri' => config('pixelfed.domain.app'), - 'urls' => [], - 'version' => '2.7.2 (compatible; Pixelfed ' . config('pixelfed.version') . ')', - 'environment' => [ - 'max_photo_size' => (int) config_cache('pixelfed.max_photo_size'), - 'max_avatar_size' => (int) config('pixelfed.max_avatar_size'), - 'max_caption_length' => (int) config('pixelfed.max_caption_length'), - 'max_bio_length' => (int) config('pixelfed.max_bio_length'), - 'max_album_length' => (int) config_cache('pixelfed.max_album_length'), - 'mobile_apis' => config_cache('pixelfed.oauth_enabled') + $res = Cache::remember('api:v1:instance-data', now()->addMinutes(15), function () { + $rules = config_cache('app.rules') ? collect(json_decode(config_cache('app.rules'), true)) + ->map(function($rule, $key) { + $id = $key + 1; + return [ + 'id' => "{$id}", + 'text' => $rule + ]; + }) + ->toArray() : []; + $res = [ + 'approval_required' => false, + 'contact_account' => null, + 'description' => config_cache('app.description'), + 'email' => config('instance.email'), + 'invites_enabled' => false, + 'rules' => $rules, + 'short_description' => 'Pixelfed - Photo sharing for everyone', + 'languages' => ['en'], + 'max_toot_chars' => (int) config('pixelfed.max_caption_length'), + 'registrations' => config_cache('pixelfed.open_registration'), + 'stats' => [ + 'user_count' => 0, + 'status_count' => 0, + 'domain_count' => 0 + ], + 'thumbnail' => config('app.url') . '/img/pixelfed-icon-color.png', + 'title' => config_cache('app.name'), + 'uri' => config('pixelfed.domain.app'), + 'urls' => [], + 'version' => '2.7.2 (compatible; Pixelfed ' . config('pixelfed.version') . ')', + 'environment' => [ + 'max_photo_size' => (int) config_cache('pixelfed.max_photo_size'), + 'max_avatar_size' => (int) config('pixelfed.max_avatar_size'), + 'max_caption_length' => (int) config('pixelfed.max_caption_length'), + 'max_bio_length' => (int) config('pixelfed.max_bio_length'), + 'max_album_length' => (int) config_cache('pixelfed.max_album_length'), + 'mobile_apis' => config_cache('pixelfed.oauth_enabled') - ] - ]; + ] + ]; + return $res; + }); return response()->json($res); } diff --git a/resources/views/admin/settings/home.blade.php b/resources/views/admin/settings/home.blade.php index 82a37e928..330b611ff 100644 --- a/resources/views/admin/settings/home.blade.php +++ b/resources/views/admin/settings/home.blade.php @@ -21,6 +21,9 @@ + @@ -151,6 +154,35 @@ +
+
+

Add rules that explain what is acceptable use.

+
+
+

Active Rules

+
    + @if($rules) + @foreach($rules as $rule) +
  1. +

    + {{$rule}} +

    +

    + +

    +
  2. + @endforeach + @endif +
+
+
+
+ + +
+
+
+
@@ -181,3 +213,18 @@
@endif @endsection + +@push('scripts') + +@endpush From 3b4add7b8e38b98711f8c3ae4034337b7df479f3 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Thu, 13 May 2021 23:46:38 -0600 Subject: [PATCH 2/4] Update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 57e3954ef..0de4597a8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -87,6 +87,7 @@ - Updated LikeService, fix likedBy method. ([a5e64da6](https://github.com/pixelfed/pixelfed/commit/a5e64da6)) - Updated PublicApiController, increase public timeline to 6 months from 3. ([8a736432](https://github.com/pixelfed/pixelfed/commit/8a736432)) - Updated LikeService, show like count to status owner. ([4408e2ef](https://github.com/pixelfed/pixelfed/commit/4408e2ef)) +- Updated admin settings, add rules. ([a4efbb75](https://github.com/pixelfed/pixelfed/commit/a4efbb75)) - ([](https://github.com/pixelfed/pixelfed/commit/)) ## [v0.10.10 (2021-01-28)](https://github.com/pixelfed/pixelfed/compare/v0.10.9...v0.10.10) From c9abd70e8a31f0583e5b06f2085cf78e8ccea68f Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Fri, 14 May 2021 17:15:08 -0600 Subject: [PATCH 3/4] Update LikeService, fix authentication bug --- app/Services/LikeService.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Services/LikeService.php b/app/Services/LikeService.php index a1bdeb55f..cb41850e1 100644 --- a/app/Services/LikeService.php +++ b/app/Services/LikeService.php @@ -76,7 +76,7 @@ class LikeService { 'others' => $status->likes_count >= 5, ]; - if(request()->user()->profile_id == $status->profile_id) { + if(request()->user() && request()->user()->profile_id == $status->profile_id) { $res['total_count'] = $status->likes_count; $res['total_count_pretty'] = number_format($res['total_count']); } From 74261999d3afb3d2dcc7399c634f269124567635 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Fri, 14 May 2021 17:15:40 -0600 Subject: [PATCH 4/4] Update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0de4597a8..74604b94a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -88,6 +88,7 @@ - Updated PublicApiController, increase public timeline to 6 months from 3. ([8a736432](https://github.com/pixelfed/pixelfed/commit/8a736432)) - Updated LikeService, show like count to status owner. ([4408e2ef](https://github.com/pixelfed/pixelfed/commit/4408e2ef)) - Updated admin settings, add rules. ([a4efbb75](https://github.com/pixelfed/pixelfed/commit/a4efbb75)) +- Updated LikeService, fix authentication bug. ([c9abd70e](https://github.com/pixelfed/pixelfed/commit/c9abd70e)) - ([](https://github.com/pixelfed/pixelfed/commit/)) ## [v0.10.10 (2021-01-28)](https://github.com/pixelfed/pixelfed/compare/v0.10.9...v0.10.10)