mirror of
https://github.com/Kovah/LinkAce.git
synced 2025-04-14 03:32:01 +02:00
Add RSS feeds for private links, lists and tags accessible via api token authorization (#197)
This commit is contained in:
parent
b8135ac162
commit
e8aec55015
61
app/Http/Controllers/App/FeedController.php
Normal file
61
app/Http/Controllers/App/FeedController.php
Normal file
@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\App;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Link;
|
||||
use App\Models\LinkList;
|
||||
use App\Models\Tag;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Response;
|
||||
|
||||
class FeedController extends Controller
|
||||
{
|
||||
public function links(Request $request)
|
||||
{
|
||||
$links = Link::latest()->with('user')->get();
|
||||
$meta = [
|
||||
'title' => 'LinkAce Links',
|
||||
'link' => $request->fullUrl(),
|
||||
'updated' => now()->toRfc3339String(),
|
||||
'id' => $request->fullUrl(),
|
||||
];
|
||||
|
||||
return new Response(view('actions.feed.links', [
|
||||
'meta' => $meta,
|
||||
'links' => $links,
|
||||
]), 200, ['Content-Type' => 'application/xml']);
|
||||
}
|
||||
|
||||
public function lists(Request $request)
|
||||
{
|
||||
$lists = LinkList::latest()->with('user')->get();
|
||||
$meta = [
|
||||
'title' => 'LinkAce Lists',
|
||||
'link' => $request->fullUrl(),
|
||||
'updated' => now()->toRfc3339String(),
|
||||
'id' => $request->fullUrl(),
|
||||
];
|
||||
|
||||
return new Response(view('actions.feed.lists', [
|
||||
'meta' => $meta,
|
||||
'lists' => $lists,
|
||||
]), 200, ['Content-Type' => 'application/xml']);
|
||||
}
|
||||
|
||||
public function tags(Request $request)
|
||||
{
|
||||
$tags = Tag::latest()->with('user')->get();
|
||||
$meta = [
|
||||
'title' => 'LinkAce Links',
|
||||
'link' => $request->fullUrl(),
|
||||
'updated' => now()->toRfc3339String(),
|
||||
'id' => $request->fullUrl(),
|
||||
];
|
||||
|
||||
return new Response(view('actions.feed.tags', [
|
||||
'meta' => $meta,
|
||||
'tags' => $tags,
|
||||
]), 200, ['Content-Type' => 'application/xml']);
|
||||
}
|
||||
}
|
@ -21,7 +21,7 @@ class FeedController extends Controller
|
||||
'id' => $request->fullUrl(),
|
||||
];
|
||||
|
||||
return new Response(view('guest.links.feed', [
|
||||
return new Response(view('actions.feed.links', [
|
||||
'meta' => $meta,
|
||||
'links' => $links,
|
||||
]), 200, ['Content-Type' => 'application/xml']);
|
||||
@ -37,7 +37,7 @@ class FeedController extends Controller
|
||||
'id' => $request->fullUrl(),
|
||||
];
|
||||
|
||||
return new Response(view('guest.lists.feed', [
|
||||
return new Response(view('actions.feed.lists', [
|
||||
'meta' => $meta,
|
||||
'lists' => $lists,
|
||||
]), 200, ['Content-Type' => 'application/xml']);
|
||||
@ -53,7 +53,7 @@ class FeedController extends Controller
|
||||
'id' => $request->fullUrl(),
|
||||
];
|
||||
|
||||
return new Response(view('guest.tags.feed', [
|
||||
return new Response(view('actions.feed.tags', [
|
||||
'meta' => $meta,
|
||||
'tags' => $tags,
|
||||
]), 200, ['Content-Type' => 'application/xml']);
|
||||
|
@ -6,8 +6,9 @@
|
||||
<id>{{ $meta['id'] }}</id>
|
||||
@foreach($links as $link)
|
||||
<entry>
|
||||
<title><![CDATA[{{ $link->title }}]]></title>
|
||||
<id>{{ $link->url }}</id>
|
||||
<title><![CDATA[{{ $link->title }}]]></title>
|
||||
<link rel="alternate" href="{{ route('links.show', ['link'=> $link]) }}" />
|
||||
<author>
|
||||
<name> <![CDATA[{{ $link->user->name }}]]></name>
|
||||
</author>
|
@ -6,9 +6,9 @@
|
||||
<id>{{ $meta['id'] }}</id>
|
||||
@foreach($lists as $list)
|
||||
<entry>
|
||||
<id>{{ route('lists.show', ['list' => $list]) }}</id>
|
||||
<title><![CDATA[{{ $list->name }}]]></title>
|
||||
<link rel="alternate" href="{{ route('guest.lists.show', ['list' => $list]) }}"/>
|
||||
<id>{{ url($list->id) }}</id>
|
||||
<link rel="alternate" href="{{ route('lists.show', ['list' => $list]) }}"/>
|
||||
<author>
|
||||
<name> <![CDATA[{{ $list->user->name }}]]></name>
|
||||
</author>
|
@ -6,8 +6,9 @@
|
||||
<id>{{ $meta['id'] }}</id>
|
||||
@foreach($tags as $tag)
|
||||
<entry>
|
||||
<title><![CDATA[{{ $tag->name }}]]></title>
|
||||
<id>{{ route('tags.show', ['tag' => $tag]) }}</id>
|
||||
<title><![CDATA[{{ $tag->name }}]]></title>
|
||||
<link rel="alternate" href="{{ route('tags.show', ['tag' => $tag]) }}" />
|
||||
<author>
|
||||
<name> <![CDATA[{{ $tag->user->name }}]]></name>
|
||||
</author>
|
@ -3,6 +3,7 @@
|
||||
use App\Http\Controllers\App\BookmarkletController;
|
||||
use App\Http\Controllers\App\DashboardController;
|
||||
use App\Http\Controllers\App\ExportController;
|
||||
use App\Http\Controllers\App\FeedController;
|
||||
use App\Http\Controllers\App\ImportController;
|
||||
use App\Http\Controllers\App\SearchController;
|
||||
use App\Http\Controllers\App\SystemSettingsController;
|
||||
@ -11,7 +12,7 @@ use App\Http\Controllers\App\UserSettingsController;
|
||||
use App\Http\Controllers\CronController;
|
||||
use App\Http\Controllers\FetchController;
|
||||
use App\Http\Controllers\FrontController;
|
||||
use App\Http\Controllers\Guest\FeedController;
|
||||
use App\Http\Controllers\Guest\FeedController as GuestFeedController;
|
||||
use App\Http\Controllers\Guest\LinkController as GuestLinkController;
|
||||
use App\Http\Controllers\Guest\ListController as GuestListController;
|
||||
use App\Http\Controllers\Guest\TagController as GuestTagController;
|
||||
@ -54,6 +55,12 @@ Route::prefix('bookmarklet')->group(function () {
|
||||
|
||||
Route::get('cron/{token}', CronController::class)->name('cron');
|
||||
|
||||
Route::group(['middleware' => 'auth:api'], function () {
|
||||
Route::get('links/feed', [FeedController::class, 'links'])->name('links.feed');
|
||||
Route::get('lists/feed', [FeedController::class, 'lists'])->name('lists.feed');
|
||||
Route::get('tags/feed', [FeedController::class, 'tags'])->name('tags.feed');
|
||||
});
|
||||
|
||||
// Model routes
|
||||
Route::group(['middleware' => ['auth']], function () {
|
||||
Route::get('dashboard', [DashboardController::class, 'index'])
|
||||
@ -130,9 +137,9 @@ Route::group(['middleware' => ['auth']], function () {
|
||||
// Guest access routes
|
||||
Route::prefix('guest')->middleware(['guestaccess'])->group(function () {
|
||||
|
||||
Route::get('links/feed', [FeedController::class, 'links'])->name('guest.links.feed');
|
||||
Route::get('lists/feed', [FeedController::class, 'lists'])->name('guest.lists.feed');
|
||||
Route::get('tags/feed', [FeedController::class, 'tags'])->name('guest.tags.feed');
|
||||
Route::get('links/feed', [GuestFeedController::class, 'links'])->name('guest.links.feed');
|
||||
Route::get('lists/feed', [GuestFeedController::class, 'lists'])->name('guest.lists.feed');
|
||||
Route::get('tags/feed', [GuestFeedController::class, 'tags'])->name('guest.tags.feed');
|
||||
|
||||
Route::resource('links', GuestLinkController::class)
|
||||
->only(['index'])
|
||||
|
75
tests/Controller/App/FeedControllerTest.php
Normal file
75
tests/Controller/App/FeedControllerTest.php
Normal file
@ -0,0 +1,75 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Controller\App;
|
||||
|
||||
use App\Models\Link;
|
||||
use App\Models\LinkList;
|
||||
use App\Models\Tag;
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Testing\TestResponse;
|
||||
use Tests\TestCase;
|
||||
|
||||
class FeedControllerTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
private $user;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->user = User::factory()->create();
|
||||
}
|
||||
|
||||
public function testUnauthorizedRequest(): void
|
||||
{
|
||||
$response = $this->get('links/feed');
|
||||
|
||||
$response->assertRedirect('login');
|
||||
}
|
||||
|
||||
public function testLinksFeed(): void
|
||||
{
|
||||
$link = Link::factory()->create();
|
||||
|
||||
$response = $this->getAuthorized('links/feed');
|
||||
|
||||
$response->assertOk()
|
||||
->assertSee($link->url);
|
||||
}
|
||||
|
||||
public function testListsFeed(): void
|
||||
{
|
||||
$list = LinkList::factory()->create();
|
||||
|
||||
$response = $this->getAuthorized('lists/feed');
|
||||
|
||||
$response->assertOk()
|
||||
->assertSee($list->name);
|
||||
}
|
||||
|
||||
public function testTagsFeed(): void
|
||||
{
|
||||
$tag = Tag::factory()->create();
|
||||
|
||||
$response = $this->getAuthorized('tags/feed');
|
||||
|
||||
$response->assertOk()
|
||||
->assertSee($tag->name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send an authorized request for the GET method.
|
||||
*
|
||||
* @param string $uri
|
||||
* @param array $headers
|
||||
* @return TestResponse
|
||||
*/
|
||||
public function getAuthorized(string $uri, array $headers = []): TestResponse
|
||||
{
|
||||
$headers['Authorization'] = 'Bearer ' . $this->user->api_token;
|
||||
return $this->get($uri, $headers);
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user