Skip to content

Commit

Permalink
Fix displaying organization URLs
Browse files Browse the repository at this point in the history
  • Loading branch information
NFarrington committed Apr 21, 2018
1 parent dee80c2 commit 62a0d18
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
6 changes: 2 additions & 4 deletions app/Http/Controllers/Platform/UrlController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
2 changes: 1 addition & 1 deletion app/Models/Url.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,6 @@ public function getFullUrlAttribute()
*/
public function scopePublic($query)
{
return $query->whereNull('user_id');
return $query->whereNull('user_id')->whereNull('organization_id');
}
}
13 changes: 11 additions & 2 deletions tests/Feature/Platform/UrlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down

0 comments on commit 62a0d18

Please sign in to comment.