Skip to content

Commit a14d8e3

Browse files
committed
Merge branch 'development' into release
2 parents a9194ff + 7504ad3 commit a14d8e3

Some content is hidden

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

75 files changed

+758
-661
lines changed

.github/translators.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,3 +342,5 @@ Eugene Pershin (SilentEugene) :: Russian
342342
周盛道 (zhoushengdao) :: Chinese Simplified
343343
hamidreza amini (hamidrezaamini2022) :: Persian
344344
Tomislav Kraljević (tomislav.kraljevic) :: Croatian
345+
Taygun Yıldırım (yildirimtaygun) :: Turkish
346+
robing29 :: German

app/Activity/DispatchWebhookJob.php

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,27 +24,23 @@ class DispatchWebhookJob implements ShouldQueue
2424
use SerializesModels;
2525

2626
protected Webhook $webhook;
27-
protected string $event;
2827
protected User $initiator;
2928
protected int $initiatedTime;
30-
31-
/**
32-
* @var string|Loggable
33-
*/
34-
protected $detail;
29+
protected array $webhookData;
3530

3631
/**
3732
* Create a new job instance.
3833
*
3934
* @return void
4035
*/
41-
public function __construct(Webhook $webhook, string $event, $detail)
36+
public function __construct(Webhook $webhook, string $event, Loggable|string $detail)
4237
{
4338
$this->webhook = $webhook;
44-
$this->event = $event;
45-
$this->detail = $detail;
4639
$this->initiator = user();
4740
$this->initiatedTime = time();
41+
42+
$themeResponse = Theme::dispatch(ThemeEvents::WEBHOOK_CALL_BEFORE, $event, $this->webhook, $detail, $this->initiator, $this->initiatedTime);
43+
$this->webhookData = $themeResponse ?? WebhookFormatter::getDefault($event, $this->webhook, $detail, $this->initiator, $this->initiatedTime)->format();
4844
}
4945

5046
/**
@@ -54,15 +50,13 @@ public function __construct(Webhook $webhook, string $event, $detail)
5450
*/
5551
public function handle()
5652
{
57-
$themeResponse = Theme::dispatch(ThemeEvents::WEBHOOK_CALL_BEFORE, $this->event, $this->webhook, $this->detail, $this->initiator, $this->initiatedTime);
58-
$webhookData = $themeResponse ?? WebhookFormatter::getDefault($this->event, $this->webhook, $this->detail, $this->initiator, $this->initiatedTime)->format();
5953
$lastError = null;
6054

6155
try {
6256
$response = Http::asJson()
6357
->withOptions(['allow_redirects' => ['strict' => true]])
6458
->timeout($this->webhook->timeout)
65-
->post($this->webhook->endpoint, $webhookData);
59+
->post($this->webhook->endpoint, $this->webhookData);
6660
} catch (\Exception $exception) {
6761
$lastError = $exception->getMessage();
6862
Log::error("Webhook call to endpoint {$this->webhook->endpoint} failed with error \"{$lastError}\"");

app/Activity/Tools/WebhookFormatter.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,14 @@ class WebhookFormatter
1717
protected string $event;
1818
protected User $initiator;
1919
protected int $initiatedTime;
20-
21-
/**
22-
* @var string|Loggable
23-
*/
24-
protected $detail;
20+
protected string|Loggable $detail;
2521

2622
/**
2723
* @var array{condition: callable(string, Model):bool, format: callable(Model):void}[]
2824
*/
2925
protected $modelFormatters = [];
3026

31-
public function __construct(string $event, Webhook $webhook, $detail, User $initiator, int $initiatedTime)
27+
public function __construct(string $event, Webhook $webhook, string|Loggable $detail, User $initiator, int $initiatedTime)
3228
{
3329
$this->webhook = $webhook;
3430
$this->event = $event;

app/Api/ApiToken.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use BookStack\Activity\Models\Loggable;
66
use BookStack\Users\Models\User;
7+
use Illuminate\Database\Eloquent\Factories\HasFactory;
78
use Illuminate\Database\Eloquent\Model;
89
use Illuminate\Database\Eloquent\Relations\BelongsTo;
910
use Illuminate\Support\Carbon;
@@ -20,6 +21,8 @@
2021
*/
2122
class ApiToken extends Model implements Loggable
2223
{
24+
use HasFactory;
25+
2326
protected $fillable = ['name', 'expires_at'];
2427
protected $casts = [
2528
'expires_at' => 'date:Y-m-d',

app/Theming/ThemeEvents.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,11 +132,12 @@ class ThemeEvents
132132
* If the listener returns a non-null value, that will be used as the POST data instead
133133
* of the system default.
134134
*
135-
* @param string $event
136-
* @param \BookStack\Activity\Models\Webhook $webhook
135+
* @param string $event
136+
* @param \BookStack\Activity\Models\Webhook $webhook
137137
* @param string|\BookStack\Activity\Models\Loggable $detail
138-
* @param \BookStack\Users\Models\User $initiator
139-
* @param int $initiatedTime
138+
* @param \BookStack\Users\Models\User $initiator
139+
* @param int $initiatedTime
140+
* @returns array|null
140141
*/
141142
const WEBHOOK_CALL_BEFORE = 'webhook_call_before';
142143
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
namespace Database\Factories\Api;
4+
5+
use BookStack\Api\ApiToken;
6+
use BookStack\Users\Models\User;
7+
use Illuminate\Database\Eloquent\Factories\Factory;
8+
use Illuminate\Support\Carbon;
9+
use Illuminate\Support\Str;
10+
11+
class ApiTokenFactory extends Factory
12+
{
13+
protected $model = ApiToken::class;
14+
15+
public function definition(): array
16+
{
17+
return [
18+
'token_id' => Str::random(10),
19+
'secret' => Str::random(12),
20+
'name' => $this->faker->name(),
21+
'expires_at' => Carbon::now()->addYear(),
22+
'created_at' => Carbon::now(),
23+
'updated_at' => Carbon::now(),
24+
'user_id' => User::factory(),
25+
];
26+
}
27+
}

database/migrations/2023_06_25_181952_remove_bookshelf_create_entity_permissions.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@
1212
*/
1313
public function up()
1414
{
15-
DB::table('entity_permissions')
16-
->where('entity_type', '=', 'bookshelf')
17-
->update(['create' => 0]);
15+
// Note: v23.06.2
16+
// Migration removed since change to remove bookshelf create permissions was reverted.
17+
// Create permissions were removed as incorrectly thought to be unused, but they did
18+
// have a use via shelf permission copy-down to books.
1819
}
1920

2021
/**

lang/ar/entities.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@
106106
'shelves_permissions_updated' => 'Shelf Permissions Updated',
107107
'shelves_permissions_active' => 'Shelf Permissions Active',
108108
'shelves_permissions_cascade_warning' => 'Permissions on shelves do not automatically cascade to contained books. This is because a book can exist on multiple shelves. Permissions can however be copied down to child books using the option found below.',
109+
'shelves_permissions_create' => 'Shelf create permissions are only used for copying permissions to child books using the action below. They do not control the ability to create books.',
109110
'shelves_copy_permissions_to_books' => 'نسخ أذونات الوصول إلى الكتب',
110111
'shelves_copy_permissions' => 'نسخ الأذونات',
111112
'shelves_copy_permissions_explain' => 'This will apply the current permission settings of this shelf to all books contained within. Before activating, ensure any changes to the permissions of this shelf have been saved.',

lang/bg/entities.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@
106106
'shelves_permissions_updated' => 'Shelf Permissions Updated',
107107
'shelves_permissions_active' => 'Shelf Permissions Active',
108108
'shelves_permissions_cascade_warning' => 'Permissions on shelves do not automatically cascade to contained books. This is because a book can exist on multiple shelves. Permissions can however be copied down to child books using the option found below.',
109+
'shelves_permissions_create' => 'Shelf create permissions are only used for copying permissions to child books using the action below. They do not control the ability to create books.',
109110
'shelves_copy_permissions_to_books' => 'Копирай настойките за достъп към книгите',
110111
'shelves_copy_permissions' => 'Копирай настройките за достъп',
111112
'shelves_copy_permissions_explain' => 'This will apply the current permission settings of this shelf to all books contained within. Before activating, ensure any changes to the permissions of this shelf have been saved.',

lang/bs/entities.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@
106106
'shelves_permissions_updated' => 'Shelf Permissions Updated',
107107
'shelves_permissions_active' => 'Shelf Permissions Active',
108108
'shelves_permissions_cascade_warning' => 'Permissions on shelves do not automatically cascade to contained books. This is because a book can exist on multiple shelves. Permissions can however be copied down to child books using the option found below.',
109+
'shelves_permissions_create' => 'Shelf create permissions are only used for copying permissions to child books using the action below. They do not control the ability to create books.',
109110
'shelves_copy_permissions_to_books' => 'Copy Permissions to Books',
110111
'shelves_copy_permissions' => 'Copy Permissions',
111112
'shelves_copy_permissions_explain' => 'This will apply the current permission settings of this shelf to all books contained within. Before activating, ensure any changes to the permissions of this shelf have been saved.',

0 commit comments

Comments
 (0)