Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Simplified and aligned handling of mixed entity endpoints
Fixes #4444
- Loading branch information
1 parent
3928cba
commit 2fbf552
Showing
8 changed files
with
67 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
|
||
namespace BookStack\Entities\Tools; | ||
|
||
use BookStack\Entities\EntityProvider; | ||
use BookStack\Entities\Models\Entity; | ||
|
||
class MixedEntityRequestHelper | ||
{ | ||
public function __construct( | ||
protected EntityProvider $entities, | ||
) { | ||
} | ||
|
||
/** | ||
* Query out an entity, visible to the current user, for the given | ||
* entity request details (this provided in a request validated by | ||
* this classes' validationRules method). | ||
* @param array{type: string, id: string} $requestData | ||
*/ | ||
public function getVisibleEntityFromRequestData(array $requestData): Entity | ||
{ | ||
$entityType = $this->entities->get($requestData['type']); | ||
|
||
return $entityType->newQuery()->scopes(['visible'])->findOrFail($requestData['id']); | ||
} | ||
|
||
/** | ||
* Get the validation rules for an abstract entity request. | ||
* @return array{type: string[], id: string[]} | ||
*/ | ||
public function validationRules(): array | ||
{ | ||
return [ | ||
'type' => ['required', 'string'], | ||
'id' => ['required', 'integer'], | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters