Have webmentions sent automatically

This commit is contained in:
Jonny Barnes 2016-06-23 14:27:00 +01:00
parent 44060da577
commit e31364e787
7 changed files with 49 additions and 11 deletions

View file

@ -6,6 +6,7 @@ use Exception;
use Illuminate\Validation\ValidationException;
use Illuminate\Session\TokenMismatchException;
use Illuminate\Auth\Access\AuthorizationException;
use Symfony\Component\Debug\Exception\FlattenException;
use Illuminate\Database\Eloquent\ModelNotFoundException;
use Symfony\Component\HttpKernel\Exception\HttpException;
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
@ -78,10 +79,11 @@ class Handler extends ExceptionHandler
});
$whoops->pushHandler($handler);
$flattened = FlattenException::create($exc);
return new \Illuminate\Http\Response(
$whoops->handleException($exc),
$exc->getStatusCode(),
$exc->getHeaders()
$flattened->getStatusCode(),
$flattened->getHeaders()
);
}
}

View file

@ -9,6 +9,12 @@ use App\Services\NoteService;
class NotesAdminController extends Controller
{
protected $noteService;
public function __construct(NoteService $noteService = null)
{
$this->noteService = $noteService ?? new NoteService();
}
/**
* Show the form to make a new note.
*

View file

@ -22,7 +22,7 @@ class SendWebMentions extends Job implements ShouldQueue
* @param Note $note
* @return void
*/
public function __construct(Note $note, Client $guzzle)
public function __construct(Note $note, Client $guzzle = null)
{
$this->note = $note;
$this->guzzle = $guzzle ?? new Client();
@ -47,7 +47,7 @@ class SendWebMentions extends Job implements ShouldQueue
'source' => $this->note->longurl,
'target' => $url
]
])
]);
}
}
}

View file

@ -5,7 +5,7 @@ namespace App\Services;
use App\Note;
use App\Place;
use Illuminate\Http\Request;
use App\Jobs\SendWebmentions;
use App\Jobs\SendWebMentions;
use App\Jobs\SyndicateToTwitter;
use Illuminate\Foundation\Bus\DispatchesJobs;
use App\Http\Controllers\WebMentionsController;
@ -46,7 +46,7 @@ class NoteService
}
}
$this->dispatch(new SendWebmentions($note));
$this->dispatch(new SendWebMentions($note));
if (//micropub request, syndication sent as array
(is_array($request->input('mp-syndicate-to'))

View file

@ -4,7 +4,6 @@
<legend>New Note</legend>
<label for="in-reply-to" accesskey="r">Reply-to: </label><input type="text" name="in-reply-to" id="in-reply-to" placeholder="in-reply-to-1 in-reply-to-2 …" value="{{ old('in-reply-to') }}">
<label for="content" accesskey="n">Note: </label><textarea name="content" id="content" placeholder="Note" autofocus>{{ old('content') }}</textarea>
<label for="webmentions" accesskey="w">Send webmentions: </label><input type="checkbox" name="webmentions" id="webmentions" checked="checked"><br>
@if ($micropub === true)
<label for="syndication" accesskey="s">Syndication: </label>@if($syndication)<ul class="syndication-targets-list" name="syndication">@foreach($syndication as $target)<li><input type="checkbox" name="mp-syndicate-to[]" id="{{ $target }}" value="{{ $target }}" checked="checked"> <label for="{{ $target }}">{{ $target }}</label></li>@endforeach</ul>@endif
<a href="/refresh-syndication-targets">Refresh Syndication Targets</a><br>

View file

@ -38,7 +38,7 @@ class MicropubTest extends TestCase
public function testMicropubRequestWithValidToken()
{
$this->call('GET', $this->appurl . '/api/post', [], [], [], ['HTTP_Authorization' => 'Bearer ' . $this->getToken()]);
$this->see('me=https%3A%2F%2Fjbl5.dev');
$this->see('me=https%3A%2F%2Fjonnybarnes.localhost');
}
public function testMicropubRequestForSyndication()
@ -79,8 +79,6 @@ class MicropubTest extends TestCase
public function testMicropubRequestCreateNewPlace()
{
$faker = \Faker\Factory::create();
$note = $faker->text;
$this->call(
'POST',
$this->appurl . '/api/post',
@ -101,7 +99,7 @@ class MicropubTest extends TestCase
$signer = new Sha256();
$token = (new Builder())
->set('client_id', 'https://quill.p3k.io')
->set('me', 'https://jbl5.dev')
->set('me', 'https://jonnybarnes.localhost')
->set('scope', 'post')
->set('issued_at', time())
->sign($signer, env('APP_KEY'))

33
tests/NotesAdminTest.php Normal file
View file

@ -0,0 +1,33 @@
<?php
namespace App\Tests;
use TestCase;
use Illuminate\Foundation\Testing\WithoutMiddleware;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Illuminate\Foundation\Testing\DatabaseTransactions;
class NotesAdminTest extends TestCase
{
use DatabaseTransactions;
protected $appurl;
protected $notesAdminController;
public function setUp()
{
parent::setUp();
$this->appurl = config('app.url');
$this->notesAdminController = new \App\Http\Controllers\NotesAdminController();
}
public function testCreatedNoteDispatchesSendWebmentionsJob()
{
$this->expectsJobs(\App\Jobs\SendWebMentions::class);
$this->withSession(['loggedin' => true])
->visit($this->appurl . '/admin/note/new')
->type('Mentioning', 'content')
->press('Submit');
}
}