From b2e78d3cd8601abc23de4748e1cdc00010d272cf Mon Sep 17 00:00:00 2001 From: Kris Date: Fri, 19 Feb 2021 14:28:00 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Added=20possibility=20to=20remove?= =?UTF-8?q?=20followers=20(#219)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Added possibility to remove followers * Adde translation * Added link to profile * Show user- and displayname * Added translation * Improved UI when user have no followers --- .idea/php.xml | 2 + .idea/trwl.iml | 2 + app/Http/Controllers/SettingsController.php | 33 ++++++++ app/Models/User.php | 2 +- app/Policies/FollowPolicy.php | 87 +++++++++++++++++++++ resources/lang/de/menu.php | 43 +++++----- resources/lang/de/settings.php | 7 ++ resources/lang/en/menu.php | 43 +++++----- resources/lang/en/settings.php | 7 ++ resources/views/settings.blade.php | 8 +- resources/views/settings/follower.blade.php | 72 +++++++++++++++++ routes/web.php | 5 ++ 12 files changed, 266 insertions(+), 45 deletions(-) create mode 100644 app/Http/Controllers/SettingsController.php create mode 100644 app/Policies/FollowPolicy.php create mode 100644 resources/views/settings/follower.blade.php diff --git a/.idea/php.xml b/.idea/php.xml index ae24db6d3..a338b5360 100644 --- a/.idea/php.xml +++ b/.idea/php.xml @@ -166,6 +166,8 @@ + + diff --git a/.idea/trwl.iml b/.idea/trwl.iml index 9fe0cd3aa..a188e5043 100644 --- a/.idea/trwl.iml +++ b/.idea/trwl.iml @@ -144,6 +144,8 @@ + + diff --git a/app/Http/Controllers/SettingsController.php b/app/Http/Controllers/SettingsController.php new file mode 100644 index 000000000..0fa062c16 --- /dev/null +++ b/app/Http/Controllers/SettingsController.php @@ -0,0 +1,33 @@ + auth()->user()->followers()->paginate(15) + ]); + } + + public function removeFollower(Request $request): RedirectResponse { + $validated = $request->validate([ + 'user_id' => ['required', Rule::in(auth()->user()->followers->pluck('id'))] + ]); + + $follow = Follow::where('user_id', $validated['user_id']) + ->where('follow_id', auth()->user()->id) + ->firstOrFail(); + + $this->authorize('delete', $follow); + $follow->delete(); + + return back()->with('success', __('settings.follower.delete-success')); + } +} diff --git a/app/Models/User.php b/app/Models/User.php index ceb932026..fde8220dc 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -56,7 +56,7 @@ public function follows(): BelongsToMany { } public function followers(): BelongsToMany { - return $this->belongsToMany(User::class, 'follows', 'user_id', 'user_id'); + return $this->belongsToMany(User::class, 'follows', 'follow_id', 'user_id'); } public function sessions(): HasMany { diff --git a/app/Policies/FollowPolicy.php b/app/Policies/FollowPolicy.php new file mode 100644 index 000000000..207dc22e7 --- /dev/null +++ b/app/Policies/FollowPolicy.php @@ -0,0 +1,87 @@ +id == $follow->follow_id; + } + + /** + * Determine whether the user can restore the model. + * + * @param User $user + * @param Follow $follow + * @return mixed + */ + public function restore(User $user, Follow $follow) { + // + } + + /** + * Determine whether the user can permanently delete the model. + * + * @param User $user + * @param Follow $follow + * @return mixed + */ + public function forceDelete(User $user, Follow $follow) { + // + } +} diff --git a/resources/lang/de/menu.php b/resources/lang/de/menu.php index afcbb306f..a3af6d4d4 100644 --- a/resources/lang/de/menu.php +++ b/resources/lang/de/menu.php @@ -1,24 +1,25 @@ "Abbrechen", - "about" => "Über Träwelling", - "active" => "Unterwegs", - "blog" => "Blog", - "dashboard" => "Dashboard", - "developed" => "Entwickelt mit in der Europäischen Union. Quellcode lizensiert unter AGPLv3.", - "discard" => "Abbrechen", - "export" => "Exportieren", - "globaldashboard" => "Globales Dashboard", - "gohome" => "Zur Startseite", - "imprint" => "Impressum", - "leaderboard" => "Top-Träweller", - "login" => "Anmelden", - "logout" => "Abmelden", - "ohno" => "Oh nein!", - "privacy" => "Datenschutz", - "profile" => "Profil", - "register" => "Registrieren", - "settings" => "Einstellungen", - "admin" => "Admin-Panel", - "readmore" => "Mehr lesen" + "abort" => "Abbrechen", + "about" => "Über Träwelling", + "active" => "Unterwegs", + "blog" => "Blog", + "dashboard" => "Dashboard", + "developed" => "Entwickelt mit in der Europäischen Union. Quellcode lizensiert unter AGPLv3.", + "discard" => "Abbrechen", + "export" => "Exportieren", + "globaldashboard" => "Globales Dashboard", + "gohome" => "Zur Startseite", + "imprint" => "Impressum", + "leaderboard" => "Top-Träweller", + "login" => "Anmelden", + "logout" => "Abmelden", + "ohno" => "Oh nein!", + "privacy" => "Datenschutz", + "profile" => "Profil", + "register" => "Registrieren", + "settings" => "Einstellungen", + "settings-myFollower" => "Meine Follower", + "admin" => "Admin-Panel", + "readmore" => "Mehr lesen" ]; diff --git a/resources/lang/de/settings.php b/resources/lang/de/settings.php index e3929b230..d4ba1e353 100644 --- a/resources/lang/de/settings.php +++ b/resources/lang/de/settings.php @@ -46,4 +46,11 @@ "create-ics-token" => "Neue Freigabe erstellen", "create-ics-token-success" => "Die Kalenderfreigabe wurde erstellt. Du kannst folgenden Link in einen Kalender einbinden, der das ICS-Format unterstützt: :link", "revoke-ics-token-success" => "Die Kalenderfreigabe wurde gelöscht.", + 'follower' => [ + 'no-follower' => 'Du hast keine Follower.', + 'manage' => 'Follower verwalten', + 'following-since' => 'Folgt dir seit', + 'delete-success' => 'Du hast den Follower erfolgreich entfernt.', + 'delete' => 'Follower entfernen', + ], ]; diff --git a/resources/lang/en/menu.php b/resources/lang/en/menu.php index b2cad58a3..bb441a7a6 100644 --- a/resources/lang/en/menu.php +++ b/resources/lang/en/menu.php @@ -1,24 +1,25 @@ "Abort", - "about" => "About", - "active" => "En Route", - "blog" => "Blog", - "dashboard" => "Dashboard", - "developed" => "Developed with in the European Union. Source code licensed under AGPLv3.", - "discard" => "Discard", - "export" => "Export", - "globaldashboard" => "Global Dashboard", - "gohome" => "Go Home", - "imprint" => "Imprint", - "leaderboard" => "Leaderboard", - "login" => "Login", - "logout" => "Logout", - "ohno" => "Oh no", - "privacy" => "Privacy", - "profile" => "Profile", - "register" => "Register", - "settings" => "Settings", - "admin" => "Admin-Panel", - "readmore" => "Read more" + "abort" => "Abort", + "about" => "About", + "active" => "En Route", + "blog" => "Blog", + "dashboard" => "Dashboard", + "developed" => "Developed with in the European Union. Source code licensed under AGPLv3.", + "discard" => "Discard", + "export" => "Export", + "globaldashboard" => "Global Dashboard", + "gohome" => "Go Home", + "imprint" => "Imprint", + "leaderboard" => "Leaderboard", + "login" => "Login", + "logout" => "Logout", + "ohno" => "Oh no", + "privacy" => "Privacy", + "profile" => "Profile", + "register" => "Register", + "settings" => "Settings", + "settings-myFollower" => "My followers", + "admin" => "Admin-Panel", + "readmore" => "Read more" ]; diff --git a/resources/lang/en/settings.php b/resources/lang/en/settings.php index 1f518b96a..012efe9a0 100644 --- a/resources/lang/en/settings.php +++ b/resources/lang/en/settings.php @@ -46,4 +46,11 @@ "create-ics-token" => "Create new token", "create-ics-token-success" => "The calendar token has been created. You can embed it with the following link to every software which support ICS files: :link", "revoke-ics-token-success" => "The calendar token has been revoked.", + 'follower' => [ + 'no-follower' => 'You don\'t have any followers.', + 'manage' => 'Manage followers', + 'following-since' => 'Following since', + 'delete-success' => 'You successfully removed the follower.', + 'delete' => 'Remove follower', + ], ]; diff --git a/resources/views/settings.blade.php b/resources/views/settings.blade.php index 723a45d68..7a39f0996 100644 --- a/resources/views/settings.blade.php +++ b/resources/views/settings.blade.php @@ -121,6 +121,10 @@ class="custom-control-input @error('private_profile') is-invalid @enderror" +
+ + {{__('settings.follower.manage')}} + @error('email') {{ $message }} @@ -381,9 +385,9 @@ class="fab fa-mastodon"> {{ __('settings.connect') }} - @include('settings.cards.ics') + @include('settings.cards.ics') - +
{{ __('settings.title-tokens') }}
diff --git a/resources/views/settings/follower.blade.php b/resources/views/settings/follower.blade.php new file mode 100644 index 000000000..d5393a5f0 --- /dev/null +++ b/resources/views/settings/follower.blade.php @@ -0,0 +1,72 @@ +@extends('layouts.app') + +@section('title') {{ __('menu.settings-myFollower') }} @endsection + +@section('content') +
+
+
+
+
{{ __('menu.settings-myFollower') }}
+ +
+ + @if($followers->count() == 0) + + + {{__('settings.follower.no-follower')}} + + @else + + + + + + + + + + + @foreach($followers as $follower) + + + + + + + @endforeach + +
Follower{{__('settings.follower.following-since')}}
+
+ + + +
+
+ + {{$follower->name}} + @if($follower->name != $follower->username) +
+ {{'@' . $follower->username}} + @endif +
+
{{$follower->created_at->diffForHumans()}} +
+ @csrf + + +
+
+ {{$followers->links()}} + @endif +
+
+
+
+
+@endsection diff --git a/routes/web.php b/routes/web.php index df3bd8f35..215b5d5f8 100644 --- a/routes/web.php +++ b/routes/web.php @@ -20,6 +20,7 @@ use App\Http\Controllers\IcsController; use App\Http\Controllers\NotificationController; use App\Http\Controllers\PrivacyAgreementController; +use App\Http\Controllers\SettingsController; use App\Http\Controllers\SocialController; use App\Http\Controllers\UserController; use Illuminate\Support\Facades\Auth; @@ -138,8 +139,12 @@ //will leave settings inside of UserController... Route::get('/settings', [UserController::class, 'getAccount']) ->name('settings'); + Route::get('/settings/follower', [SettingsController::class, 'renderFollowerSettings']) + ->name('settings.follower'); Route::post('/settings', [UserController::class, 'updateSettings']); + Route::post('/settings/follower/remove', [SettingsController::class, 'removeFollower']) + ->name('settings.follower.remove'); Route::post('/settings/uploadProfileImage', [FrontendUserController::class, 'updateProfilePicture']) ->name('settings.upload-image');