Skip to content

Commit f492a66

Browse files
committed
Merge branch 'master' into release
2 parents 0943683 + ef11100 commit f492a66

231 files changed

Lines changed: 3369 additions & 907 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/translators.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,3 +206,7 @@ Thiago Rafael Pereira de Carvalho (thiago.rafael) :: Portuguese, Brazilian
206206
Ken Roger Bolgnes (kenbo124) :: Norwegian Bokmal
207207
Nguyen Hung Phuong (hnwolf) :: Vietnamese
208208
Umut ERGENE (umutergene67) :: Turkish
209+
Tomáš Batelka (Vofy) :: Czech
210+
Mundo Racional (ismael.mesquita) :: Portuguese, Brazilian
211+
Zarik (3apuk) :: Russian
212+
Ali Shaatani (a.shaatani) :: Arabic

app/Actions/DispatchWebhookJob.php

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44

55
use BookStack\Auth\User;
66
use BookStack\Entities\Models\Entity;
7+
use BookStack\Facades\Theme;
78
use BookStack\Interfaces\Loggable;
89
use BookStack\Model;
10+
use BookStack\Theming\ThemeEvents;
911
use Illuminate\Bus\Queueable;
1012
use Illuminate\Contracts\Queue\ShouldQueue;
1113
use Illuminate\Foundation\Bus\Dispatchable;
@@ -68,14 +70,32 @@ public function __construct(Webhook $webhook, string $event, $detail)
6870
*/
6971
public function handle()
7072
{
71-
$response = Http::asJson()
72-
->withOptions(['allow_redirects' => ['strict' => true]])
73-
->timeout(3)
74-
->post($this->webhook->endpoint, $this->buildWebhookData());
73+
$themeResponse = Theme::dispatch(ThemeEvents::WEBHOOK_CALL_BEFORE, $this->event, $this->webhook, $this->detail);
74+
$webhookData = $themeResponse ?? $this->buildWebhookData();
75+
$lastError = null;
76+
77+
try {
78+
$response = Http::asJson()
79+
->withOptions(['allow_redirects' => ['strict' => true]])
80+
->timeout($this->webhook->timeout)
81+
->post($this->webhook->endpoint, $webhookData);
82+
} catch (\Exception $exception) {
83+
$lastError = $exception->getMessage();
84+
Log::error("Webhook call to endpoint {$this->webhook->endpoint} failed with error \"{$lastError}\"");
85+
}
7586

76-
if ($response->failed()) {
87+
if (isset($response) && $response->failed()) {
88+
$lastError = "Response status from endpoint was {$response->status()}";
7789
Log::error("Webhook call to endpoint {$this->webhook->endpoint} failed with status {$response->status()}");
7890
}
91+
92+
$this->webhook->last_called_at = now();
93+
if ($lastError) {
94+
$this->webhook->last_errored_at = now();
95+
$this->webhook->last_error = $lastError;
96+
}
97+
98+
$this->webhook->save();
7999
}
80100

81101
protected function buildWebhookData(): array

app/Actions/Webhook.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace BookStack\Actions;
44

55
use BookStack\Interfaces\Loggable;
6+
use Carbon\Carbon;
67
use Illuminate\Database\Eloquent\Collection;
78
use Illuminate\Database\Eloquent\Factories\HasFactory;
89
use Illuminate\Database\Eloquent\Model;
@@ -14,13 +15,22 @@
1415
* @property string $endpoint
1516
* @property Collection $trackedEvents
1617
* @property bool $active
18+
* @property int $timeout
19+
* @property string $last_error
20+
* @property Carbon $last_called_at
21+
* @property Carbon $last_errored_at
1722
*/
1823
class Webhook extends Model implements Loggable
1924
{
20-
protected $fillable = ['name', 'endpoint'];
25+
protected $fillable = ['name', 'endpoint', 'timeout'];
2126

2227
use HasFactory;
2328

29+
protected $casts = [
30+
'last_called_at' => 'datetime',
31+
'last_errored_at' => 'datetime',
32+
];
33+
2434
/**
2535
* Define the tracked event relation a webhook.
2636
*/

app/Entities/Repos/ChapterRepo.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use BookStack\Entities\Tools\TrashCan;
1111
use BookStack\Exceptions\MoveOperationException;
1212
use BookStack\Exceptions\NotFoundException;
13+
use BookStack\Exceptions\PermissionsException;
1314
use BookStack\Facades\Activity;
1415
use Exception;
1516

@@ -85,15 +86,19 @@ public function destroy(Chapter $chapter)
8586
* 'book:<id>' (book:5).
8687
*
8788
* @throws MoveOperationException
89+
* @throws PermissionsException
8890
*/
8991
public function move(Chapter $chapter, string $parentIdentifier): Book
9092
{
91-
/** @var Book $parent */
9293
$parent = $this->findParentByIdentifier($parentIdentifier);
9394
if (is_null($parent)) {
9495
throw new MoveOperationException('Book to move chapter into not found');
9596
}
9697

98+
if (!userCan('chapter-create', $parent)) {
99+
throw new PermissionsException('User does not have permission to create a chapter within the chosen book');
100+
}
101+
97102
$chapter->changeBook($parent->id);
98103
$chapter->rebuildPermissions();
99104
Activity::add(ActivityType::CHAPTER_MOVE, $chapter);

app/Entities/Repos/PageRepo.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ public function restoreRevision(Page $page, int $revisionId): Page
328328
public function move(Page $page, string $parentIdentifier): Entity
329329
{
330330
$parent = $this->findParentByIdentifier($parentIdentifier);
331-
if ($parent === null) {
331+
if (is_null($parent)) {
332332
throw new MoveOperationException('Book or chapter to move page into not found');
333333
}
334334

0 commit comments

Comments
 (0)