craftercms / craftercms

Parent project for Crafter CMS. Issue tracking across all repositories and global builds.
GNU General Public License v3.0
282 stars 98 forks source link

Files are overwritten when a read-only file-name is configured with a default value #6744

Open phuongnq opened 2 weeks ago

phuongnq commented 2 weeks ago

Latest version

Duplicates

Is your enhancement request related to a problem? Please describe.

CI:5015

We have a particular use case where we want to allow no more than 1 file per directory of a particular content type, and that file name should always be "root" (so it ends in "/root.xml"). We set the file-name field to be read-only, and set a default value of "root" to enforce this. This works for the initial creation, however, if you try to add a second content item to the same directory, the field validation on the file-name field doesn't run and doesn't prevent duplicates like if the field weren't readonly. The form then successfully submits and the new file replaces the existing one.

This can be reproduced with the following steps:

  1. Create a new site from Editorial BP
  2. Update the Header content type to have the file-name with a default root value and in readonly mode: edit_content_type
  3. Create a new Header content type, notice that the Component ID is /components/headers/root which is correct and in read-only mode root_header
  4. After the component is created in step 3, create a new Header component: should_not_be_possible
  5. Save the component in step 4, notice that it overrides the component in step 3 which is not an expected behavior 2024-05-03_14-45_1

Describe the solution you'd like

My expectation is the form would be prevented from submitting, or at the very least there'd be a warning that the file would be overwritten.