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

[Bug] ValidUpload performs no validation during request validation when upload field is used as subfield #5409

Open
daPhantom opened this issue Dec 21, 2023 · 3 comments
Assignees

Comments

@daPhantom
Copy link

Bug report

What I did

Defined a relationship within the model:

    public function entities(): HasMany
    {
        return $this->hasMany(Entity::class);
    }

Defined a relationship field including an upload field as subfield:

[
                'name' => 'entities',
                'label' => __('Some Entities'),
                'type' => 'relationship',
                'subfields' => [
                    [
                        'name' => 'document',
                        'label' => __('Document'),
                        'type' => 'upload',
                        'withFiles' => [
                            'disk' => 's3',
                            'path' => 'upload',
                        ],
                    ],
                ]
            ],

Defined validation rules within Request:

    'entities.*.document' => ValidUpload::field('required')->file('mimes:pdf,jpeg,png,jpg,gif,svg|max:20480'),

What I expected to happen

  1. Field is marked as required (Asterisk *) in UI.
  2. Field will be validated for required/actual file provided on submit.
  3. Uploaded file will be validated against required mime types and size.

What happened

  1. Field is marked as required in UI (Asterisk *). ✅
  2. Field will be validated for required/actual file provided on submit. ❌
  3. Uploaded file will be validated against required mime types and size. ❌

I am able to save empty files or files which do not match the mime type. Therefore it looks like no validation at all is performed.

What I've already tried to fix it

When I use the same configuration as a root element without subfield or relationship the validation works properly.

Is it a bug in the latest version of Backpack?

yes

Backpack, Laravel, PHP, DB version

PHP VERSION:

PHP 8.2.12 (cli) (built: Oct 26 2023 17:33:49) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.2.12, Copyright (c) Zend Technologies
with Zend OPcache v8.2.12, Copyright (c), by Zend Technologies
with Xdebug v3.2.1, Copyright (c) 2002-2023, by Derick Rethans

LARAVEL VERSION:

10.38.1.0

BACKPACK PACKAGE VERSIONS:

backpack/basset: 1.2.2
backpack/crud: 6.4.2
backpack/devtools: 2.0.3
backpack/generators: v4.0.2
backpack/permissionmanager: 7.1.1
backpack/pro: 2.0.20
backpack/revise-operation: 2.0.0
backpack/theme-tabler: 1.1.2

@daPhantom
Copy link
Author

daPhantom commented Dec 21, 2023

I also checked the actual rules when dumping it in the request... it all looks properly setup and configured. I got no idea. Is it maybe related to the issue I reported regarding validation and behaviour of upload_multiple a few weeks ago?

Sorry for opening the third issue. But I try a lot of ways and invest 1-3 hours before opening a bug report here.

@phpfour
Copy link
Member

phpfour commented Dec 25, 2023

Hi @daPhantom,

Thanks for reporting the issue, and don't worry about posting many issues. As long as you spend time validating the scenarios and think something is not working properly, we appreciate you taking the time to post it here. If this is a valid issue, everyone will get the benefit.

I will try to reproduce this and assign it to the team if this is indeed an issue. In any way, we will keep you posted.

Thanks!

@pxpm
Copy link
Contributor

pxpm commented Feb 22, 2024

related with #5440

@pxpm pxpm linked a pull request Feb 22, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: No status
Development

Successfully merging a pull request may close this issue.

3 participants