From 327dd891779cff983b05a16a290f507e505b7c1f Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Sat, 29 Dec 2018 22:36:16 -0700 Subject: [PATCH 01/23] Update PostComments, fix comment order --- resources/assets/js/components/PostComments.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/assets/js/components/PostComments.vue b/resources/assets/js/components/PostComments.vue index 6122f0b21..fc9990c1d 100644 --- a/resources/assets/js/components/PostComments.vue +++ b/resources/assets/js/components/PostComments.vue @@ -92,7 +92,7 @@ export default { axios.get(url) .then(response => { let self = this; - this.results = response.data.data; + this.results = _.reverse(response.data.data); this.pagination = response.data.meta.pagination; if(this.results.length > 0) { $('.load-more-link').removeClass('d-none'); From 9a3b70d23d2ce8c990c77fc037ea6c7c252e0048 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Sat, 29 Dec 2018 22:37:30 -0700 Subject: [PATCH 02/23] Update config --- config/pixelfed.php | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/config/pixelfed.php b/config/pixelfed.php index feb3ed318..0bd5b94f7 100644 --- a/config/pixelfed.php +++ b/config/pixelfed.php @@ -177,6 +177,28 @@ return [ */ 'image_quality' => (int) env('IMAGE_QUALITY', 80), + /* + |-------------------------------------------------------------------------- + | Account deletion + |-------------------------------------------------------------------------- + | + | Enable account deletion. + | + */ + 'account_deletion' => env('ACCOUNT_DELETION', true), + + /* + |-------------------------------------------------------------------------- + | Account deletion after X days + |-------------------------------------------------------------------------- + | + | Set account deletion queue after X days, set to false to delete accounts + | immediately. + | + */ + 'account_delete_after' => env('ACCOUNT_DELETE_AFTER', false), + + 'media_types' => env('MEDIA_TYPES', 'image/jpeg,image/png,image/gif'), 'enforce_account_limit' => env('LIMIT_ACCOUNT_SIZE', true), 'ap_inbox' => env('ACTIVITYPUB_INBOX', false), From 5b68d147d282bb49506da60f1ed58906dee50791 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Sat, 29 Dec 2018 22:39:08 -0700 Subject: [PATCH 03/23] Update StatusPipeline, only deliver if ap is enabled --- app/Jobs/StatusPipeline/NewStatusPipeline.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/Jobs/StatusPipeline/NewStatusPipeline.php b/app/Jobs/StatusPipeline/NewStatusPipeline.php index 973223689..efb7d6b1d 100644 --- a/app/Jobs/StatusPipeline/NewStatusPipeline.php +++ b/app/Jobs/StatusPipeline/NewStatusPipeline.php @@ -37,7 +37,10 @@ class NewStatusPipeline implements ShouldQueue $status = $this->status; StatusEntityLexer::dispatch($status); - StatusActivityPubDeliver::dispatch($status); + + if(config('pixelfed.activitypub_enabled') == true) { + StatusActivityPubDeliver::dispatch($status); + } // Cache::forever('post.'.$status->id, $status); // $redis = Redis::connection(); From 6f4da63a83cca651b8454051bf2525a028fb4ed3 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Sat, 29 Dec 2018 22:39:39 -0700 Subject: [PATCH 04/23] Update SettingsController --- app/Http/Controllers/SettingsController.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/app/Http/Controllers/SettingsController.php b/app/Http/Controllers/SettingsController.php index a41295007..730e0b4e9 100644 --- a/app/Http/Controllers/SettingsController.php +++ b/app/Http/Controllers/SettingsController.php @@ -149,11 +149,17 @@ class SettingsController extends Controller public function removeAccountPermanent(Request $request) { + if(config('pixelfed.account_deletion') == false) { + abort(404); + } return view('settings.remove.permanent'); } public function removeAccountPermanentSubmit(Request $request) { + if(config('pixelfed.account_deletion') == false) { + abort(404); + } $user = Auth::user(); if($user->is_admin == true) { return abort(400, 'You cannot delete an admin account.'); From b6757550f23b375e6d945d5c0d58b21279e2a02a Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Sat, 29 Dec 2018 22:41:51 -0700 Subject: [PATCH 05/23] Update Help Center --- resources/views/site/help/your-profile.blade.php | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/resources/views/site/help/your-profile.blade.php b/resources/views/site/help/your-profile.blade.php index 7354585ea..4d81698c3 100644 --- a/resources/views/site/help/your-profile.blade.php +++ b/resources/views/site/help/your-profile.blade.php @@ -140,7 +140,7 @@

- {{--
+

Delete Your Account

+ @if(config('pixelfed.account_delete_after') == false)
-

When you delete your account, your profile, photos, videos, comments, likes and followers will be permanently removed. If you'd just like to take a break, you can temporarily disable your account instead.

+

When you delete your account, your profile, photos, videos, comments, likes and followers will be permanently removed. If you'd just like to take a break, you can temporarily disable your account instead.

+ @else +
+

When you delete your account, your profile, photos, videos, comments, likes and followers will be permanently removed after {{config('pixelfed.account_delete_after')}} days. You can log in during that period to prevent your account from permanent deletion. If you'd just like to take a break, you can temporarily disable your account instead.

+
+ @endif

After you delete your account, you can't sign up again with the same username on this instance or add that username to another account on this instance, and we can't reactivate deleted accounts.

To permanently delete your account:

    @@ -178,5 +185,6 @@
-

--}} +

+ @endif @endsection \ No newline at end of file From c78686e355b59a93cde3e91a778050a04c27a2a7 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Sat, 29 Dec 2018 23:10:14 -0700 Subject: [PATCH 06/23] Add Announce validator and test --- app/Util/ActivityPub/Validator/Announce.php | 28 ++++ tests/Unit/ActivityPub/Verb/AnnounceTest.php | 168 +++++++++++++++++++ 2 files changed, 196 insertions(+) create mode 100644 app/Util/ActivityPub/Validator/Announce.php create mode 100644 tests/Unit/ActivityPub/Verb/AnnounceTest.php diff --git a/app/Util/ActivityPub/Validator/Announce.php b/app/Util/ActivityPub/Validator/Announce.php new file mode 100644 index 000000000..c66fedbb2 --- /dev/null +++ b/app/Util/ActivityPub/Validator/Announce.php @@ -0,0 +1,28 @@ + 'required', + 'id' => 'required|string', + 'type' => [ + 'required', + Rule::in(['Announce']) + ], + 'actor' => 'required|url|active_url', + 'published' => 'required|date', + 'to' => 'required', + 'cc' => 'required', + 'object' => 'required|url|active_url' + ])->passes(); + + return $valid; + } +} \ No newline at end of file diff --git a/tests/Unit/ActivityPub/Verb/AnnounceTest.php b/tests/Unit/ActivityPub/Verb/AnnounceTest.php new file mode 100644 index 000000000..c3e739692 --- /dev/null +++ b/tests/Unit/ActivityPub/Verb/AnnounceTest.php @@ -0,0 +1,168 @@ +validAnnounce = [ + "@context" => "https://www.w3.org/ns/activitystreams", + "id" => "https://example.org/users/alice/statuses/100000000000001/activity", + "type" => "Announce", + "actor" => "https://example.org/users/alice", + "published" => "2018-12-31T23:59:59Z", + "to" => [ + "https://www.w3.org/ns/activitystreams#Public" + ], + "cc" => [ + "https://example.org/users/bob", + "https://example.org/users/alice/followers" + ], + "object" => "https://example.org/p/bob/100000000000000", + ]; + + $this->invalidAnnounce = [ + "@context" => "https://www.w3.org/ns/activitystreams", + "id" => "https://example.org/users/alice/statuses/100000000000001/activity", + "type" => "Announce2", + "actor" => "https://example.org/users/alice", + "published" => "2018-12-31T23:59:59Z", + "to" => [ + "https://www.w3.org/ns/activitystreams#Public" + ], + "cc" => [ + "https://example.org/users/bob", + "https://example.org/users/alice/followers" + ], + "object" => "https://example.org/p/bob/100000000000000", + ]; + + $this->invalidDate = [ + "@context" => "https://www.w3.org/ns/activitystreams", + "id" => "https://example.org/users/alice/statuses/100000000000001/activity", + "type" => "Announce", + "actor" => "https://example.org/users/alice", + "published" => "2018-12-31T23:59:59ZEZE", + "to" => [ + "https://www.w3.org/ns/activitystreams#Public" + ], + "cc" => [ + "https://example.org/users/bob", + "https://example.org/users/alice/followers" + ], + "object" => "https://example.org/p/bob/100000000000000", + ]; + + $this->contextMissing = [ + "id" => "https://example.org/users/alice/statuses/100000000000001/activity", + "type" => "Announce", + "actor" => "https://example.org/users/alice", + "published" => "2018-12-31T23:59:59Z", + "to" => [ + "https://www.w3.org/ns/activitystreams#Public" + ], + "cc" => [ + "https://example.org/users/bob", + "https://example.org/users/alice/followers" + ], + "object" => "https://example.org/p/bob/100000000000000", + ]; + + $this->audienceMissing = [ + "id" => "https://example.org/users/alice/statuses/100000000000001/activity", + "type" => "Announce", + "actor" => "https://example.org/users/alice", + "published" => "2018-12-31T23:59:59Z", + "object" => "https://example.org/p/bob/100000000000000", + ]; + + $this->audienceMissing2 = [ + "@context" => "https://www.w3.org/ns/activitystreams", + "id" => "https://example.org/users/alice/statuses/100000000000001/activity", + "type" => "Announce", + "actor" => "https://example.org/users/alice", + "published" => "2018-12-31T23:59:59Z", + "to" => null, + "cc" => null, + "object" => "https://example.org/p/bob/100000000000000", + ]; + + $this->invalidActor = [ + "@context" => "https://www.w3.org/ns/activitystreams", + "id" => "https://example.org/users/alice/statuses/100000000000001/activity", + "type" => "Announce", + "actor" => "10000", + "published" => "2018-12-31T23:59:59Z", + "to" => [ + "https://www.w3.org/ns/activitystreams#Public" + ], + "cc" => [ + "https://example.org/users/bob", + "https://example.org/users/alice/followers" + ], + "object" => "https://example.org/p/bob/100000000000000", + ]; + + $this->invalidActor2 = [ + "@context" => "https://www.w3.org/ns/activitystreams", + "id" => "https://example.org/users/alice/statuses/100000000000001/activity", + "type" => "Announce", + "published" => "2018-12-31T23:59:59Z", + "to" => [ + "https://www.w3.org/ns/activitystreams#Public" + ], + "cc" => [ + "https://example.org/users/bob", + "https://example.org/users/alice/followers" + ], + "object" => "https://example.org/p/bob/100000000000000", + ]; + } + + /** @test */ + public function basic_accept() + { + $this->assertTrue(Announce::validate($this->validAnnounce)); + } + + /** @test */ + public function invalid_accept() + { + $this->assertFalse(Announce::validate($this->invalidAnnounce)); + } + + /** @test */ + public function invalid_date() + { + $this->assertFalse(Announce::validate($this->invalidDate)); + } + + /** @test */ + public function context_missing() + { + $this->assertFalse(Announce::validate($this->contextMissing)); + } + + /** @test */ + public function audience_missing() + { + $this->assertFalse(Announce::validate($this->audienceMissing)); + $this->assertFalse(Announce::validate($this->audienceMissing2)); + } + + /** @test */ + public function invalid_actor() + { + $this->assertFalse(Announce::validate($this->invalidActor)); + $this->assertFalse(Announce::validate($this->invalidActor2)); + } +} From 982aecb4cc3984b1ba7f5ca07cc9537ec984ee92 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Sun, 30 Dec 2018 13:51:42 -0700 Subject: [PATCH 07/23] Add new migration --- ...update_profiles_table_use_text_for_bio.php | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 database/migrations/2018_12_30_065102_update_profiles_table_use_text_for_bio.php diff --git a/database/migrations/2018_12_30_065102_update_profiles_table_use_text_for_bio.php b/database/migrations/2018_12_30_065102_update_profiles_table_use_text_for_bio.php new file mode 100644 index 000000000..96443631a --- /dev/null +++ b/database/migrations/2018_12_30_065102_update_profiles_table_use_text_for_bio.php @@ -0,0 +1,32 @@ +text('bio')->nullable()->change(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('profiles', function (Blueprint $table) { + $table->string('bio')->nullable()->change(); + }); + } +} From 547ac5c8f9a85585331c1e6e540698aeed8b3798 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Sun, 30 Dec 2018 21:26:37 -0700 Subject: [PATCH 08/23] Add/update API transformers --- app/Transformer/Api/AccountTransformer.php | 46 +++++++++---------- .../Api/ApplicationTransformer.php | 14 +++--- app/Transformer/Api/AttachmentTransformer.php | 28 +++++++++++ app/Transformer/Api/ContextTransformer.php | 16 +++++++ app/Transformer/Api/EmojiTransformer.php | 18 ++++---- app/Transformer/Api/FilterTransformer.php | 20 ++++++++ app/Transformer/Api/HashtagTransformer.php | 14 +++--- app/Transformer/Api/MediaTransformer.php | 28 +++++------ app/Transformer/Api/ResultsTransformer.php | 24 ++++++++++ 9 files changed, 148 insertions(+), 60 deletions(-) create mode 100644 app/Transformer/Api/AttachmentTransformer.php create mode 100644 app/Transformer/Api/ContextTransformer.php create mode 100644 app/Transformer/Api/FilterTransformer.php create mode 100644 app/Transformer/Api/ResultsTransformer.php diff --git a/app/Transformer/Api/AccountTransformer.php b/app/Transformer/Api/AccountTransformer.php index 45ff02564..352894e77 100644 --- a/app/Transformer/Api/AccountTransformer.php +++ b/app/Transformer/Api/AccountTransformer.php @@ -7,27 +7,27 @@ use League\Fractal; class AccountTransformer extends Fractal\TransformerAbstract { - public function transform(Profile $profile) - { - return [ - 'id' => $profile->id, - 'username' => $profile->username, - 'acct' => $profile->username, - 'display_name' => $profile->name, - 'locked' => (bool) $profile->is_private, - 'created_at' => $profile->created_at->format('c'), - 'followers_count' => $profile->followerCount(), - 'following_count' => $profile->followingCount(), - 'statuses_count' => $profile->statusCount(), - 'note' => $profile->bio, - 'url' => $profile->url(), - 'avatar' => $profile->avatarUrl(), - 'avatar_static' => $profile->avatarUrl(), - 'header' => null, - 'header_static' => null, - 'moved' => null, - 'fields' => null, - 'bot' => null, - ]; - } + public function transform(Profile $profile) + { + return [ + 'id' => $profile->id, + 'username' => $profile->username, + 'acct' => $profile->username, + 'display_name' => $profile->name, + 'locked' => (bool) $profile->is_private, + 'created_at' => $profile->created_at->format('c'), + 'followers_count' => $profile->followerCount(), + 'following_count' => $profile->followingCount(), + 'statuses_count' => $profile->statusCount(), + 'note' => $profile->bio, + 'url' => $profile->url(), + 'avatar' => $profile->avatarUrl(), + 'avatar_static' => $profile->avatarUrl(), + 'header' => null, + 'header_static' => null, + 'moved' => null, + 'fields' => null, + 'bot' => null, + ]; + } } diff --git a/app/Transformer/Api/ApplicationTransformer.php b/app/Transformer/Api/ApplicationTransformer.php index 23e29afd5..158fe9ae1 100644 --- a/app/Transformer/Api/ApplicationTransformer.php +++ b/app/Transformer/Api/ApplicationTransformer.php @@ -6,11 +6,11 @@ use League\Fractal; class ApplicationTransformer extends Fractal\TransformerAbstract { - public function transform() - { - return [ - 'name' => '', - 'website' => null, - ]; - } + public function transform() + { + return [ + 'name' => '', + 'website' => null, + ]; + } } diff --git a/app/Transformer/Api/AttachmentTransformer.php b/app/Transformer/Api/AttachmentTransformer.php new file mode 100644 index 000000000..2e1be8449 --- /dev/null +++ b/app/Transformer/Api/AttachmentTransformer.php @@ -0,0 +1,28 @@ + $media->id, + 'type' => $media->activityVerb(), + 'url' => $media->url(), + 'remote_url' => null, + 'preview_url' => $media->thumbnailUrl(), + 'text_url' => null, + 'meta' => null, + 'description' => $media->caption, + 'license' => $media->license, + 'is_nsfw' => $media->is_nsfw, + 'orientation' => $media->orientation, + 'filter_name' => $media->filter_name, + 'filter_class' => $media->filter_class, + 'mime' => $media->mime, + ]; + } +} diff --git a/app/Transformer/Api/ContextTransformer.php b/app/Transformer/Api/ContextTransformer.php new file mode 100644 index 000000000..0a6c7822b --- /dev/null +++ b/app/Transformer/Api/ContextTransformer.php @@ -0,0 +1,16 @@ + [], + 'descendants' => [] + ]; + } +} diff --git a/app/Transformer/Api/EmojiTransformer.php b/app/Transformer/Api/EmojiTransformer.php index 0d7fd10f7..93c7437cc 100644 --- a/app/Transformer/Api/EmojiTransformer.php +++ b/app/Transformer/Api/EmojiTransformer.php @@ -6,13 +6,13 @@ use League\Fractal; class EmojiTransformer extends Fractal\TransformerAbstract { - public function transform($emoji) - { - return [ - 'shortcode' => '', - 'static_url' => '', - 'url' => '', - 'visible_in_picker' => false - ]; - } + public function transform($emoji) + { + return [ + 'shortcode' => '', + 'static_url' => '', + 'url' => '', + 'visible_in_picker' => false + ]; + } } diff --git a/app/Transformer/Api/FilterTransformer.php b/app/Transformer/Api/FilterTransformer.php new file mode 100644 index 000000000..92a6d7d7d --- /dev/null +++ b/app/Transformer/Api/FilterTransformer.php @@ -0,0 +1,20 @@ + (string) '', + 'phrase' => (string) '', + 'context' => [], + 'expires_at' => null, + 'irreversible' => (bool) false, + 'whole_word' => (bool) false + ]; + } +} diff --git a/app/Transformer/Api/HashtagTransformer.php b/app/Transformer/Api/HashtagTransformer.php index 153c311cc..b11c0e3b8 100644 --- a/app/Transformer/Api/HashtagTransformer.php +++ b/app/Transformer/Api/HashtagTransformer.php @@ -7,11 +7,11 @@ use League\Fractal; class HashtagTransformer extends Fractal\TransformerAbstract { - public function transform(Hashtag $hashtag) - { - return [ - 'name' => $hashtag->name, - 'url' => $hashtag->url(), - ]; - } + public function transform(Hashtag $hashtag) + { + return [ + 'name' => $hashtag->name, + 'url' => $hashtag->url(), + ]; + } } diff --git a/app/Transformer/Api/MediaTransformer.php b/app/Transformer/Api/MediaTransformer.php index 8ab38fc6f..2920bea1e 100644 --- a/app/Transformer/Api/MediaTransformer.php +++ b/app/Transformer/Api/MediaTransformer.php @@ -10,20 +10,20 @@ class MediaTransformer extends Fractal\TransformerAbstract public function transform(Media $media) { return [ - 'id' => $media->id, - 'type' => $media->activityVerb(), - 'url' => $media->url(), - 'remote_url' => null, - 'preview_url' => $media->thumbnailUrl(), - 'text_url' => null, - 'meta' => null, - 'description' => $media->caption, - 'license' => $media->license, - 'is_nsfw' => $media->is_nsfw, - 'orientation' => $media->orientation, - 'filter_name' => $media->filter_name, - 'filter_class' => $media->filter_class, - 'mime' => $media->mime, + 'id' => $media->id, + 'type' => $media->activityVerb(), + 'url' => $media->url(), + 'remote_url' => null, + 'preview_url' => $media->thumbnailUrl(), + 'text_url' => null, + 'meta' => null, + 'description' => $media->caption, + 'license' => $media->license, + 'is_nsfw' => $media->is_nsfw, + 'orientation' => $media->orientation, + 'filter_name' => $media->filter_name, + 'filter_class' => $media->filter_class, + 'mime' => $media->mime, ]; } } diff --git a/app/Transformer/Api/ResultsTransformer.php b/app/Transformer/Api/ResultsTransformer.php new file mode 100644 index 000000000..ea2473605 --- /dev/null +++ b/app/Transformer/Api/ResultsTransformer.php @@ -0,0 +1,24 @@ + [], + 'statuses' => [], + 'hashtags' => [] + ]; + } +} From ac27365a637facb34ce4506baa514892e423075a Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Sun, 30 Dec 2018 21:30:57 -0700 Subject: [PATCH 09/23] Add laravel passport --- app/Providers/AuthServiceProvider.php | 7 ++++++- config/auth.php | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/app/Providers/AuthServiceProvider.php b/app/Providers/AuthServiceProvider.php index 9e68caa6f..dbbbece8e 100644 --- a/app/Providers/AuthServiceProvider.php +++ b/app/Providers/AuthServiceProvider.php @@ -3,6 +3,7 @@ namespace App\Providers; use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider; +use Laravel\Passport\Passport; class AuthServiceProvider extends ServiceProvider { @@ -24,6 +25,10 @@ class AuthServiceProvider extends ServiceProvider { $this->registerPolicies(); - // + Passport::routes(); + + Passport::tokensExpireIn(now()->addDays(15)); + + Passport::refreshTokensExpireIn(now()->addDays(30)); } } diff --git a/config/auth.php b/config/auth.php index a9264b4a2..3b50d4c1a 100644 --- a/config/auth.php +++ b/config/auth.php @@ -42,7 +42,7 @@ return [ ], 'api' => [ - 'driver' => 'token', + 'driver' => 'passport', 'provider' => 'users', ], ], From 067a2db5d0261f1cf4fd014aa6312dc88e08c563 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Sun, 30 Dec 2018 21:31:57 -0700 Subject: [PATCH 10/23] Add scoped css to vue components --- resources/assets/js/components/PostComments.vue | 2 +- resources/assets/js/components/PostComponent.vue | 2 +- resources/assets/js/components/Timeline.vue | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/resources/assets/js/components/PostComments.vue b/resources/assets/js/components/PostComments.vue index fc9990c1d..152feb3c1 100644 --- a/resources/assets/js/components/PostComments.vue +++ b/resources/assets/js/components/PostComments.vue @@ -1,4 +1,4 @@ -