Skip to content

Commit

Permalink
Merge branch 'development' into release
Browse files Browse the repository at this point in the history
  • Loading branch information
ssddanbrown committed Nov 30, 2022
2 parents edb0c6a + 69d702c commit 914790f
Show file tree
Hide file tree
Showing 501 changed files with 8,722 additions and 3,826 deletions.
7 changes: 7 additions & 0 deletions .github/translators.txt
Original file line number Diff line number Diff line change
Expand Up @@ -291,3 +291,10 @@ Fabrice Boyer (FabriceBoyer) :: French
mikael (bitcanon) :: Swedish
Matthias Mai (schnapsidee) :: German
Ufuk Ayyıldız (ufukayyildiz) :: Turkish
Jan Mitrof (jan.kachlik) :: Czech
edwardsmirnov :: Russian
Mr_OSS117 :: French
shotu :: French
Cesar_Lopez_Aguillon :: Spanish
bdewoop :: German
dina davoudi (dina.davoudi) :: Persian
4 changes: 2 additions & 2 deletions .github/workflows/analyse-php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ jobs:
- name: Get Composer Cache Directory
id: composer-cache
run: |
echo "::set-output name=dir::$(composer config cache-files-dir)"
echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
- name: Cache composer packages
uses: actions/cache@v2
uses: actions/cache@v3
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-8.1
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/test-migrations.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
runs-on: ubuntu-22.04
strategy:
matrix:
php: ['7.4', '8.0', '8.1']
php: ['7.4', '8.0', '8.1', '8.2']
steps:
- uses: actions/checkout@v1

Expand All @@ -21,10 +21,10 @@ jobs:
- name: Get Composer Cache Directory
id: composer-cache
run: |
echo "::set-output name=dir::$(composer config cache-files-dir)"
echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
- name: Cache composer packages
uses: actions/cache@v2
uses: actions/cache@v3
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ matrix.php }}
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/test-php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
runs-on: ubuntu-22.04
strategy:
matrix:
php: ['7.4', '8.0', '8.1']
php: ['7.4', '8.0', '8.1', '8.2']
steps:
- uses: actions/checkout@v1

Expand All @@ -21,10 +21,10 @@ jobs:
- name: Get Composer Cache Directory
id: composer-cache
run: |
echo "::set-output name=dir::$(composer config cache-files-dir)"
echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
- name: Cache composer packages
uses: actions/cache@v2
uses: actions/cache@v3
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ matrix.php }}
Expand Down
30 changes: 30 additions & 0 deletions app/Actions/Queries/WebhooksAllPaginatedAndSorted.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

namespace BookStack\Actions\Queries;

use BookStack\Actions\Webhook;
use BookStack\Util\SimpleListOptions;
use Illuminate\Pagination\LengthAwarePaginator;

/**
* Get all the webhooks in the system in a paginated format.
*/
class WebhooksAllPaginatedAndSorted
{
public function run(int $count, SimpleListOptions $listOptions): LengthAwarePaginator
{
$query = Webhook::query()->select(['*'])
->withCount(['trackedEvents'])
->orderBy($listOptions->getSort(), $listOptions->getOrder());

if ($listOptions->getSearch()) {
$term = '%' . $listOptions->getSearch() . '%';
$query->where(function ($query) use ($term) {
$query->where('name', 'like', $term)
->orWhere('endpoint', 'like', $term);
});
}

return $query->paginate($count);
}
}
11 changes: 9 additions & 2 deletions app/Actions/TagRepo.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use BookStack\Auth\Permissions\PermissionApplicator;
use BookStack\Entities\Models\Entity;
use BookStack\Util\SimpleListOptions;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\DB;
Expand All @@ -20,8 +21,14 @@ public function __construct(PermissionApplicator $permissions)
/**
* Start a query against all tags in the system.
*/
public function queryWithTotals(string $searchTerm, string $nameFilter): Builder
public function queryWithTotals(SimpleListOptions $listOptions, string $nameFilter): Builder
{
$searchTerm = $listOptions->getSearch();
$sort = $listOptions->getSort();
if ($sort === 'name' && $nameFilter) {
$sort = 'value';
}

$query = Tag::query()
->select([
'name',
Expand All @@ -32,7 +39,7 @@ public function queryWithTotals(string $searchTerm, string $nameFilter): Builder
DB::raw('SUM(IF(entity_type = \'book\', 1, 0)) as book_count'),
DB::raw('SUM(IF(entity_type = \'bookshelf\', 1, 0)) as shelf_count'),
])
->orderBy($nameFilter ? 'value' : 'name');
->orderBy($sort, $listOptions->getOrder());

if ($nameFilter) {
$query->where('name', '=', $nameFilter);
Expand Down
22 changes: 15 additions & 7 deletions app/Api/ListingResponseBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,29 @@

use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;

class ListingResponseBuilder
{
protected $query;
protected $request;
protected $fields;
protected Builder $query;
protected Request $request;

/**
* @var string[]
*/
protected array $fields;

/**
* @var array<callable>
*/
protected $resultModifiers = [];
protected array $resultModifiers = [];

protected $filterOperators = [
/**
* @var array<string, string>
*/
protected array $filterOperators = [
'eq' => '=',
'ne' => '!=',
'gt' => '>',
Expand Down Expand Up @@ -62,9 +70,9 @@ public function toResponse(): JsonResponse
/**
* Add a callback to modify each element of the results.
*
* @param (callable(Model)) $modifier
* @param (callable(Model): void) $modifier
*/
public function modifyResults($modifier): void
public function modifyResults(callable $modifier): void
{
$this->resultModifiers[] = $modifier;
}
Expand Down
9 changes: 4 additions & 5 deletions app/Auth/Access/Oidc/OidcJwtSigningKey.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,10 @@ protected function loadFromJwkArray(array $jwk)
throw new OidcInvalidKeyException("Only RS256 keys are currently supported. Found key using {$alg}");
}

if (empty($jwk['use'])) {
throw new OidcInvalidKeyException('A "use" parameter on the provided key is expected');
}

if ($jwk['use'] !== 'sig') {
// 'use' is optional for a JWK but we assume 'sig' where no value exists since that's what
// the OIDC discovery spec infers since 'sig' MUST be set if encryption keys come into play.
$use = $jwk['use'] ?? 'sig';
if ($use !== 'sig') {
throw new OidcInvalidKeyException("Only signature keys are currently supported. Found key for use {$jwk['use']}");
}

Expand Down
42 changes: 10 additions & 32 deletions app/Auth/Access/Oidc/OidcProviderSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,40 +15,17 @@
*/
class OidcProviderSettings
{
/**
* @var string
*/
public $issuer;

/**
* @var string
*/
public $clientId;

/**
* @var string
*/
public $clientSecret;

/**
* @var string
*/
public $redirectUri;

/**
* @var string
*/
public $authorizationEndpoint;

/**
* @var string
*/
public $tokenEndpoint;
public string $issuer;
public string $clientId;
public string $clientSecret;
public ?string $redirectUri;
public ?string $authorizationEndpoint;
public ?string $tokenEndpoint;

/**
* @var string[]|array[]
*/
public $keys = [];
public ?array $keys = [];

public function __construct(array $settings)
{
Expand Down Expand Up @@ -164,9 +141,10 @@ protected function loadSettingsFromIssuerDiscovery(ClientInterface $httpClient):
protected function filterKeys(array $keys): array
{
return array_filter($keys, function (array $key) {
$alg = $key['alg'] ?? null;
$alg = $key['alg'] ?? 'RS256';
$use = $key['use'] ?? 'sig';

return $key['kty'] === 'RSA' && $key['use'] === 'sig' && (is_null($alg) || $alg === 'RS256');
return $key['kty'] === 'RSA' && $use === 'sig' && $alg === 'RS256';
});
}

Expand Down
1 change: 0 additions & 1 deletion app/Auth/Access/Oidc/OidcService.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ public function login(): array
{
$settings = $this->getProviderSettings();
$provider = $this->getProvider($settings);

return [
'url' => $provider->getAuthorizationUrl(),
'state' => $provider->getState(),
Expand Down
4 changes: 2 additions & 2 deletions app/Auth/Permissions/JointPermissionBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class JointPermissionBuilder
/**
* @var array<string, array<int, SimpleEntityData>>
*/
protected $entityCache;
protected array $entityCache;

/**
* Re-generate all entity permission from scratch.
Expand Down Expand Up @@ -230,7 +230,7 @@ protected function entitiesToSimpleEntities(array $entities): array
/**
* Create & Save entity jointPermissions for many entities and roles.
*
* @param Entity[] $entities
* @param Entity[] $originalEntities
* @param Role[] $roles
*/
protected function createManyJointPermissions(array $originalEntities, array $roles)
Expand Down
35 changes: 35 additions & 0 deletions app/Auth/Queries/RolesAllPaginatedAndSorted.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

namespace BookStack\Auth\Queries;

use BookStack\Auth\Role;
use BookStack\Util\SimpleListOptions;
use Illuminate\Pagination\LengthAwarePaginator;

/**
* Get all the roles in the system in a paginated format.
*/
class RolesAllPaginatedAndSorted
{
public function run(int $count, SimpleListOptions $listOptions): LengthAwarePaginator
{
$sort = $listOptions->getSort();
if ($sort === 'created_at') {
$sort = 'users.created_at';
}

$query = Role::query()->select(['*'])
->withCount(['users', 'permissions'])
->orderBy($sort, $listOptions->getOrder());

if ($listOptions->getSearch()) {
$term = '%' . $listOptions->getSearch() . '%';
$query->where(function ($query) use ($term) {
$query->where('display_name', 'like', $term)
->orWhere('description', 'like', $term);
});
}

return $query->paginate($count);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace BookStack\Auth\Queries;

use BookStack\Auth\User;
use BookStack\Util\SimpleListOptions;
use Illuminate\Pagination\LengthAwarePaginator;

/**
Expand All @@ -11,23 +12,23 @@
* user is assumed to be trusted. (Admin users).
* Email search can be abused to extract email addresses.
*/
class AllUsersPaginatedAndSorted
class UsersAllPaginatedAndSorted
{
/**
* @param array{sort: string, order: string, search: string} $sortData
*/
public function run(int $count, array $sortData): LengthAwarePaginator
public function run(int $count, SimpleListOptions $listOptions): LengthAwarePaginator
{
$sort = $sortData['sort'];
$sort = $listOptions->getSort();
if ($sort === 'created_at') {
$sort = 'users.created_at';
}

$query = User::query()->select(['*'])
->scopes(['withLastActivityAt'])
->with(['roles', 'avatar'])
->withCount('mfaValues')
->orderBy($sort, $sortData['order']);
->orderBy($sort, $listOptions->getOrder());

if ($sortData['search']) {
$term = '%' . $sortData['search'] . '%';
if ($listOptions->getSearch()) {
$term = '%' . $listOptions->getSearch() . '%';
$query->where(function ($query) use ($term) {
$query->where('name', 'like', $term)
->orWhere('email', 'like', $term);
Expand Down
8 changes: 0 additions & 8 deletions app/Auth/Role.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,14 +110,6 @@ public static function getSystemRole(string $systemName): ?self
return static::query()->where('system_name', '=', $systemName)->first();
}

/**
* Get all visible roles.
*/
public static function visible(): Collection
{
return static::query()->where('hidden', '=', false)->orderBy('name')->get();
}

/**
* {@inheritdoc}
*/
Expand Down
3 changes: 3 additions & 0 deletions app/Auth/UserRepo.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,9 @@ public function destroy(User $user, ?int $newOwnerId = null)
// Delete user profile images
$this->userAvatar->destroyAllForUser($user);

// Delete related activities
setting()->deleteUserSettings($user->id);

if (!empty($newOwnerId)) {
$newOwner = User::query()->find($newOwnerId);
if (!is_null($newOwner)) {
Expand Down
2 changes: 1 addition & 1 deletion app/Config/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
'locale' => env('APP_LANG', 'en'),

// Locales available
'locales' => ['en', 'ar', 'bg', 'bs', 'ca', 'cs', 'cy', 'da', 'de', 'de_informal', 'el', 'es', 'es_AR', 'et', 'eu', 'fa', 'fr', 'he', 'hr', 'hu', 'id', 'it', 'ja', 'ko', 'lt', 'lv', 'nl', 'nb', 'pt', 'pt_BR', 'sk', 'sl', 'sv', 'pl', 'ro', 'ru', 'tr', 'uk', 'uz', 'vi', 'zh_CN', 'zh_TW'],
'locales' => ['en', 'ar', 'bg', 'bs', 'ca', 'cs', 'cy', 'da', 'de', 'de_informal', 'el', 'es', 'es_AR', 'et', 'eu', 'fa', 'fr', 'he', 'hr', 'hu', 'id', 'it', 'ja', 'ka', 'ko', 'lt', 'lv', 'nl', 'nb', 'pt', 'pt_BR', 'sk', 'sl', 'sv', 'pl', 'ro', 'ru', 'tr', 'uk', 'uz', 'vi', 'zh_CN', 'zh_TW'],

// Application Fallback Locale
'fallback_locale' => 'en',
Expand Down
Loading

0 comments on commit 914790f

Please sign in to comment.