Skip to content

Commit

Permalink
Merge branch 'release/5.0.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
lindyhopchris committed Nov 29, 2024
2 parents f84fa0a + 080798d commit f3a4b75
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 40 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file. This projec

## Unreleased

## [5.0.0] - 2024-11-29

### Added

- **BREAKING**: [#21](https://github.com/laravel-json-api/core/pull/21) The `Authorizer` contract now allows all methods
to return a `bool` or an Illuminate authorization response.

## [4.3.1] - 2024-11-29

### Fixed
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"require": {
"php": "^8.2",
"ext-json": "*",
"illuminate/auth": "^11.33",
"illuminate/contracts": "^11.0",
"illuminate/http": "^11.0",
"illuminate/support": "^11.0"
Expand All @@ -45,7 +46,7 @@
},
"extra": {
"branch-alias": {
"dev-develop": "4.x-dev"
"dev-develop": "5.x-dev"
}
},
"minimum-stability": "stable",
Expand Down
41 changes: 21 additions & 20 deletions src/Contracts/Auth/Authorizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace LaravelJsonApi\Contracts\Auth;

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

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

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

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

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

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

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

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

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

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

/**
* Authorize the detach-relationship controller action.
*
* @param Request $request
* @param object $model
* @param string $fieldName
* @return bool
* @return bool|Response
*/
public function detachRelationship(Request $request, object $model, string $fieldName): bool;
public function detachRelationship(Request $request, object $model, string $fieldName): bool|Response;
}
39 changes: 20 additions & 19 deletions src/Core/Auth/Authorizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
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 @@ -47,10 +48,10 @@ public function __construct(Gate $gate, JsonApiService $service)
/**
* @inheritDoc
*/
public function index(Request $request, string $modelClass): bool
public function index(Request $request, string $modelClass): bool|Response
{
if ($this->mustAuthorize()) {
return $this->gate->check(
return $this->gate->inspect(
'viewAny',
$modelClass
);
Expand All @@ -62,10 +63,10 @@ public function index(Request $request, string $modelClass): bool
/**
* @inheritDoc
*/
public function store(Request $request, string $modelClass): bool
public function store(Request $request, string $modelClass): bool|Response
{
if ($this->mustAuthorize()) {
return $this->gate->check(
return $this->gate->inspect(
'create',
$modelClass
);
Expand All @@ -77,10 +78,10 @@ public function store(Request $request, string $modelClass): bool
/**
* @inheritDoc
*/
public function show(Request $request, object $model): bool
public function show(Request $request, object $model): bool|Response
{
if ($this->mustAuthorize()) {
return $this->gate->check(
return $this->gate->inspect(
'view',
$model
);
Expand All @@ -92,10 +93,10 @@ public function show(Request $request, object $model): bool
/**
* @inheritDoc
*/
public function update(Request $request, object $model): bool
public function update(Request $request, object $model): bool|Response
{
if ($this->mustAuthorize()) {
return $this->gate->check(
return $this->gate->inspect(
'update',
$model
);
Expand All @@ -107,10 +108,10 @@ public function update(Request $request, object $model): bool
/**
* @inheritDoc
*/
public function destroy(Request $request, object $model): bool
public function destroy(Request $request, object $model): bool|Response
{
if ($this->mustAuthorize()) {
return $this->gate->check(
return $this->gate->inspect(
'delete',
$model
);
Expand All @@ -122,10 +123,10 @@ public function destroy(Request $request, object $model): bool
/**
* @inheritDoc
*/
public function showRelated(Request $request, object $model, string $fieldName): bool
public function showRelated(Request $request, object $model, string $fieldName): bool|Response
{
if ($this->mustAuthorize()) {
return $this->gate->check(
return $this->gate->inspect(
'view' . Str::classify($fieldName),
$model
);
Expand All @@ -137,18 +138,18 @@ public function showRelated(Request $request, object $model, string $fieldName):
/**
* @inheritDoc
*/
public function showRelationship(Request $request, object $model, string $fieldName): bool
public function showRelationship(Request $request, object $model, string $fieldName): bool|Response
{
return $this->showRelated($request, $model, $fieldName);
}

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

0 comments on commit f3a4b75

Please sign in to comment.