Applied StyleCi changes, updated php deps

This commit is contained in:
Dan Brown 2022-08-29 17:46:41 +01:00
parent e537d0c4e8
commit 1cc7c649dc
No known key found for this signature in database
GPG Key ID: 46D9F943C24A2EF9
26 changed files with 435 additions and 526 deletions

View File

@ -31,7 +31,7 @@ class OidcOAuthProvider extends AbstractProvider
protected $tokenEndpoint; protected $tokenEndpoint;
/** /**
* Scopes to use for the OIDC authorization call * Scopes to use for the OIDC authorization call.
*/ */
protected array $scopes = ['openid', 'profile', 'email']; protected array $scopes = ['openid', 'profile', 'email'];

View File

@ -2,9 +2,8 @@
namespace BookStack\Auth\Access\Oidc; namespace BookStack\Auth\Access\Oidc;
use BookStack\Auth\Access\GroupSyncService;
use Illuminate\Support\Arr;
use function auth; use function auth;
use BookStack\Auth\Access\GroupSyncService;
use BookStack\Auth\Access\LoginService; use BookStack\Auth\Access\LoginService;
use BookStack\Auth\Access\RegistrationService; use BookStack\Auth\Access\RegistrationService;
use BookStack\Auth\User; use BookStack\Auth\User;
@ -12,6 +11,7 @@ use BookStack\Exceptions\JsonDebugException;
use BookStack\Exceptions\StoppedAuthenticationException; use BookStack\Exceptions\StoppedAuthenticationException;
use BookStack\Exceptions\UserRegistrationException; use BookStack\Exceptions\UserRegistrationException;
use function config; use function config;
use Illuminate\Support\Arr;
use Illuminate\Support\Facades\Cache; use Illuminate\Support\Facades\Cache;
use League\OAuth2\Client\OptionProvider\HttpBasicAuthOptionProvider; use League\OAuth2\Client\OptionProvider\HttpBasicAuthOptionProvider;
use League\OAuth2\Client\Provider\Exception\IdentityProviderException; use League\OAuth2\Client\Provider\Exception\IdentityProviderException;
@ -35,11 +35,10 @@ class OidcService
*/ */
public function __construct( public function __construct(
RegistrationService $registrationService, RegistrationService $registrationService,
LoginService $loginService, LoginService $loginService,
HttpClient $httpClient, HttpClient $httpClient,
GroupSyncService $groupService GroupSyncService $groupService
) ) {
{
$this->registrationService = $registrationService; $this->registrationService = $registrationService;
$this->loginService = $loginService; $this->loginService = $loginService;
$this->httpClient = $httpClient; $this->httpClient = $httpClient;
@ -148,7 +147,7 @@ class OidcService
$scopeConfig = $this->config()['additional_scopes'] ?: ''; $scopeConfig = $this->config()['additional_scopes'] ?: '';
$scopeArr = explode(',', $scopeConfig); $scopeArr = explode(',', $scopeConfig);
$scopeArr = array_map(fn(string $scope) => trim($scope), $scopeArr); $scopeArr = array_map(fn (string $scope) => trim($scope), $scopeArr);
return array_filter($scopeArr); return array_filter($scopeArr);
} }
@ -192,7 +191,7 @@ class OidcService
return []; return [];
} }
return array_values(array_filter($groupsList, function($val) { return array_values(array_filter($groupsList, function ($val) {
return is_string($val); return is_string($val);
})); }));
} }

View File

@ -22,7 +22,7 @@ return [
// The number of revisions to keep in the database. // The number of revisions to keep in the database.
// Once this limit is reached older revisions will be deleted. // Once this limit is reached older revisions will be deleted.
// If set to false then a limit will not be enforced. // If set to false then a limit will not be enforced.
'revision_limit' => env('REVISION_LIMIT', 100), 'revision_limit' => env('REVISION_LIMIT', 100),
// The number of days that content will remain in the recycle bin before // The number of days that content will remain in the recycle bin before
// being considered for auto-removal. It is not a guarantee that content will // being considered for auto-removal. It is not a guarantee that content will

View File

@ -58,6 +58,7 @@ class RegenerateCommentContent extends Command
DB::setDefaultConnection($connection); DB::setDefaultConnection($connection);
$this->comment('Comment HTML content has been regenerated'); $this->comment('Comment HTML content has been regenerated');
return 0; return 0;
} }
} }

View File

@ -50,6 +50,7 @@ class RegeneratePermissions extends Command
DB::setDefaultConnection($connection); DB::setDefaultConnection($connection);
$this->comment('Permissions regenerated'); $this->comment('Permissions regenerated');
return 0; return 0;
} }
} }

View File

@ -53,6 +53,7 @@ class RegenerateReferences extends Command
DB::setDefaultConnection($connection); DB::setDefaultConnection($connection);
$this->comment('References have been regenerated'); $this->comment('References have been regenerated');
return 0; return 0;
} }
} }

View File

@ -32,12 +32,11 @@ class PageRepo
* PageRepo constructor. * PageRepo constructor.
*/ */
public function __construct( public function __construct(
BaseRepo $baseRepo, BaseRepo $baseRepo,
RevisionRepo $revisionRepo, RevisionRepo $revisionRepo,
ReferenceStore $referenceStore, ReferenceStore $referenceStore,
ReferenceUpdater $referenceUpdater ReferenceUpdater $referenceUpdater
) ) {
{
$this->baseRepo = $baseRepo; $this->baseRepo = $baseRepo;
$this->revisionRepo = $revisionRepo; $this->revisionRepo = $revisionRepo;
$this->referenceStore = $referenceStore; $this->referenceStore = $referenceStore;
@ -135,11 +134,11 @@ class PageRepo
public function getNewDraftPage(Entity $parent) public function getNewDraftPage(Entity $parent)
{ {
$page = (new Page())->forceFill([ $page = (new Page())->forceFill([
'name' => trans('entities.pages_initial_name'), 'name' => trans('entities.pages_initial_name'),
'created_by' => user()->id, 'created_by' => user()->id,
'owned_by' => user()->id, 'owned_by' => user()->id,
'updated_by' => user()->id, 'updated_by' => user()->id,
'draft' => true, 'draft' => true,
]); ]);
if ($parent instanceof Chapter) { if ($parent instanceof Chapter) {

View File

@ -23,7 +23,6 @@ class ChapterController extends Controller
protected ChapterRepo $chapterRepo; protected ChapterRepo $chapterRepo;
protected ReferenceFetcher $referenceFetcher; protected ReferenceFetcher $referenceFetcher;
public function __construct(ChapterRepo $chapterRepo, ReferenceFetcher $referenceFetcher) public function __construct(ChapterRepo $chapterRepo, ReferenceFetcher $referenceFetcher)
{ {
$this->chapterRepo = $chapterRepo; $this->chapterRepo = $chapterRepo;

View File

@ -27,7 +27,7 @@ class ReferenceController extends Controller
$references = $this->referenceFetcher->getPageReferencesToEntity($page); $references = $this->referenceFetcher->getPageReferencesToEntity($page);
return view('pages.references', [ return view('pages.references', [
'page' => $page, 'page' => $page,
'references' => $references, 'references' => $references,
]); ]);
} }
@ -42,7 +42,7 @@ class ReferenceController extends Controller
$references = $this->referenceFetcher->getPageReferencesToEntity($chapter); $references = $this->referenceFetcher->getPageReferencesToEntity($chapter);
return view('chapters.references', [ return view('chapters.references', [
'chapter' => $chapter, 'chapter' => $chapter,
'references' => $references, 'references' => $references,
]); ]);
} }
@ -56,7 +56,7 @@ class ReferenceController extends Controller
$references = $this->referenceFetcher->getPageReferencesToEntity($book); $references = $this->referenceFetcher->getPageReferencesToEntity($book);
return view('books.references', [ return view('books.references', [
'book' => $book, 'book' => $book,
'references' => $references, 'references' => $references,
]); ]);
} }
@ -70,7 +70,7 @@ class ReferenceController extends Controller
$references = $this->referenceFetcher->getPageReferencesToEntity($shelf); $references = $this->referenceFetcher->getPageReferencesToEntity($shelf);
return view('shelves.references', [ return view('shelves.references', [
'shelf' => $shelf, 'shelf' => $shelf,
'references' => $references, 'references' => $references,
]); ]);
} }

View File

@ -99,5 +99,4 @@ class CrossLinkParser
new BookshelfLinkModelResolver(), new BookshelfLinkModelResolver(),
]); ]);
} }
} }

View File

@ -19,7 +19,7 @@ class BookLinkModelResolver implements CrossLinkModelResolver
$bookSlug = $matches[1]; $bookSlug = $matches[1];
/** @var ?Book $model */ /** @var ?Book $model */
$model = Book::query()->where('slug', '=', $bookSlug)->first(['id']); $model = Book::query()->where('slug', '=', $bookSlug)->first(['id']);
return $model; return $model;
} }

View File

@ -19,7 +19,7 @@ class BookshelfLinkModelResolver implements CrossLinkModelResolver
$shelfSlug = $matches[1]; $shelfSlug = $matches[1];
/** @var ?Bookshelf $model */ /** @var ?Bookshelf $model */
$model = Bookshelf::query()->where('slug', '=', $shelfSlug)->first(['id']); $model = Bookshelf::query()->where('slug', '=', $shelfSlug)->first(['id']);
return $model; return $model;
} }

View File

@ -2,14 +2,13 @@
namespace BookStack\References; namespace BookStack\References;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\MorphTo; use Illuminate\Database\Eloquent\Relations\MorphTo;
/** /**
* @property int $from_id * @property int $from_id
* @property string $from_type * @property string $from_type
* @property int $to_id * @property int $to_id
* @property string $to_type * @property string $to_type
*/ */
class Reference extends Model class Reference extends Model

View File

@ -26,9 +26,9 @@ class ReferenceFetcher
$baseQuery = $entity->referencesTo() $baseQuery = $entity->referencesTo()
->where('from_type', '=', (new Page())->getMorphClass()) ->where('from_type', '=', (new Page())->getMorphClass())
->with([ ->with([
'from' => fn(Relation $query) => $query->select(Page::$listAttributes), 'from' => fn (Relation $query) => $query->select(Page::$listAttributes),
'from.book' => fn(Relation $query) => $query->scopes('visible'), 'from.book' => fn (Relation $query) => $query->scopes('visible'),
'from.chapter' => fn(Relation $query) => $query->scopes('visible') 'from.chapter' => fn (Relation $query) => $query->scopes('visible'),
]); ]);
$references = $this->permissions->restrictEntityRelationQuery( $references = $this->permissions->restrictEntityRelationQuery(

View File

@ -7,7 +7,6 @@ use Illuminate\Database\Eloquent\Collection;
class ReferenceStore class ReferenceStore
{ {
/** /**
* Update the outgoing references for the given page. * Update the outgoing references for the given page.
*/ */
@ -25,7 +24,7 @@ class ReferenceStore
->where('from_type', '=', (new Page())->getMorphClass()) ->where('from_type', '=', (new Page())->getMorphClass())
->delete(); ->delete();
Page::query()->select(['id', 'html'])->chunk(100, function(Collection $pages) { Page::query()->select(['id', 'html'])->chunk(100, function (Collection $pages) {
$this->updateForPages($pages->all()); $this->updateForPages($pages->all());
}); });
} }
@ -44,7 +43,7 @@ class ReferenceStore
$parser = CrossLinkParser::createWithEntityResolvers(); $parser = CrossLinkParser::createWithEntityResolvers();
$references = []; $references = [];
$pageIds = array_map(fn(Page $page) => $page->id, $pages); $pageIds = array_map(fn (Page $page) => $page->id, $pages);
Reference::query() Reference::query()
->where('from_type', '=', $pages[0]->getMorphClass()) ->where('from_type', '=', $pages[0]->getMorphClass())
->whereIn('from_id', $pageIds) ->whereIn('from_id', $pageIds)
@ -55,10 +54,10 @@ class ReferenceStore
foreach ($models as $model) { foreach ($models as $model) {
$references[] = [ $references[] = [
'from_id' => $page->id, 'from_id' => $page->id,
'from_type' => $page->getMorphClass(), 'from_type' => $page->getMorphClass(),
'to_id' => $model->id, 'to_id' => $model->id,
'to_type' => $model->getMorphClass(), 'to_type' => $model->getMorphClass(),
]; ];
} }
} }
@ -67,5 +66,4 @@ class ReferenceStore
Reference::query()->insert($referenceDataChunk); Reference::query()->insert($referenceDataChunk);
} }
} }
} }

821
composer.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -374,7 +374,7 @@ class OidcTest extends TestCase
$resp = $this->runLogin([ $resp = $this->runLogin([
'email' => 'benny@example.com', 'email' => 'benny@example.com',
'sub' => 'benny1010101', 'sub' => 'benny1010101',
'groups' => ['Wizards', 'Zookeepers'] 'groups' => ['Wizards', 'Zookeepers'],
]); ]);
$resp->assertRedirect('/'); $resp->assertRedirect('/');
@ -398,13 +398,13 @@ class OidcTest extends TestCase
$resp = $this->runLogin([ $resp = $this->runLogin([
'email' => 'benny@example.com', 'email' => 'benny@example.com',
'sub' => 'benny1010101', 'sub' => 'benny1010101',
'my' => [ 'my' => [
'custom' => [ 'custom' => [
'groups' => [ 'groups' => [
'attr' => ['Wizards'] 'attr' => ['Wizards'],
] ],
] ],
] ],
]); ]);
$resp->assertRedirect('/'); $resp->assertRedirect('/');

View File

@ -23,10 +23,10 @@ class RegenerateReferencesCommandTest extends TestCase
->assertExitCode(0); ->assertExitCode(0);
$this->assertDatabaseHas('references', [ $this->assertDatabaseHas('references', [
'from_id' => $page->id, 'from_id' => $page->id,
'from_type' => $page->getMorphClass(), 'from_type' => $page->getMorphClass(),
'to_id' => $book->id, 'to_id' => $book->id,
'to_type' => $book->getMorphClass(), 'to_type' => $book->getMorphClass(),
]); ]);
} }
} }

View File

@ -2,14 +2,12 @@
namespace Tests\References; namespace Tests\References;
use BookStack\Entities\Models\Book;
use BookStack\Entities\Models\Page; use BookStack\Entities\Models\Page;
use BookStack\References\CrossLinkParser; use BookStack\References\CrossLinkParser;
use Tests\TestCase; use Tests\TestCase;
class CrossLinkParserTest extends TestCase class CrossLinkParserTest extends TestCase
{ {
public function test_instance_with_entity_resolvers_matches_entity_links() public function test_instance_with_entity_resolvers_matches_entity_links()
{ {
$entities = $this->getEachEntityType(); $entities = $this->getEachEntityType();
@ -17,7 +15,7 @@ class CrossLinkParserTest extends TestCase
$html = ' $html = '
<a href="' . url('/link/' . $otherPage->id) . '#cat">Page Permalink</a> <a href="' . url('/link/' . $otherPage->id) . '#cat">Page Permalink</a>
<a href="' . $entities['page'] ->getUrl(). '?a=b">Page Link</a> <a href="' . $entities['page']->getUrl() . '?a=b">Page Link</a>
<a href="' . $entities['chapter']->getUrl() . '?cat=mouse#donkey">Chapter Link</a> <a href="' . $entities['chapter']->getUrl() . '?cat=mouse#donkey">Chapter Link</a>
<a href="' . $entities['book']->getUrl() . '/edit">Book Link</a> <a href="' . $entities['book']->getUrl() . '/edit">Book Link</a>
<a href="' . $entities['bookshelf']->getUrl() . '/edit?cat=happy#hello">Shelf Link</a> <a href="' . $entities['bookshelf']->getUrl() . '/edit?cat=happy#hello">Shelf Link</a>

View File

@ -12,7 +12,6 @@ use Tests\TestCase;
class ReferencesTest extends TestCase class ReferencesTest extends TestCase
{ {
public function test_references_created_on_page_update() public function test_references_created_on_page_update()
{ {
/** @var Page $pageA */ /** @var Page $pageA */
@ -24,14 +23,14 @@ class ReferencesTest extends TestCase
$this->asEditor()->put($pageA->getUrl(), [ $this->asEditor()->put($pageA->getUrl(), [
'name' => 'Reference test', 'name' => 'Reference test',
'html' => '<a href="' . $pageB->getUrl() . '">Testing</a>' 'html' => '<a href="' . $pageB->getUrl() . '">Testing</a>',
]); ]);
$this->assertDatabaseHas('references', [ $this->assertDatabaseHas('references', [
'from_id' => $pageA->id, 'from_id' => $pageA->id,
'from_type' => $pageA->getMorphClass(), 'from_type' => $pageA->getMorphClass(),
'to_id' => $pageB->id, 'to_id' => $pageB->id,
'to_type' => $pageB->getMorphClass(), 'to_type' => $pageB->getMorphClass(),
]); ]);
} }
@ -141,7 +140,7 @@ class ReferencesTest extends TestCase
$this->assertStringContainsString('href="http://localhost/books/my-updated-book-slugaroo"', $page->html); $this->assertStringContainsString('href="http://localhost/books/my-updated-book-slugaroo"', $page->html);
$this->assertDatabaseHas('page_revisions', [ $this->assertDatabaseHas('page_revisions', [
'page_id' => $page->id, 'page_id' => $page->id,
'summary' => 'System auto-update of internal links' 'summary' => 'System auto-update of internal links',
]); ]);
} }
} }
@ -179,10 +178,9 @@ class ReferencesTest extends TestCase
{ {
(new Reference())->forceFill([ (new Reference())->forceFill([
'from_type' => $from->getMorphClass(), 'from_type' => $from->getMorphClass(),
'from_id' => $from->id, 'from_id' => $from->id,
'to_type' => $to->getMorphClass(), 'to_type' => $to->getMorphClass(),
'to_id' => $to->id, 'to_id' => $to->id,
])->save(); ])->save();
} }
} }