From 62a0d1827eece2307695c04ca2f79353384af5e6 Mon Sep 17 00:00:00 2001 From: Neil Farrington Date: Sat, 21 Apr 2018 18:33:38 -0400 Subject: [PATCH] Fix displaying organization URLs --- app/Http/Controllers/Platform/UrlController.php | 6 ++---- app/Models/Url.php | 2 +- tests/Feature/Platform/UrlTest.php | 13 +++++++++++-- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/app/Http/Controllers/Platform/UrlController.php b/app/Http/Controllers/Platform/UrlController.php index 35eae86..ab52068 100644 --- a/app/Http/Controllers/Platform/UrlController.php +++ b/app/Http/Controllers/Platform/UrlController.php @@ -31,10 +31,8 @@ public function __construct() public function index(Request $request) { $urls = Url::where('user_id', $request->user()->id) - ->where(function ($query) use ($request) { - $query->whereIn('organization_id', $request->user()->organizations()->pluck('organizations.id')) - ->orWhereNull('organization_id'); - })->join('domains', 'urls.domain_id', 'domains.id') + ->orWhereIn('organization_id', $request->user()->organizations()->pluck('organizations.id')) + ->join('domains', 'urls.domain_id', 'domains.id') ->orderBy('organization_id') ->orderBy('domains.url') ->orderBy('urls.url') diff --git a/app/Models/Url.php b/app/Models/Url.php index 2bea984..8f4a0a2 100644 --- a/app/Models/Url.php +++ b/app/Models/Url.php @@ -104,6 +104,6 @@ public function getFullUrlAttribute() */ public function scopePublic($query) { - return $query->whereNull('user_id'); + return $query->whereNull('user_id')->whereNull('organization_id'); } } diff --git a/tests/Feature/Platform/UrlTest.php b/tests/Feature/Platform/UrlTest.php index d5d908d..db213b9 100644 --- a/tests/Feature/Platform/UrlTest.php +++ b/tests/Feature/Platform/UrlTest.php @@ -26,9 +26,18 @@ function index_page_loads_successfully() { $this->get(route('platform.urls.index')) ->assertStatus(200); - create(Url::class, ['user_id' => $this->user->id]); + + $url = create(Url::class, ['user_id' => $this->user->id]); $this->get(route('platform.urls.index')) - ->assertStatus(200); + ->assertStatus(200) + ->assertSee($url->url); + + $organization = create(Organization::class); + $organization->users()->attach($this->user, ['role_id' => OrganizationUser::ROLE_MEMBER]); + $url = factory(Url::class)->states('org')->create(['organization_id' => $organization->id]); + $this->get(route('platform.urls.index')) + ->assertStatus(200) + ->assertSee($url->url); } /** @test */