1
0
mirror of https://github.com/Kovah/LinkAce.git synced 2025-04-21 07:22:20 +02:00

Fix link display for tags and lists (#912 #914)

This commit is contained in:
Kovah 2025-02-16 21:00:12 +01:00
parent b42290f49a
commit 3230d77163
5 changed files with 24 additions and 10 deletions

View File

@ -39,9 +39,7 @@ class LinkController extends Controller
session()->put('links.index.orderBy', $this->orderBy);
session()->put('links.index.orderDir', $this->orderDir);
$links = Link::query()
->visibleForUser()
->with('tags');
$links = Link::query()->visibleForUser()->with('tags');
if ($this->orderBy === 'random') {
$links->inRandomOrder();

View File

@ -83,7 +83,7 @@ class ListController extends Controller
$this->orderDir = $request->input('orderBy', 'desc');
$this->checkOrdering();
$links = $list->links()->publicOnly();
$links = $list->links()->visibleForUser();
if ($this->orderBy === 'random') {
$links->inRandomOrder();

View File

@ -86,7 +86,7 @@ class TagController extends Controller
$this->orderDir = $request->input('orderBy', 'desc');
$this->checkOrdering();
$links = $tag->links()->publicOnly();
$links = $tag->links()->visibleForUser();
if ($this->orderBy === 'random') {
$links->inRandomOrder();

View File

@ -2,6 +2,7 @@
namespace Tests\Controller\Models;
use App\Enums\ModelAttribute;
use App\Models\Link;
use App\Models\LinkList;
use App\Models\User;
@ -146,9 +147,15 @@ class ListControllerTest extends TestCase
[$list, $list2, $list3, $firstUser] = $this->createTestLists();
Link::factory()->for($firstUser)->create(['title' => 'FirstTestLink'])->lists()->sync([$list->id]);
Link::factory()->for($firstUser)->create([
'title' => 'InternalTestLink',
'visibility' => ModelAttribute::VISIBILITY_INTERNAL,
])->lists()->sync([$list->id]);
$this->actingAs($otherUser);
$this->get('lists/1')->assertOk()->assertSee('Public List')->assertSee('Public List')->assertSee('FirstTestLink');
$this->get('lists/1')->assertOk()->assertSee('Public List')->assertSee('Public List')
->assertSee('FirstTestLink')
->assertSee('InternalTestLink');
$this->get('lists/2')->assertOk()->assertSee('Internal List')->assertSee('Internal List');
$this->get('lists/3')->assertForbidden();
}

View File

@ -2,6 +2,8 @@
namespace Tests\Controller\Models;
use App\Enums\ModelAttribute;
use App\Models\Link;
use App\Models\Tag;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
@ -20,7 +22,6 @@ class TagControllerTest extends TestCase
parent::setUp();
$this->user = User::factory()->create();
$this->actingAs($this->user);
}
@ -108,7 +109,7 @@ class TagControllerTest extends TestCase
public function test_validation_error_for_create(): void
{
$response = $this->post('tags', [
$this->post('tags', [
'name' => null,
'visibility' => 1,
])->assertSessionHasErrors([
@ -118,9 +119,17 @@ class TagControllerTest extends TestCase
public function test_detail_view(): void
{
$this->createTestTags();
[$tag1, $tag2, $tag3, $otherUser] = $this->createTestTags();
$this->get('tags/1')->assertOk()->assertSee('Public Tag');
Link::factory()->for($this->user)->create(['title' => 'FirstTestLink'])->tags()->sync([$tag1->id]);
Link::factory()->for($this->user)->create([
'title' => 'SecondTestLink',
'visibility' => ModelAttribute::VISIBILITY_INTERNAL,
])->tags()->sync([$tag1->id]);
$this->get('tags/1')->assertOk()->assertSee('Public Tag')
->assertSee('FirstTestLink')
->assertSee('SecondTestLink');
$this->get('tags/2')->assertOk()->assertSee('Internal Tag');
$this->get('tags/3')->assertForbidden();
}