Skip to content

Commit

Permalink
✨ Added possibility to remove followers (#219)
Browse files Browse the repository at this point in the history
* Added possibility to remove followers

* Adde translation

* Added link to profile

* Show user- and displayname

* Added translation

* Improved UI when user have no followers
  • Loading branch information
MrKrisKrisu authored Feb 19, 2021
1 parent e5e66cf commit b2e78d3
Show file tree
Hide file tree
Showing 12 changed files with 266 additions and 45 deletions.
2 changes: 2 additions & 0 deletions .idea/php.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions .idea/trwl.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 33 additions & 0 deletions app/Http/Controllers/SettingsController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

namespace App\Http\Controllers;

use App\Models\Follow;
use Illuminate\Contracts\Support\Renderable;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Validation\Rule;

class SettingsController extends Controller
{
public function renderFollowerSettings(): Renderable {
return view('settings.follower', [
'followers' => 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'));
}
}
2 changes: 1 addition & 1 deletion app/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
87 changes: 87 additions & 0 deletions app/Policies/FollowPolicy.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
<?php

namespace App\Policies;

use App\Models\Follow;
use App\Models\User;
use Illuminate\Auth\Access\HandlesAuthorization;

class FollowPolicy
{
use HandlesAuthorization;

/**
* Determine whether the user can view any models.
*
* @param User $user
* @return mixed
*/
public function viewAny(User $user) {
//
}

/**
* Determine whether the user can view the model.
*
* @param User $user
* @param Follow $follow
* @return mixed
*/
public function view(User $user, Follow $follow) {
//
}

/**
* Determine whether the user can create models.
*
* @param User $user
* @return mixed
*/
public function create(User $user) {
//
}

/**
* Determine whether the user can update the model.
*
* @param User $user
* @param Follow $follow
* @return mixed
*/
public function update(User $user, Follow $follow) {
//
}

/**
* Determine whether the user can delete the model.
*
* @param User $user
* @param Follow $follow
* @return mixed
*/
public function delete(User $user, Follow $follow): bool {
return $user->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) {
//
}
}
43 changes: 22 additions & 21 deletions resources/lang/de/menu.php
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
<?php
return [
"abort" => "Abbrechen",
"about" => "Über Träwelling",
"active" => "Unterwegs",
"blog" => "Blog",
"dashboard" => "Dashboard",
"developed" => "Entwickelt mit <i class=\"fas fa-heart fa-sm\" style=\"color: Tomato;\"\"></i> in der Europäischen Union. <a href='https://github.com/traewelling/traewelling'>Quellcode</a> lizensiert unter <a href='https://www.gnu.org/licenses/agpl-3.0.html'>AGPLv3</a>.",
"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 <i class=\"fas fa-heart fa-sm\" style=\"color: Tomato;\"\"></i> in der Europäischen Union. <a href='https://github.com/traewelling/traewelling'>Quellcode</a> lizensiert unter <a href='https://www.gnu.org/licenses/agpl-3.0.html'>AGPLv3</a>.",
"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"
];
7 changes: 7 additions & 0 deletions resources/lang/de/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
],
];
43 changes: 22 additions & 21 deletions resources/lang/en/menu.php
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
<?php
return [
"abort" => "Abort",
"about" => "About",
"active" => "En Route",
"blog" => "Blog",
"dashboard" => "Dashboard",
"developed" => "Developed with <i class=\"fas fa-heart fa-sm\" style=\"color: Tomato;\"\"></i> in the European Union. <a href='https://github.com/traewelling/traewelling'>Source code</a> licensed under <a href='https://www.gnu.org/licenses/agpl-3.0.html'>AGPLv3</a>.",
"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 <i class=\"fas fa-heart fa-sm\" style=\"color: Tomato;\"\"></i> in the European Union. <a href='https://github.com/traewelling/traewelling'>Source code</a> licensed under <a href='https://www.gnu.org/licenses/agpl-3.0.html'>AGPLv3</a>.",
"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"
];
7 changes: 7 additions & 0 deletions resources/lang/en/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
],
];
8 changes: 6 additions & 2 deletions resources/views/settings.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,10 @@ class="custom-control-input @error('private_profile') is-invalid @enderror"
<label class="custom-control-label"
for="private_profile">{{ __('user.private-profile') }}</label>
</div>
<br/>
<a href="{{route('settings.follower')}}">
{{__('settings.follower.manage')}}
</a>
@error('email')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
Expand Down Expand Up @@ -381,9 +385,9 @@ class="fab fa-mastodon"></i> {{ __('settings.connect') }}
</div>
</div>

@include('settings.cards.ics')
@include('settings.cards.ics')

<!-- API Tokens -->
<!-- API Tokens -->
<div class="card mt-3">
<div class="card-header">{{ __('settings.title-tokens') }}</div>

Expand Down
72 changes: 72 additions & 0 deletions resources/views/settings/follower.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
@extends('layouts.app')

@section('title') {{ __('menu.settings-myFollower') }} @endsection

@section('content')
<div class="container">
<div class="row justify-content-center">
<div class="col-md-8">
<div class="card">
<div class="card-header">{{ __('menu.settings-myFollower') }}</div>

<div class="card-body">

@if($followers->count() == 0)
<b class="text-danger">
<i class="fas fa-users-slash"></i>
{{__('settings.follower.no-follower')}}
</b>
@else

<table class="table table-responsive table-striped">
<thead>
<tr>
<th colspan="2">Follower</th>
<th>{{__('settings.follower.following-since')}}</th>
<th></th>
</tr>
</thead>
<tbody>
@foreach($followers as $follower)
<tr>
<td>
<div class="image-box pr-0 d-none d-lg-flex">
<a href="{{ route('account.show', ['username' => $follower->username]) }}">
<img src="{{ route('account.showProfilePicture', ['username' => $follower->username]) }}"
style="height: 3em;"
/>
</a>
</div>
</td>
<td style="vertical-align: middle">
<a href="{{route('account.show', ['username' => $follower->username])}}">
{{$follower->name}}
@if($follower->name != $follower->username)
<br/>
<small>{{'@' . $follower->username}}</small>
@endif
</a>
</td>
<td style="vertical-align: middle">{{$follower->created_at->diffForHumans()}}</td>
<td>
<form method="POST" action="{{route('settings.follower.remove')}}">
@csrf
<input type="hidden" name="user_id" value="{{$follower->id}}"/>
<button type="submit" class="btn btn-sm btn-danger">
<i class="fas fa-users-slash"></i>
{{__('settings.follower.delete')}}
</button>
</form>
</td>
</tr>
@endforeach
</tbody>
</table>
{{$followers->links()}}
@endif
</div>
</div>
</div>
</div>
</div>
@endsection
5 changes: 5 additions & 0 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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');
Expand Down

0 comments on commit b2e78d3

Please sign in to comment.