Skip to content

Commit aa3e58c

Browse files
authored
Merge pull request #749 from code16/authorizations-checks
Add more entity checks
2 parents ea0033f + 7c026ca commit aa3e58c

14 files changed

Lines changed: 58 additions & 8 deletions

src/Http/Controllers/Api/ApiFilterAutocompleteController.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ class ApiFilterAutocompleteController extends Controller
1111
{
1212
public function index(string $globalFilter, EntityKey $entityKey, string $filterHandlerKey): array
1313
{
14+
$this->authorizationManager->check('entity', $entityKey);
15+
1416
$entity = $this->entityManager->entityFor($entityKey);
1517

1618
if ($entity instanceof SharpDashboardEntity) {

src/Http/Controllers/Api/ApiFormAutocompleteController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class ApiFormAutocompleteController extends Controller
1818

1919
public function index(string $globalFilter, EntityKey $entityKey, string $autocompleteFieldKey)
2020
{
21-
$fieldContainer = $this->getFieldContainer($entityKey);
21+
$fieldContainer = $this->getFieldContainer($entityKey, isUpdate: false);
2222
$field = $fieldContainer->findFieldByKey($autocompleteFieldKey);
2323

2424
if ($field === null) {

src/Http/Controllers/Api/ApiFormRefreshController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class ApiFormRefreshController extends Controller
1111

1212
public function update(string $globalFilter, EntityKey $entityKey)
1313
{
14-
$fieldContainer = $this->getFieldContainer($entityKey);
14+
$fieldContainer = $this->getFieldContainer($entityKey, isUpdate: false);
1515

1616
return response()->json([
1717
'form' => [

src/Http/Controllers/Api/ApiFormUploadController.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@ class ApiFormUploadController extends Controller
1616

1717
public function store(string $globalFilter, EntityKey $entityKey, string $uploadFieldKey, FileUtil $fileUtil)
1818
{
19-
$field = $this->getFieldContainer($entityKey)
20-
->findFieldByKey($uploadFieldKey);
19+
$container = $this->getFieldContainer($entityKey, isUpdate: true);
20+
21+
$field = $container->findFieldByKey($uploadFieldKey);
2122

2223
if ($field instanceof SharpFormEditorField) {
2324
$field = $field->uploadsConfig();

src/Http/Controllers/Api/Commands/ApiDashboardCommandController.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ public function __construct(
2020

2121
public function show(string $globalFilter, string $entityKey, string $commandKey)
2222
{
23+
$this->authorizationManager->check('entity', $entityKey);
24+
2325
$dashboard = $this->entityManager->entityFor($entityKey)->getViewOrFail();
2426
$dashboard->buildDashboardConfig();
2527
$dashboard->initQueryParams(request()->query());
@@ -35,6 +37,8 @@ public function show(string $globalFilter, string $entityKey, string $commandKey
3537

3638
public function update(string $globalFilter, string $entityKey, string $commandKey)
3739
{
40+
$this->authorizationManager->check('entity', $entityKey);
41+
3842
$dashboard = $this->entityManager->entityFor($entityKey)->getViewOrFail();
3943
$dashboard->buildDashboardConfig();
4044
$dashboard->initQueryParams(request()->input('query'));

src/Http/Controllers/Api/Commands/ApiEntityListEntityCommandController.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ public function __construct(
2020

2121
public function show(string $globalFilter, string $entityKey, string $commandKey)
2222
{
23+
$this->authorizationManager->check('entity', $entityKey);
24+
2325
$list = $this->entityManager->entityFor($entityKey)->getListOrFail();
2426
$list->buildListConfig();
2527
$list->initQueryParams(request()->query());
@@ -35,6 +37,8 @@ public function show(string $globalFilter, string $entityKey, string $commandKey
3537

3638
public function update(string $globalFilter, string $entityKey, string $commandKey)
3739
{
40+
$this->authorizationManager->check('entity', $entityKey);
41+
3842
$list = $this->entityManager->entityFor($entityKey)->getListOrFail();
3943
$list->buildListConfig();
4044
$list->initQueryParams(request()->input('query'));

src/Http/Controllers/Api/Commands/ApiEntityListEntityStateController.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ class ApiEntityListEntityStateController extends Controller
1212

1313
public function update(string $globalFilter, string $entityKey, mixed $instanceId)
1414
{
15+
$this->authorizationManager->check('entity', $entityKey);
16+
1517
$list = $this->entityManager->entityFor($entityKey)->getListOrFail();
1618
$list->buildListConfig();
1719
$list->initQueryParams(request()->input('query'));

src/Http/Controllers/Api/Commands/ApiEntityListInstanceCommandController.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ public function __construct(
2020

2121
public function show(string $globalFilter, string $entityKey, string $commandKey, mixed $instanceId)
2222
{
23+
$this->authorizationManager->check('entity', $entityKey);
24+
2325
$list = $this->entityManager->entityFor($entityKey)->getListOrFail();
2426
$list->buildListConfig();
2527
$list->initQueryParams(request()->query());
@@ -38,6 +40,8 @@ public function show(string $globalFilter, string $entityKey, string $commandKey
3840
*/
3941
public function update(string $globalFilter, string $entityKey, string $commandKey, mixed $instanceId)
4042
{
43+
$this->authorizationManager->check('entity', $entityKey);
44+
4145
$list = $this->entityManager->entityFor($entityKey)->getListOrFail();
4246
$list->buildListConfig();
4347
$list->initQueryParams(request()->input('query'));

src/Http/Controllers/Api/Commands/ApiShowEntityStateController.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ class ApiShowEntityStateController extends Controller
1313

1414
public function update(string $globalFilter, string $entityKey, mixed $instanceId = null)
1515
{
16+
$this->authorizationManager->check('view', $entityKey, $instanceId);
17+
1618
$showPage = $this->getShowPage($entityKey, $instanceId);
1719
$stateHandler = $showPage->entityStateHandler();
1820

src/Http/Controllers/Api/Commands/ApiShowInstanceCommandController.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ public function __construct(
2121

2222
public function show(string $globalFilter, string $entityKey, string $commandKey, mixed $instanceId = null)
2323
{
24+
$this->authorizationManager->check('view', $entityKey, $instanceId);
25+
2426
$showPage = $this->getShowPage($entityKey, $instanceId);
2527
$commandHandler = $this->getInstanceCommandHandler($showPage, $commandKey, $instanceId);
2628

@@ -33,6 +35,8 @@ public function show(string $globalFilter, string $entityKey, string $commandKey
3335

3436
public function update(string $globalFilter, string $entityKey, string $commandKey, mixed $instanceId = null)
3537
{
38+
$this->authorizationManager->check('view', $entityKey, $instanceId);
39+
3640
$showPage = $this->getShowPage($entityKey, $instanceId);
3741
$commandHandler = $this->getInstanceCommandHandler($showPage, $commandKey, $instanceId);
3842

0 commit comments

Comments
 (0)