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

Prevent users from changing collection #53

Open
johnpuddephatt opened this issue Mar 1, 2023 · 3 comments
Open

Prevent users from changing collection #53

johnpuddephatt opened this issue Mar 1, 2023 · 3 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@johnpuddephatt
Copy link

Because conversions can be collection specific, letting the user choose which collection an uploaded image is added to could cause issues as it will determine which image conversions are created/available.

e.g. let's say a user adds a 'profile picture' image to a user model, in Nova. The default collection might be set to "avatars", and "avatars" might have a conversion that creates a 300x300px square crop of the profile picture which might be displayed in a user directory on the frontend. But if the user who adds the image changes the collection to something other than "avatars", then this 300x300px square crop will now not be created.

A solution to this could be that there is a new option on MediaHubField... I'm not sure on the naming but it could be something like ->enforceDefaultCollection() or ->disableCollectionSelection(), and if this is present the select input that allows changing collections could be hidden.

I'd be very happy to submit a PR in line with the above, but I wanted to share my thoughts first in case there's something I'm missing or if anyone else has ideas.

@Tarpsvo Tarpsvo added enhancement New feature or request help wanted Extra attention is needed labels Mar 16, 2023
@johnpuddephatt
Copy link
Author

@Tarpsvo do you think this is a good idea? happy to submit a PR!

@adin00
Copy link

adin00 commented Jul 10, 2023

In addition to the above, the context menu option on image Move to collection should be rejected if either source or destination collection have custom conversions.

It is what happened to me today: Someone uploaded some images in the wrong collection, then realized the mistake and moved them to the correct one, and broke the page. It took me some time to figure out what was wrong because everything was seemingly fine 🤦

As for how it should be implemented in code, my suggestion is a second parameter for defaultCollection named allowCollectionSelection with default value true -- that is to keep backward compatibility, arguably I'd say that default value should be false:

      MediaHubField::make('Gallery')
        ->defaultCollection('events', $allowCollectionSelection = false)
        ->multiple(),

@richard-raadi
Copy link
Contributor

Hey @johnpuddephatt @adin00.

Seems like a valid use case.

Feel free to throw us a PR to review!

Sorry for the late reply.
BR
R

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

4 participants