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 overwriting existing file #1164

Closed
speexy opened this issue Mar 8, 2018 · 20 comments · Fixed by #2139
Closed

Prevent overwriting existing file #1164

speexy opened this issue Mar 8, 2018 · 20 comments · Fixed by #2139

Comments

@speexy
Copy link

speexy commented Mar 8, 2018

- Do you want to request a feature or report a bug?
BUG

- What is the current behavior?
When I add a file with the same title as an existing one and my slug equals title, the existing file is overwritten.

- If the current behavior is a bug, please provide the steps to reproduce.
make sure your slug equals title. add a file, choose a title that is already used by another file, save.
you have overwritten the existing file

- What is the expected behavior?

  • either:
    a new file is created (i.e. with counter to filename)
  • or:
    a warning that the file cannot be saved as it needs a unique title

Less urgent if #1069 were implemented.

@tech4him1
Copy link
Contributor

- What is the expected behavior?

  • either:
    a new file is created (i.e. with counter to filename)
  • or:
    a warning that the file cannot be saved as it needs a unique title

In my opinion, a warning is the most reasonable option until #445 is done. @erquhart @talves @Benaiah

@Benaiah
Copy link
Contributor

Benaiah commented Mar 9, 2018

@tech4him1 I agree, and a warning should be straightforward to implement.

@brianlmacdonald
Copy link
Contributor

Can I claim this?

@tech4him1
Copy link
Contributor

@brianlmacdonald That would be great, thanks!

@talves
Copy link
Collaborator

talves commented Mar 9, 2018

I agree, this should be a warning until #445 and
let the user decide how they want to resolve.

@tech4him1
Copy link
Contributor

tech4him1 commented Mar 30, 2018

@brianlmacdonald Let me know if you have any questions on this.

@brianlmacdonald
Copy link
Contributor

@tech4him1 , yes, can you point me to the files I need to be looking at for this?

@tech4him1
Copy link
Contributor

tech4him1 commented Apr 2, 2018

@brianlmacdonald The area where the slug is created from the file title is:
https://github.com/netlify/netlify-cms/blob/f948f7a4082bccaed837684ee4915c9038db7d4d/src/backends/backend.js#L242-L251

You could likely just throw an error there, and it would be caught in the action:
https://github.com/netlify/netlify-cms/blob/55f01e6f1da080b59c711cbc45703be28429a34c/src/actions/entries.js#L304-L322

I'm not sure if something else would need to be done when in Editorial Workflow mode, that would be something to test.

@brianlmacdonald
Copy link
Contributor

@tech4him1 As a starting point, I was thinking about calling this.getEntry(collection, slug) after line 248, and if the return object comes back with the data key as anything other than an empty object, meaning it it found a preexisting file with the same name, then it throws an error.

@tech4him1
Copy link
Contributor

tech4him1 commented Apr 2, 2018

@brianlmacdonald That sounds reasonable enough to me. The entry data is probably already stored under entries.entities in Redux, but that is not guaranteed to have all the entries anyway (i.e. pagination), so I would go with getEntry.

@brianlmacdonald
Copy link
Contributor

@tech4him1 I got it working in regular mode-- it throws a nice error when you try to save with a duplicate filename. Is it possible to set up editorial workflow mode using the default test repo?

@tech4him1
Copy link
Contributor

@brianlmacdonald No, you have to use a live repo for editorial workflow currently. (One way to do it is just creating a blank GitHub repo for testing -- it doesn't need to be connected to a Netlify site.)

@erquhart
Copy link
Contributor

erquhart commented Apr 3, 2018

Adding editorial workflow support to the test backend in #1225.

@erquhart
Copy link
Contributor

Re-opening, #1239 was reverted a while back.

@erquhart erquhart reopened this Jul 31, 2018
@siddhant1
Copy link

Can I claim this issue?

@erquhart
Copy link
Contributor

erquhart commented Nov 26, 2018

@siddhant1 for sure! claimed label is still applied from before, but it now applies to you :)

@schalkventer
Copy link

@siddhant1 Are you still working on this?

I'm keen to get this issue fixed, so happy to lend a hand or take it over if you're no longer working on it. 😁

@siddhant1
Copy link

So sorry for the delay ! I am a beginner and will appreciate a helping hand to resolve this ! Thanks :)

@barthc
Copy link
Contributor

barthc commented Jan 7, 2019

I think this PR #1931 has a fix for this issue.

@schalkventer
Copy link

Great! Thanks @barthc

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment