Skip to content

Commit 0063ad0

Browse files
committed
✨ renamed automatic gates to gates
1 parent 3037976 commit 0063ad0

25 files changed

+61
-61
lines changed

config/rest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@
44

55
/*
66
|--------------------------------------------------------------------------
7-
| Rest Automatic Gates
7+
| Rest Gates
88
|--------------------------------------------------------------------------
99
|
1010
| The following configuration option contains gates customisation. You might
1111
| want to adapt this feature to your needs.
1212
|
1313
*/
1414

15-
'automatic_gates' => [
15+
'gates' => [
1616
'enabled' => true,
1717
'key' => 'gates',
1818
// Here you can customize the keys for each gate

src/Concerns/Resource/DisableAutomaticGates.php renamed to src/Concerns/Resource/DisableGates.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22

33
namespace Lomkit\Rest\Concerns\Resource;
44

5-
trait DisableAutomaticGates
5+
trait DisableGates
66
{
77
/**
8-
* Check if automatic gating is enabled.
8+
* Check if gating is enabled.
99
*
1010
* @return bool
1111
*/
12-
public function isAutomaticGatingEnabled(): bool
12+
public function isGatingEnabled(): bool
1313
{
1414
return false;
1515
}

src/Http/Resource.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,13 +84,13 @@ public function defaultOrderBy(RestRequest $request): array
8484
}
8585

8686
/**
87-
* Check if automatic gating is enabled for this resource.
87+
* Check if gating is enabled for this resource.
8888
*
8989
* @return bool
9090
*/
91-
public function isAutomaticGatingEnabled(): bool
91+
public function isGatingEnabled(): bool
9292
{
93-
return config('rest.automatic_gates.enabled', true);
93+
return config('rest.gates.enabled', true);
9494
}
9595

9696
/**

src/Http/Response.php

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@ public function resource(Resource $resource)
3333
protected function buildGatesForModel(Model $model, Resource $resource, array $gates)
3434
{
3535
return array_merge(
36-
in_array('view', $gates) ? [config('rest.automatic_gates.names.authorized_to_view') => $resource->authorizedTo('view', $model)] : [],
37-
in_array('update', $gates) ? [config('rest.automatic_gates.names.authorized_to_update') => $resource->authorizedTo('update', $model)] : [],
38-
in_array('delete', $gates) ? [config('rest.automatic_gates.names.authorized_to_delete') => $resource->authorizedTo('delete', $model)] : [],
39-
in_array('restore', $gates) ? [config('rest.automatic_gates.names.authorized_to_restore') => $resource->authorizedTo('restore', $model)] : [],
40-
in_array('forceDelete', $gates) ? [config('rest.automatic_gates.names.authorized_to_force_delete') => $resource->authorizedTo('forceDelete', $model)] : [],
36+
in_array('view', $gates) ? [config('rest.gates.names.authorized_to_view') => $resource->authorizedTo('view', $model)] : [],
37+
in_array('update', $gates) ? [config('rest.gates.names.authorized_to_update') => $resource->authorizedTo('update', $model)] : [],
38+
in_array('delete', $gates) ? [config('rest.gates.names.authorized_to_delete') => $resource->authorizedTo('delete', $model)] : [],
39+
in_array('restore', $gates) ? [config('rest.gates.names.authorized_to_restore') => $resource->authorizedTo('restore', $model)] : [],
40+
in_array('forceDelete', $gates) ? [config('rest.gates.names.authorized_to_force_delete') => $resource->authorizedTo('forceDelete', $model)] : [],
4141
);
4242
}
4343

@@ -64,9 +64,9 @@ public function modelToResponse(Model $model, Resource $resource, array $request
6464
->toArray()
6565
)
6666
)
67-
->when($resource->isAutomaticGatingEnabled() && isset($currentRequestArray['gates']), function ($attributes) use ($currentRequestArray, $resource, $model) {
67+
->when($resource->isGatingEnabled() && isset($currentRequestArray['gates']), function ($attributes) use ($currentRequestArray, $resource, $model) {
6868
return $attributes->put(
69-
config('rest.automatic_gates.key'),
69+
config('rest.gates.key'),
7070
$this->buildGatesForModel($model, $resource, $currentRequestArray['gates'])
7171
);
7272
})
@@ -127,9 +127,9 @@ public function toResponse($request)
127127
$this->responsable->perPage(),
128128
$this->responsable->currentPage(),
129129
$this->responsable->getOptions(),
130-
$this->resource->isAutomaticGatingEnabled() && in_array('create', $request->input('search.gates', [])) ? [
131-
config('rest.automatic_gates.key') => [
132-
config('rest.automatic_gates.names.authorized_to_create') => $this->resource->authorizedTo('create', $this->resource::newModel()::class),
130+
$this->resource->isGatingEnabled() && in_array('create', $request->input('search.gates', [])) ? [
131+
config('rest.gates.key') => [
132+
config('rest.gates.names.authorized_to_create') => $this->resource->authorizedTo('create', $this->resource::newModel()::class),
133133
],
134134
] : []
135135
);
@@ -148,9 +148,9 @@ public function toResponse($request)
148148
return [
149149
'data' => $data ?? $this->map($this->responsable, $this->modelToResponse($this->responsable, $this->resource, $request->input('search', []))),
150150
'meta' => array_merge(
151-
$this->resource->isAutomaticGatingEnabled() && in_array('create', $request->input('search.gates', [])) ? [
152-
config('rest.automatic_gates.key') => [
153-
config('rest.automatic_gates.names.authorized_to_create') => $this->resource->authorizedTo('create', $this->resource::newModel()::class),
151+
$this->resource->isGatingEnabled() && in_array('create', $request->input('search.gates', [])) ? [
152+
config('rest.gates.key') => [
153+
config('rest.gates.names.authorized_to_create') => $this->resource->authorizedTo('create', $this->resource::newModel()::class),
154154
],
155155
] : []
156156
),

tests/Feature/Controllers/AutomaticGatingTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public function test_searching_automatic_gated_resource_with_global_config_disab
6969

7070
Gate::policy(Model::class, GreenPolicy::class);
7171

72-
config(['rest.automatic_gates.enabled' => false]);
72+
config(['rest.gates.enabled' => false]);
7373

7474
$response = $this->post(
7575
'/api/automatic-gating/search',

tests/Support/Rest/Resources/BelongsToManyResource.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22

33
namespace Lomkit\Rest\Tests\Support\Rest\Resources;
44

5-
use Lomkit\Rest\Concerns\Resource\DisableAutomaticGates;
5+
use Lomkit\Rest\Concerns\Resource\DisableGates;
66
use Lomkit\Rest\Http\Requests\RestRequest;
77
use Lomkit\Rest\Http\Resource;
88
use Lomkit\Rest\Tests\Support\Models\BelongsToManyRelation;
99

1010
class BelongsToManyResource extends Resource
1111
{
12-
use DisableAutomaticGates;
12+
use DisableGates;
1313

1414
public static $model = BelongsToManyRelation::class;
1515

tests/Support/Rest/Resources/BelongsToResource.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22

33
namespace Lomkit\Rest\Tests\Support\Rest\Resources;
44

5-
use Lomkit\Rest\Concerns\Resource\DisableAutomaticGates;
5+
use Lomkit\Rest\Concerns\Resource\DisableGates;
66
use Lomkit\Rest\Http\Requests\RestRequest;
77
use Lomkit\Rest\Http\Resource;
88
use Lomkit\Rest\Relations\HasMany;
99
use Lomkit\Rest\Tests\Support\Models\BelongsToRelation;
1010

1111
class BelongsToResource extends Resource
1212
{
13-
use DisableAutomaticGates;
13+
use DisableGates;
1414

1515
public static $model = BelongsToRelation::class;
1616

tests/Support/Rest/Resources/ConstrainedHasManyResource.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22

33
namespace Lomkit\Rest\Tests\Support\Rest\Resources;
44

5-
use Lomkit\Rest\Concerns\Resource\DisableAutomaticGates;
5+
use Lomkit\Rest\Concerns\Resource\DisableGates;
66
use Lomkit\Rest\Http\Requests\RestRequest;
77
use Lomkit\Rest\Http\Resource;
88
use Lomkit\Rest\Tests\Support\Models\HasManyRelation;
99

1010
class ConstrainedHasManyResource extends Resource
1111
{
12-
use DisableAutomaticGates;
12+
use DisableGates;
1313
public static $model = HasManyRelation::class;
1414

1515
public function rules(RestRequest $request)

tests/Support/Rest/Resources/HasManyResource.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22

33
namespace Lomkit\Rest\Tests\Support\Rest\Resources;
44

5-
use Lomkit\Rest\Concerns\Resource\DisableAutomaticGates;
5+
use Lomkit\Rest\Concerns\Resource\DisableGates;
66
use Lomkit\Rest\Http\Requests\RestRequest;
77
use Lomkit\Rest\Http\Resource;
88
use Lomkit\Rest\Tests\Support\Models\HasManyRelation;
99

1010
class HasManyResource extends Resource
1111
{
12-
use DisableAutomaticGates;
12+
use DisableGates;
1313
public static $model = HasManyRelation::class;
1414

1515
public function relations(RestRequest $request): array

tests/Support/Rest/Resources/HasManyThroughResource.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22

33
namespace Lomkit\Rest\Tests\Support\Rest\Resources;
44

5-
use Lomkit\Rest\Concerns\Resource\DisableAutomaticGates;
5+
use Lomkit\Rest\Concerns\Resource\DisableGates;
66
use Lomkit\Rest\Http\Requests\RestRequest;
77
use Lomkit\Rest\Http\Resource;
88
use Lomkit\Rest\Tests\Support\Models\HasManyThroughRelation;
99

1010
class HasManyThroughResource extends Resource
1111
{
12-
use DisableAutomaticGates;
12+
use DisableGates;
1313
public static $model = HasManyThroughRelation::class;
1414

1515
public function relations(RestRequest $request): array

0 commit comments

Comments
 (0)