From 18cd857e90f62195c130cfa24b9b1165ca05dce2 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Wed, 22 Aug 2018 00:56:16 -0600 Subject: [PATCH 1/4] Update AccountController --- app/Http/Controllers/AccountController.php | 106 ++++++++++++++++++++- 1 file changed, 105 insertions(+), 1 deletion(-) diff --git a/app/Http/Controllers/AccountController.php b/app/Http/Controllers/AccountController.php index d3abf4dc8..76a47e938 100644 --- a/app/Http/Controllers/AccountController.php +++ b/app/Http/Controllers/AccountController.php @@ -6,10 +6,21 @@ use Illuminate\Http\Request; use Carbon\Carbon; use App\Mail\ConfirmEmail; use Auth, DB, Cache, Mail, Redis; -use App\{EmailVerification, Notification, Profile, User}; +use App\{ + EmailVerification, + Notification, + Profile, + User, + UserFilter +}; class AccountController extends Controller { + protected $filters = [ + 'user.mute', + 'user.block' + ]; + public function __construct() { $this->middleware('auth'); @@ -134,4 +145,97 @@ class AccountController extends Controller return $notifications; } + public function messages() + { + return view('account.messages'); + } + + + public function showMessage(Request $request, $id) + { + return view('account.message'); + } + + public function mute(Request $request) + { + $this->validate($request, [ + 'type' => 'required|string', + 'item' => 'required|integer|min:1' + ]); + + $user = Auth::user()->profile; + $type = $request->input('type'); + $item = $request->input('item'); + $action = "{$type}.mute"; + + if(!in_array($action, $this->filters)) { + return abort(406); + } + $filterable = []; + switch ($type) { + case 'user': + $profile = Profile::findOrFail($item); + if($profile->id == $user->id) { + return abort(403); + } + $class = get_class($profile); + $filterable['id'] = $profile->id; + $filterable['type'] = $class; + break; + + default: + # code... + break; + } + + $filter = UserFilter::firstOrCreate([ + 'user_id' => $user->id, + 'filterable_id' => $filterable['id'], + 'filterable_type' => $filterable['type'], + 'filter_type' => 'mute' + ]); + + return redirect()->back(); + + } + + public function block(Request $request) + { + $this->validate($request, [ + 'type' => 'required|string', + 'item' => 'required|integer|min:1' + ]); + + $user = Auth::user()->profile; + $type = $request->input('type'); + $item = $request->input('item'); + $action = "{$type}.block"; + if(!in_array($action, $this->filters)) { + return abort(406); + } + $filterable = []; + switch ($type) { + case 'user': + $profile = Profile::findOrFail($item); + $class = get_class($profile); + $filterable['id'] = $profile->id; + $filterable['type'] = $class; + break; + + default: + # code... + break; + } + + $filter = UserFilter::firstOrCreate([ + 'user_id' => $user->id, + 'filterable_id' => $filterable['id'], + 'filterable_type' => $filterable['type'], + 'filter_type' => 'block' + ]); + + return redirect()->back(); + + } + } From c7489a46c9bb5773686848875485dec121232540 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Wed, 22 Aug 2018 22:23:19 -0600 Subject: [PATCH 2/4] Update UserFilter model --- app/UserFilter.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/app/UserFilter.php b/app/UserFilter.php index 071f2eeb4..41edd5398 100644 --- a/app/UserFilter.php +++ b/app/UserFilter.php @@ -6,5 +6,10 @@ use Illuminate\Database\Eloquent\Model; class UserFilter extends Model { - // + protected $fillable = [ + 'user_id', + 'filterable_id', + 'filterable_type', + 'filter_type' + ]; } From 814b959c3fd007e18432816a776861cb8685d75c Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Wed, 22 Aug 2018 22:28:26 -0600 Subject: [PATCH 3/4] Update navbar --- resources/views/layouts/partial/nav.blade.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/views/layouts/partial/nav.blade.php b/resources/views/layouts/partial/nav.blade.php index ffe87c815..28e9c485a 100644 --- a/resources/views/layouts/partial/nav.blade.php +++ b/resources/views/layouts/partial/nav.blade.php @@ -30,7 +30,7 @@ From b3827566a28ef314235f84f420724e14bfd57926 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Wed, 22 Aug 2018 22:30:53 -0600 Subject: [PATCH 4/4] Update tests --- tests/Feature/ExampleTest.php | 21 --------------------- tests/Feature/InstalledTest.php | 29 +++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 21 deletions(-) delete mode 100644 tests/Feature/ExampleTest.php create mode 100644 tests/Feature/InstalledTest.php diff --git a/tests/Feature/ExampleTest.php b/tests/Feature/ExampleTest.php deleted file mode 100644 index f31e495ca..000000000 --- a/tests/Feature/ExampleTest.php +++ /dev/null @@ -1,21 +0,0 @@ -get('/'); - - $response->assertStatus(200); - } -} diff --git a/tests/Feature/InstalledTest.php b/tests/Feature/InstalledTest.php new file mode 100644 index 000000000..0f9aa6d6b --- /dev/null +++ b/tests/Feature/InstalledTest.php @@ -0,0 +1,29 @@ +get('/'); + $response + ->assertStatus(200) + ->assertSeeText('Image Sharing for Everyone'); + } + + public function testNodeinfoTest() + { + $response = $this->get('/.well-known/nodeinfo'); + $response + ->assertStatus(200) + ->assertJson([ + "links" => [ + ["rel" => "http://nodeinfo.diaspora.software/ns/schema/2.0"] + ]]); + } +}