Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(Bulk Update): Only Validate Data for Current Item in Loop #612

Merged
merged 4 commits into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Commands/PublishAuthCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public function checkDirectory(string $path): self

protected function copyDirectory(string $path, string $stubDirectory, string $format, ?array $actions = []): self
{
$filesystem = new Filesystem();
$filesystem = new Filesystem;

collect($filesystem->allFiles(__DIR__.$stubDirectory))
->filter(function (SplFileInfo $file) use ($actions) {
Expand Down
10 changes: 5 additions & 5 deletions src/Fields/Concerns/Attachable.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public function authorizeToAttach(RestifyRequest $request)
);

if (! $this->authorizedToAttach($request, $pivot)) {
throw new AuthorizationException();
throw new AuthorizationException;
}
});

Expand All @@ -106,7 +106,7 @@ public function authorizeToSync(RestifyRequest $request)
);

if (! $this->authorizedToSync($request, $pivot)) {
throw new AuthorizationException();
throw new AuthorizationException;
}
});

Expand All @@ -123,7 +123,7 @@ public function authorizedToDetach(RestifyRequest $request, Pivot $pivot): bool
public function authorizeToDetach(RestifyRequest $request, Pivot $pivot)
{
if (! $this->authorizedToDetach($request, $pivot)) {
throw new AuthorizationException();
throw new AuthorizationException;
}

return $this;
Expand Down Expand Up @@ -156,8 +156,8 @@ public function initializePivot(RestifyRequest $request, $relationship, $related

if ($relationship->withTimestamps) {
$pivot->forceFill([
$relationship->createdAt() => new DateTime(),
$relationship->updatedAt() => new DateTime(),
$relationship->createdAt() => new DateTime,
$relationship->updatedAt() => new DateTime,
]);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Http/Controllers/Auth/ForgotPasswordController.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function __invoke(Request $request)
$request->input('url') ?? config('restify.auth.password_reset_url')
);

(new AnonymousNotifiable())->route('mail', $user->email)->notify(new ForgotPasswordNotification($url));
(new AnonymousNotifiable)->route('mail', $user->email)->notify(new ForgotPasswordNotification($url));

return ok(__('Reset password link sent to your email.'));
}
Expand Down
2 changes: 1 addition & 1 deletion src/Http/Controllers/RepositoryUpdateBulkController.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public function __invoke(RepositoryUpdateBulkRequest $request)
$repository = $request->repositoryWith($model);

return $repository
->allowToUpdateBulk($request)
->allowToUpdateBulk($request, $item)
->updateBulk(
$request,
$id,
Expand Down
6 changes: 3 additions & 3 deletions src/Http/Controllers/RestResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -252,8 +252,8 @@ public function __call($func, $args)
public function respond($response = null): JsonResponse
{
if (! func_num_args()) {
$response = new \stdClass();
$response->data = new \stdClass();
$response = new \stdClass;
$response->data = new \stdClass;

foreach (static::$RESPONSE_DEFAULT_ATTRIBUTES as $property) {
if (isset($this->{$property})) {
Expand Down Expand Up @@ -537,7 +537,7 @@ public function model(Model $model): self

public static function created()
{
return (new self())->code(201);
return (new self)->code(201);
}

public static function index(AbstractPaginator|Paginator $paginator, array $meta = []): JsonResponse
Expand Down
2 changes: 1 addition & 1 deletion src/LaravelRestifyServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function packageRegistered(): void

// Register the main class to use with the facade
$this->app->singleton('laravel-restify', function () {
return new Restify();
return new Restify;
});
}

Expand Down
2 changes: 1 addition & 1 deletion src/Repositories/ValidatingTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ public static function validatorForUpdateBulk(RestifyRequest $request, $resource
})->toArray();

return Validator::make(
$plainPayload ?? $request->all(),
[$plainPayload] ?? $request->all(),
$on->getUpdatingBulkRules($request),
$messages
)->after(function ($validator) use ($request) {
Expand Down
4 changes: 2 additions & 2 deletions src/Restify.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public static function repositories(array $repositories)
(new BootRepository($repository))->boot();
});

return new static();
return new static;
}

/**
Expand All @@ -149,7 +149,7 @@ public static function repositoriesFrom(string $directory, string $namespace): v
return;
}

foreach ((new Finder())->in($directory)->files() as $repository) {
foreach ((new Finder)->in($directory)->files() as $repository) {
$repository = $namespace.str_replace(
['/', '.php'],
['\\', ''],
Expand Down
2 changes: 1 addition & 1 deletion src/RestifyApplicationServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ protected function routes(): void
protected function singleton(): void
{
if (! App::runningUnitTests()) {
$this->app->singletonIf(RelatedDto::class, fn ($app) => new RelatedDto());
$this->app->singletonIf(RelatedDto::class, fn ($app) => new RelatedDto);
}
}
}
2 changes: 1 addition & 1 deletion src/Services/Search/RepositorySearchService.php
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,6 @@ protected function applyFilters(RestifyRequest $request, Repository $repository,

public static function make(): static
{
return new static();
return new static;
}
}
8 changes: 4 additions & 4 deletions src/Traits/AuthorizableModels.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,15 +145,15 @@ public function authorizeToSync(Request $request, $method, Collection $keys): bo
public function authorizeToDetach(Request $request, $method, $model)
{
if (! static::authorizable()) {
throw new AuthorizationException();
throw new AuthorizationException;
}

$authorized = method_exists(Gate::getPolicyFor($this->model()), $method)
? Gate::check($method, [$this->model(), $model])
: false;

if ($authorized === false) {
throw new AuthorizationException();
throw new AuthorizationException;
}
}

Expand Down Expand Up @@ -194,7 +194,7 @@ public function authorizedToDelete(Request $request): bool
public function authorizeTo(Request $request, iterable|string $ability): void
{
if ($this->authorizedTo($request, $ability) === false) {
throw new AuthorizationException();
throw new AuthorizationException;
}
}

Expand All @@ -213,6 +213,6 @@ public function authorizedTo(Request $request, iterable|string $ability): bool

public static function isRepositoryContext(): bool
{
return new static() instanceof Repository;
return new static instanceof Repository;
}
}
2 changes: 1 addition & 1 deletion src/Traits/AuthorizesRequests.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public static function auth($callback)
{
static::$authUsing = $callback;

return new static();
return new static;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Traits/InteractWithSQLight.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public static function resolveConnection($connection = null)

public static function bootSushi()
{
$instance = (new static());
$instance = (new static);
$cacheFileName = 'sushi-'.Str::kebab(str_replace('\\', '', static::class)).'.sqlite';
$cacheDirectory = realpath(config('sushi.cache-path', storage_path('framework/cache')));
$cachePath = $cacheDirectory.'/'.$cacheFileName;
Expand Down
2 changes: 1 addition & 1 deletion src/Traits/InteractWithSearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public static function collectFilters($type): Collection

return $type instanceof Filter
? tap($type, fn ($filter) => $filter->column = $filter->column ?? $column)
: tap(new $base(), function (Filter $filter) use ($column, $type) {
: tap(new $base, function (Filter $filter) use ($column, $type) {
$filter->type = $type ? $type : 'value';
$filter->column = $column;
});
Expand Down
6 changes: 3 additions & 3 deletions tests/Actions/FieldActionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class FieldActionTest extends IntegrationTestCase
#[Test]
public function can_use_actionable_field(): void
{
$action = new class() extends Action
$action = new class extends Action
{
public bool $showOnShow = true;

Expand Down Expand Up @@ -56,7 +56,7 @@ public function handle(RestifyRequest $request, Post $post)
#[Test]
public function can_use_actionable_field_on_bulk_store(): void
{
$action = new class() extends Action
$action = new class extends Action
{
public bool $showOnShow = true;

Expand Down Expand Up @@ -101,7 +101,7 @@ public function handle(RestifyRequest $request, Post $post, int $row)
#[Test]
public function can_use_actionable_field_on_bulk_update(): void
{
$action = new class() extends Action
$action = new class extends Action
{
public bool $showOnShow = true;

Expand Down
2 changes: 1 addition & 1 deletion tests/Actions/PerformActionControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public function test_could_perform_action_using_all(): void
PostRepository::partialMock()
->shouldReceive('actions')
->andReturn([
new class() extends Action
new class extends Action
{
public static $uriKey = 'publish';

Expand Down
4 changes: 2 additions & 2 deletions tests/Controllers/Index/IndexRelatedFeatureTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ protected function setUp(): void
{
parent::setUp();

$this->app->singletonIf(RelatedDto::class, fn ($app) => new RelatedDto());
$this->app->singletonIf(RelatedDto::class, fn ($app) => new RelatedDto);
}

public function test_can_retrieve_nested_relationships(): void
Expand All @@ -45,7 +45,7 @@ public function test_can_retrieve_nested_relationships(): void
'owner',
'users' => HasMany::make('users', UserRepository::class),
'extraData' => fn () => ['country' => 'Romania'],
'extraMeta' => new InvokableExtraMeta(),
'extraMeta' => new InvokableExtraMeta,
]);

UserRepository::partialMock()
Expand Down
2 changes: 1 addition & 1 deletion tests/Controllers/RepositoryAttachControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ public function test_many_to_many_field_can_intercept_attach_method(): void

return true;
})
->attachCallback(new AttachInvokable()),
->attachCallback(new AttachInvokable),
]);

$this->postJson(CompanyRepository::route("$company->id/attach/users"), [
Expand Down
2 changes: 1 addition & 1 deletion tests/Feature/ActionLogTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public function test_can_create_log_for_repository_custom_action(): void

$user = User::factory()->create();

$action = new class() extends Action
$action = new class extends Action
{
public static $uriKey = 'test action';
};
Expand Down
2 changes: 1 addition & 1 deletion tests/Feature/Filters/MatchFilterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class MatchFilterTest extends IntegrationTestCase
{
public function test_matchable_filter_has_key(): void
{
$filter = new class() extends MatchFilter
$filter = new class extends MatchFilter
{
public ?string $column = 'approved_at';
};
Expand Down
Loading