Skip to content

Commit

Permalink
Revert "feat: support Illuminate\Auth\Access\Response returns from ga…
Browse files Browse the repository at this point in the history
…tes/poli…"

This reverts commit 0f7dc1d.
  • Loading branch information
lindyhopchris committed Nov 29, 2024
1 parent 1ea2289 commit 9ab61d5
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 42 deletions.
1 change: 0 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
"require": {
"php": "^8.2",
"ext-json": "*",
"illuminate/auth": "^11.33",
"illuminate/contracts": "^11.0",
"illuminate/http": "^11.0",
"illuminate/support": "^11.0"
Expand Down
41 changes: 20 additions & 21 deletions src/Contracts/Auth/Authorizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

namespace LaravelJsonApi\Contracts\Auth;

use Illuminate\Auth\Access\Response;
use Illuminate\Http\Request;

interface Authorizer
Expand All @@ -21,93 +20,93 @@ interface Authorizer
*
* @param Request $request
* @param string $modelClass
* @return bool|Response
* @return bool
*/
public function index(Request $request, string $modelClass): bool|Response;
public function index(Request $request, string $modelClass): bool;

/**
* Authorize the store controller action.
*
* @param Request $request
* @param string $modelClass
* @return bool|Response
* @return bool
*/
public function store(Request $request, string $modelClass): bool|Response;
public function store(Request $request, string $modelClass): bool;

/**
* Authorize the show controller action.
*
* @param Request $request
* @param object $model
* @return bool|Response
* @return bool
*/
public function show(Request $request, object $model): bool|Response;
public function show(Request $request, object $model): bool;

/**
* Authorize the update controller action.
*
* @param object $model
* @param Request $request
* @return bool|Response
* @return bool
*/
public function update(Request $request, object $model): bool|Response;
public function update(Request $request, object $model): bool;

/**
* Authorize the destroy controller action.
*
* @param Request $request
* @param object $model
* @return bool|Response
* @return bool
*/
public function destroy(Request $request, object $model): bool|Response;
public function destroy(Request $request, object $model): bool;

/**
* Authorize the show-related controller action.
*
* @param Request $request
* @param object $model
* @param string $fieldName
* @return bool|Response
* @return bool
*/
public function showRelated(Request $request, object $model, string $fieldName): bool|Response;
public function showRelated(Request $request, object $model, string $fieldName): bool;

/**
* Authorize the show-relationship controller action.
*
* @param Request $request
* @param object $model
* @param string $fieldName
* @return bool|Response
* @return bool
*/
public function showRelationship(Request $request, object $model, string $fieldName): bool|Response;
public function showRelationship(Request $request, object $model, string $fieldName): bool;

/**
* Authorize the update-relationship controller action.
*
* @param Request $request
* @param object $model
* @param string $fieldName
* @return bool|Response
* @return bool
*/
public function updateRelationship(Request $request, object $model, string $fieldName): bool|Response;
public function updateRelationship(Request $request, object $model, string $fieldName): bool;

/**
* Authorize the attach-relationship controller action.
*
* @param Request $request
* @param object $model
* @param string $fieldName
* @return bool|Response
* @return bool
*/
public function attachRelationship(Request $request, object $model, string $fieldName): bool|Response;
public function attachRelationship(Request $request, object $model, string $fieldName): bool;

/**
* Authorize the detach-relationship controller action.
*
* @param Request $request
* @param object $model
* @param string $fieldName
* @return bool|Response
* @return bool
*/
public function detachRelationship(Request $request, object $model, string $fieldName): bool|Response;
public function detachRelationship(Request $request, object $model, string $fieldName): bool;
}
39 changes: 19 additions & 20 deletions src/Core/Auth/Authorizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
namespace LaravelJsonApi\Core\Auth;

use Illuminate\Contracts\Auth\Access\Gate;
use Illuminate\Auth\Access\Response;
use Illuminate\Http\Request;
use LaravelJsonApi\Contracts\Auth\Authorizer as AuthorizerContract;
use LaravelJsonApi\Contracts\Schema\Schema;
Expand Down Expand Up @@ -48,10 +47,10 @@ public function __construct(Gate $gate, JsonApiService $service)
/**
* @inheritDoc
*/
public function index(Request $request, string $modelClass): bool|Response
public function index(Request $request, string $modelClass): bool
{
if ($this->mustAuthorize()) {
return $this->gate->inspect(
return $this->gate->check(
'viewAny',
$modelClass
);
Expand All @@ -63,10 +62,10 @@ public function index(Request $request, string $modelClass): bool|Response
/**
* @inheritDoc
*/
public function store(Request $request, string $modelClass): bool|Response
public function store(Request $request, string $modelClass): bool
{
if ($this->mustAuthorize()) {
return $this->gate->inspect(
return $this->gate->check(
'create',
$modelClass
);
Expand All @@ -78,10 +77,10 @@ public function store(Request $request, string $modelClass): bool|Response
/**
* @inheritDoc
*/
public function show(Request $request, object $model): bool|Response
public function show(Request $request, object $model): bool
{
if ($this->mustAuthorize()) {
return $this->gate->inspect(
return $this->gate->check(
'view',
$model
);
Expand All @@ -93,10 +92,10 @@ public function show(Request $request, object $model): bool|Response
/**
* @inheritDoc
*/
public function update(Request $request, object $model): bool|Response
public function update(Request $request, object $model): bool
{
if ($this->mustAuthorize()) {
return $this->gate->inspect(
return $this->gate->check(
'update',
$model
);
Expand All @@ -108,10 +107,10 @@ public function update(Request $request, object $model): bool|Response
/**
* @inheritDoc
*/
public function destroy(Request $request, object $model): bool|Response
public function destroy(Request $request, object $model): bool
{
if ($this->mustAuthorize()) {
return $this->gate->inspect(
return $this->gate->check(
'delete',
$model
);
Expand All @@ -123,10 +122,10 @@ public function destroy(Request $request, object $model): bool|Response
/**
* @inheritDoc
*/
public function showRelated(Request $request, object $model, string $fieldName): bool|Response
public function showRelated(Request $request, object $model, string $fieldName): bool
{
if ($this->mustAuthorize()) {
return $this->gate->inspect(
return $this->gate->check(
'view' . Str::classify($fieldName),
$model
);
Expand All @@ -138,18 +137,18 @@ public function showRelated(Request $request, object $model, string $fieldName):
/**
* @inheritDoc
*/
public function showRelationship(Request $request, object $model, string $fieldName): bool|Response
public function showRelationship(Request $request, object $model, string $fieldName): bool
{
return $this->showRelated($request, $model, $fieldName);
}

/**
* @inheritDoc
*/
public function updateRelationship(Request $request, object $model, string $fieldName): bool|Response
public function updateRelationship(Request $request, object $model, string $fieldName): bool
{
if ($this->mustAuthorize()) {
return $this->gate->inspect(
return $this->gate->check(
'update' . Str::classify($fieldName),
[$model, $this->createRelation($request, $fieldName)]
);
Expand All @@ -161,10 +160,10 @@ public function updateRelationship(Request $request, object $model, string $fiel
/**
* @inheritDoc
*/
public function attachRelationship(Request $request, object $model, string $fieldName): bool|Response
public function attachRelationship(Request $request, object $model, string $fieldName): bool
{
if ($this->mustAuthorize()) {
return $this->gate->inspect(
return $this->gate->check(
'attach' . Str::classify($fieldName),
[$model, $this->createRelation($request, $fieldName)]
);
Expand All @@ -176,10 +175,10 @@ public function attachRelationship(Request $request, object $model, string $fiel
/**
* @inheritDoc
*/
public function detachRelationship(Request $request, object $model, string $fieldName): bool|Response
public function detachRelationship(Request $request, object $model, string $fieldName): bool
{
if ($this->mustAuthorize()) {
return $this->gate->inspect(
return $this->gate->check(
'detach' . Str::classify($fieldName),
[$model, $this->createRelation($request, $fieldName)]
);
Expand Down

0 comments on commit 9ab61d5

Please sign in to comment.