news-catalyst / google-app-scripts

a collection of scripts for tinynews google docs add-ons
https://script.google.com/a/newscatalyst.org/d/1ILURq69o3cYUy6k1n1X6HwxdMfl9xWNhILYuZxgLfeblb3IR15WCMZSj/edit
1 stars 1 forks source link

Bugfix/prevent overwriting articles same slug #340

Closed jacqui closed 2 years ago

jacqui commented 2 years ago

Closes #338 Closes #341

NOTE: this is version 98 of the google docs add-on. The latest code includes handling of blockquotes and hrs.

Adds dupe detection on preview & publish of articles scoped to the category & slug and pages scoped to slug in a given organization.

To test, try creating an article in same category with an existing article's slug - but note you'll have to create the google doc first, then add as a test case using latest code. Similarly, you can try creating a page with an existing slug.

Screen Shot 2021-10-04 at 7 47 35 am

This PR also includes a bugfix that removes the custom published date handling from the sidebar for static pages (#341).

TylerFisher commented 2 years ago

This worked for the articles I tried, but it doesn't work for pages. We'd want to prevent duplicate slugs on pages as well.

jacqui commented 2 years ago

This PR is now updated so that content assigned to duplicate slugs is prevented from being previewed or published for both articles and pages.

While updating the code to work for pages, I realized my previous implementation was problematic: I was doing a lookup on articles by category & slug scoped to the current organization, which works fine on a brand new article, but trips up when you're merely trying to save an existing, valid article. To fix this, I've updated the query used for both articles and pages to check for an existing record by slug (+ category on articles) that uses a different google document ID.

This works for both pages and articles now, previewing & publishing.