From a66835fbfda7639b048947df9ef4c597b4eb3728 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Tue, 10 Sep 2019 22:41:53 -0600 Subject: [PATCH 01/18] Update changelog --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7b5d230f9..465a0092c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,9 @@ ### Changed - Updated EmailService, added new domains [#1690](https://github.com/pixelfed/pixelfed/pull/1690) - Updated quill.js to v1.3.7 [#1692](https://github.com/pixelfed/pixelfed/pull/1690) + +## Deprecated +- Remove deprecated profile following/followers [#1697](https://github.com/pixelfed/pixelfed/pull/1697) ## [v0.10.3 (2019-09-08)](https://github.com/pixelfed/pixelfed/compare/v0.10.2...v0.10.3) From 39394327f06a8ddb266d20f51410d630a7b92e18 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Tue, 10 Sep 2019 23:33:51 -0600 Subject: [PATCH 02/18] Update FollowController, fix private account bug --- app/Http/Controllers/FollowerController.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/Http/Controllers/FollowerController.php b/app/Http/Controllers/FollowerController.php index bd3f4b674..dfac38ce4 100644 --- a/app/Http/Controllers/FollowerController.php +++ b/app/Http/Controllers/FollowerController.php @@ -27,7 +27,11 @@ class FollowerController extends Controller ]); $item = (int) $request->input('item'); $this->handleFollowRequest($item); - return response()->json(200); + if($request->wantsJson()) { + return response()->json(200); + } else { + return redirect()->back(); + } } protected function handleFollowRequest($item) From 23bb12413b93267bb586bcf2b4324f7b1735febc Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Tue, 10 Sep 2019 23:36:02 -0600 Subject: [PATCH 03/18] Update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 465a0092c..eb207ae36 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ ### Fixed - Fixed count bug in StatusHashtagService [#1694](https://github.com/pixelfed/pixelfed/pull/1694) +- Fixed private account bug [#1699](https://github.com/pixelfed/pixelfed/pull/1699) ### Changed - Updated EmailService, added new domains [#1690](https://github.com/pixelfed/pixelfed/pull/1690) From 01352e04eabf1466496d3fcf7b9468e0709d6320 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Wed, 11 Sep 2019 00:15:27 -0600 Subject: [PATCH 04/18] Update Privacy Settings --- app/Http/Controllers/Settings/PrivacySettings.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/Http/Controllers/Settings/PrivacySettings.php b/app/Http/Controllers/Settings/PrivacySettings.php index 99f7d4100..754258fc7 100644 --- a/app/Http/Controllers/Settings/PrivacySettings.php +++ b/app/Http/Controllers/Settings/PrivacySettings.php @@ -29,14 +29,14 @@ trait PrivacySettings public function privacyStore(Request $request) { - $settings = Auth::user()->settings; - $profile = Auth::user()->profile; + $settings = $request->user()->settings; + $profile = $request->user()->profile; $fields = [ 'is_private', 'crawlable', 'show_profile_follower_count', 'show_profile_following_count', - ]; + ]; foreach ($fields as $field) { $form = $request->input($field); if ($field == 'is_private') { @@ -65,7 +65,7 @@ trait PrivacySettings } $settings->save(); } - + Cache::forget('profile:settings:' . $profile->id); return redirect(route('settings.privacy'))->with('status', 'Settings successfully updated!'); } From a74b3ea798f6b0659a1079fd468cf6c8306957d6 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Wed, 11 Sep 2019 00:22:03 -0600 Subject: [PATCH 05/18] Update ProfileController --- app/Http/Controllers/ProfileController.php | 156 ++++++++++----------- 1 file changed, 77 insertions(+), 79 deletions(-) diff --git a/app/Http/Controllers/ProfileController.php b/app/Http/Controllers/ProfileController.php index cbc120ced..59fc4f451 100644 --- a/app/Http/Controllers/ProfileController.php +++ b/app/Http/Controllers/ProfileController.php @@ -20,80 +20,93 @@ class ProfileController extends Controller { public function show(Request $request, $username) { - $user = Profile::whereUsername($username)->firstOrFail(); - if($user->domain) { - return redirect($user->remote_url); - } - if($user->status != null) { - return $this->accountCheck($user); - } else { - return $this->buildProfile($request, $user); + $user = Profile::whereNull('domain') + ->whereNull('status') + ->whereUsername($username) + ->firstOrFail(); + if($request->wantsJson() && config('federation.activitypub.enabled')) { + return $this->showActivityPub($request, $user); } + return $this->buildProfile($request, $user); } - // TODO: refactor this mess protected function buildProfile(Request $request, $user) { $username = $user->username; $loggedIn = Auth::check(); $isPrivate = false; $isBlocked = false; + if(!$loggedIn) { + $key = 'profile:settings:' . $user->id; + $ttl = now()->addHours(6); + $settings = Cache::remember($key, $ttl, function() use($user) { + return $user->user->settings; + }); - if($user->status != null) { - return ProfileController::accountCheck($user); - } + if ($user->is_private == true) { + abort(404); + } - if ($user->remote_url) { - $settings = new \StdClass; - $settings->crawlable = false; - $settings->show_profile_follower_count = true; - $settings->show_profile_following_count = true; + $owner = false; + $is_following = false; + + $is_admin = $user->user->is_admin; + $profile = $user; + $settings = [ + 'crawlable' => $settings->crawlable, + 'following' => [ + 'count' => $settings->show_profile_following_count, + 'list' => $settings->show_profile_following + ], + 'followers' => [ + 'count' => $settings->show_profile_follower_count, + 'list' => $settings->show_profile_followers + ] + ]; + return view('profile.show', compact('profile', 'settings')); } else { - $settings = $user->user->settings; - } + $key = 'profile:settings:' . $user->id; + $ttl = now()->addHours(6); + $settings = Cache::remember($key, $ttl, function() use($user) { + return $user->user->settings; + }); - if ($request->wantsJson() && config('federation.activitypub.enabled')) { - return $this->showActivityPub($request, $user); - } + if ($user->is_private == true) { + $isPrivate = $this->privateProfileCheck($user, $loggedIn); + } - if ($user->is_private == true) { - $isPrivate = $this->privateProfileCheck($user, $loggedIn); - } - - if ($loggedIn == true) { $isBlocked = $this->blockedProfileCheck($user); + + $owner = $loggedIn && Auth::id() === $user->user_id; + $is_following = ($owner == false && Auth::check()) ? $user->followedBy(Auth::user()->profile) : false; + + if ($isPrivate == true || $isBlocked == true) { + $requested = Auth::check() ? FollowRequest::whereFollowerId(Auth::user()->profile_id) + ->whereFollowingId($user->id) + ->exists() : false; + return view('profile.private', compact('user', 'is_following', 'requested')); + } + + $is_admin = is_null($user->domain) ? $user->user->is_admin : false; + $profile = $user; + $settings = [ + 'crawlable' => $settings->crawlable, + 'following' => [ + 'count' => $settings->show_profile_following_count, + 'list' => $settings->show_profile_following + ], + 'followers' => [ + 'count' => $settings->show_profile_follower_count, + 'list' => $settings->show_profile_followers + ] + ]; + return view('profile.show', compact('profile', 'settings')); } - - $owner = $loggedIn && Auth::id() === $user->user_id; - $is_following = ($owner == false && Auth::check()) ? $user->followedBy(Auth::user()->profile) : false; - - if ($isPrivate == true || $isBlocked == true) { - $requested = Auth::check() ? FollowRequest::whereFollowerId(Auth::user()->profile_id) - ->whereFollowingId($user->id) - ->exists() : false; - return view('profile.private', compact('user', 'is_following', 'requested')); - } - - $is_admin = is_null($user->domain) ? $user->user->is_admin : false; - $profile = $user; - $settings = [ - 'crawlable' => $settings->crawlable, - 'following' => [ - 'count' => $settings->show_profile_following_count, - 'list' => $settings->show_profile_following - ], - 'followers' => [ - 'count' => $settings->show_profile_follower_count, - 'list' => $settings->show_profile_followers - ] - ]; - return view('profile.show', compact('user', 'profile', 'settings', 'owner', 'is_following', 'is_admin')); } public function permalinkRedirect(Request $request, $username) { - $user = Profile::whereUsername($username)->firstOrFail(); - $settings = User::whereUsername($username)->firstOrFail()->settings; + $user = Profile::whereNull('domain')->whereUsername($username)->firstOrFail(); if ($request->wantsJson() && config('federation.activitypub.enabled')) { return $this->showActivityPub($request, $user); @@ -136,34 +149,19 @@ class ProfileController extends Controller return false; } - public static function accountCheck(Profile $profile) - { - switch ($profile->status) { - case 'disabled': - case 'suspended': - case 'delete': - return view('profile.disabled'); - break; - - default: - # code... - break; - } - - return abort(404); - } - public function showActivityPub(Request $request, $user) { abort_if(!config('federation.activitypub.enabled'), 404); - - if($user->status != null) { - return ProfileController::accountCheck($user); - } - $fractal = new Fractal\Manager(); - $resource = new Fractal\Resource\Item($user, new ProfileTransformer); - $res = $fractal->createData($resource)->toArray(); - return response(json_encode($res['data']))->header('Content-Type', 'application/activity+json'); + abort_if($user->domain, 404); + $key = 'profile:ap:' . $user->id; + $ttl = now()->addHours(6); + + return Cache::remember($key, $ttl, function() use($user) { + $fractal = new Fractal\Manager(); + $resource = new Fractal\Resource\Item($user, new ProfileTransformer); + $res = $fractal->createData($resource)->toArray(); + return response(json_encode($res['data']))->header('Content-Type', 'application/activity+json'); + }); } public function showAtomFeed(Request $request, $user) From c1eb19f8350a41d0c4a5e86fceb7d9f7bb4dbd0d Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Wed, 11 Sep 2019 00:23:42 -0600 Subject: [PATCH 06/18] Update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index eb207ae36..74053c4d5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ ### Changed - Updated EmailService, added new domains [#1690](https://github.com/pixelfed/pixelfed/pull/1690) - Updated quill.js to v1.3.7 [#1692](https://github.com/pixelfed/pixelfed/pull/1690) +- Cache ProfileController [#1700](https://github.com/pixelfed/pixelfed/pull/1700) ## Deprecated - Remove deprecated profile following/followers [#1697](https://github.com/pixelfed/pixelfed/pull/1697) From 9195ba45b9470c699a37144bf3ee7569498037ef Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Thu, 12 Sep 2019 22:36:12 -0600 Subject: [PATCH 07/18] Update ComposeModal v4 --- .../assets/js/components/ComposeModal.vue | 63 ++++++++++++------- 1 file changed, 42 insertions(+), 21 deletions(-) diff --git a/resources/assets/js/components/ComposeModal.vue b/resources/assets/js/components/ComposeModal.vue index 3d9035bf1..99c3df1b1 100644 --- a/resources/assets/js/components/ComposeModal.vue +++ b/resources/assets/js/components/ComposeModal.vue @@ -1,6 +1,6 @@