Skip to content

Commit 8c82aaa

Browse files
committed
Merge branch 'development' into release
2 parents ce9b536 + c7e33d1 commit 8c82aaa

File tree

741 files changed

+5185
-4667
lines changed

Some content is hidden

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

741 files changed

+5185
-4667
lines changed

.env.example.complete

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@ MAIL_USERNAME=null
8080
MAIL_PASSWORD=null
8181
MAIL_ENCRYPTION=null
8282

83+
# Command to use when email is sent via sendmail
84+
MAIL_SENDMAIL_COMMAND="/usr/sbin/sendmail -bs"
85+
8386
# Cache & Session driver to use
8487
# Can be 'file', 'database', 'memcached' or 'redis'
8588
CACHE_DRIVER=file

.github/translators.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,3 +308,6 @@ Adrian Ocneanu (aocneanu) :: Romanian
308308
Eduardo Castanho (EduardoCastanho) :: Portuguese
309309
VIET NAM VPS (vietnamvps) :: Vietnamese
310310
m4tthi4s :: French
311+
toras9000 :: Japanese
312+
pathab :: German
313+
MichelSchoon85 :: Dutch

.github/workflows/test-migrations.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ jobs:
88
runs-on: ubuntu-22.04
99
strategy:
1010
matrix:
11-
php: ['7.4', '8.0', '8.1', '8.2']
11+
php: ['8.0', '8.1', '8.2']
1212
steps:
1313
- uses: actions/checkout@v1
1414

.github/workflows/test-php.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ jobs:
88
runs-on: ubuntu-22.04
99
strategy:
1010
matrix:
11-
php: ['7.4', '8.0', '8.1', '8.2']
11+
php: ['8.0', '8.1', '8.2']
1212
steps:
1313
- uses: actions/checkout@v1
1414

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ yarn-error.log
1111
/public/js/*.map
1212
/public/bower
1313
/public/build/
14+
/public/favicon.ico
1415
/storage/images
1516
_ide_helper.php
1617
/storage/debugbar

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License (MIT)
22

3-
Copyright (c) 2015-2022, Dan Brown and the BookStack Project contributors.
3+
Copyright (c) 2015-2023, Dan Brown and the BookStack Project contributors.
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

app/Auth/Permissions/PermissionApplicator.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,11 @@ public function restrictPageRelationQuery(Builder $query, string $tableName, str
158158
$query->select('id')->from('pages')
159159
->whereColumn('pages.id', '=', $fullPageIdColumn)
160160
->where('pages.draft', '=', false);
161+
})->orWhereExists(function (QueryBuilder $query) use ($fullPageIdColumn) {
162+
$query->select('id')->from('pages')
163+
->whereColumn('pages.id', '=', $fullPageIdColumn)
164+
->where('pages.draft', '=', true)
165+
->where('pages.created_by', '=', $this->currentUser()->id);
161166
});
162167
});
163168
}

app/Auth/Permissions/PermissionsRepo.php

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,8 @@
1212
class PermissionsRepo
1313
{
1414
protected JointPermissionBuilder $permissionBuilder;
15-
protected $systemRoles = ['admin', 'public'];
15+
protected array $systemRoles = ['admin', 'public'];
1616

17-
/**
18-
* PermissionsRepo constructor.
19-
*/
2017
public function __construct(JointPermissionBuilder $permissionBuilder)
2118
{
2219
$this->permissionBuilder = $permissionBuilder;
@@ -41,7 +38,7 @@ public function getAllRolesExcept(Role $role): Collection
4138
/**
4239
* Get a role via its ID.
4340
*/
44-
public function getRoleById($id): Role
41+
public function getRoleById(int $id): Role
4542
{
4643
return Role::query()->findOrFail($id);
4744
}
@@ -52,10 +49,10 @@ public function getRoleById($id): Role
5249
public function saveNewRole(array $roleData): Role
5350
{
5451
$role = new Role($roleData);
55-
$role->mfa_enforced = ($roleData['mfa_enforced'] ?? 'false') === 'true';
52+
$role->mfa_enforced = boolval($roleData['mfa_enforced'] ?? false);
5653
$role->save();
5754

58-
$permissions = isset($roleData['permissions']) ? array_keys($roleData['permissions']) : [];
55+
$permissions = $roleData['permissions'] ?? [];
5956
$this->assignRolePermissions($role, $permissions);
6057
$this->permissionBuilder->rebuildForRole($role);
6158

@@ -66,42 +63,45 @@ public function saveNewRole(array $roleData): Role
6663

6764
/**
6865
* Updates an existing role.
69-
* Ensure Admin role always have core permissions.
66+
* Ensures Admin system role always have core permissions.
7067
*/
71-
public function updateRole($roleId, array $roleData)
68+
public function updateRole($roleId, array $roleData): Role
7269
{
7370
$role = $this->getRoleById($roleId);
7471

75-
$permissions = isset($roleData['permissions']) ? array_keys($roleData['permissions']) : [];
76-
if ($role->system_name === 'admin') {
77-
$permissions = array_merge($permissions, [
78-
'users-manage',
79-
'user-roles-manage',
80-
'restrictions-manage-all',
81-
'restrictions-manage-own',
82-
'settings-manage',
83-
]);
72+
if (isset($roleData['permissions'])) {
73+
$this->assignRolePermissions($role, $roleData['permissions']);
8474
}
8575

86-
$this->assignRolePermissions($role, $permissions);
87-
8876
$role->fill($roleData);
89-
$role->mfa_enforced = ($roleData['mfa_enforced'] ?? 'false') === 'true';
9077
$role->save();
9178
$this->permissionBuilder->rebuildForRole($role);
9279

9380
Activity::add(ActivityType::ROLE_UPDATE, $role);
81+
82+
return $role;
9483
}
9584

9685
/**
97-
* Assign a list of permission names to a role.
86+
* Assign a list of permission names to the given role.
9887
*/
99-
protected function assignRolePermissions(Role $role, array $permissionNameArray = [])
88+
protected function assignRolePermissions(Role $role, array $permissionNameArray = []): void
10089
{
10190
$permissions = [];
10291
$permissionNameArray = array_values($permissionNameArray);
10392

104-
if ($permissionNameArray) {
93+
// Ensure the admin system role retains vital system permissions
94+
if ($role->system_name === 'admin') {
95+
$permissionNameArray = array_unique(array_merge($permissionNameArray, [
96+
'users-manage',
97+
'user-roles-manage',
98+
'restrictions-manage-all',
99+
'restrictions-manage-own',
100+
'settings-manage',
101+
]));
102+
}
103+
104+
if (!empty($permissionNameArray)) {
105105
$permissions = RolePermission::query()
106106
->whereIn('name', $permissionNameArray)
107107
->pluck('id')
@@ -114,13 +114,13 @@ protected function assignRolePermissions(Role $role, array $permissionNameArray
114114
/**
115115
* Delete a role from the system.
116116
* Check it's not an admin role or set as default before deleting.
117-
* If an migration Role ID is specified the users assign to the current role
117+
* If a migration Role ID is specified the users assign to the current role
118118
* will be added to the role of the specified id.
119119
*
120120
* @throws PermissionsException
121121
* @throws Exception
122122
*/
123-
public function deleteRole($roleId, $migrateRoleId)
123+
public function deleteRole(int $roleId, int $migrateRoleId = 0): void
124124
{
125125
$role = $this->getRoleById($roleId);
126126

@@ -131,7 +131,7 @@ public function deleteRole($roleId, $migrateRoleId)
131131
throw new PermissionsException(trans('errors.role_registration_default_cannot_delete'));
132132
}
133133

134-
if ($migrateRoleId) {
134+
if ($migrateRoleId !== 0) {
135135
$newRole = Role::query()->find($migrateRoleId);
136136
if ($newRole) {
137137
$users = $role->users()->pluck('id')->toArray();

app/Auth/Permissions/RolePermission.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
/**
1010
* @property int $id
11+
* @property string $name
12+
* @property string $display_name
1113
*/
1214
class RolePermission extends Model
1315
{

app/Auth/Role.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,14 @@ class Role extends Model implements Loggable
2727
{
2828
use HasFactory;
2929

30-
protected $fillable = ['display_name', 'description', 'external_auth_id'];
30+
protected $fillable = ['display_name', 'description', 'external_auth_id', 'mfa_enforced'];
3131

3232
protected $hidden = ['pivot'];
3333

34+
protected $casts = [
35+
'mfa_enforced' => 'boolean',
36+
];
37+
3438
/**
3539
* The roles that belong to the role.
3640
*/
@@ -107,7 +111,13 @@ public static function getRole(string $displayName): ?self
107111
*/
108112
public static function getSystemRole(string $systemName): ?self
109113
{
110-
return static::query()->where('system_name', '=', $systemName)->first();
114+
static $cache = [];
115+
116+
if (!isset($cache[$systemName])) {
117+
$cache[$systemName] = static::query()->where('system_name', '=', $systemName)->first();
118+
}
119+
120+
return $cache[$systemName];
111121
}
112122

113123
/**

0 commit comments

Comments
 (0)