Prevent Unpublishing of Singleton Models

It would be great if there were an option to prevent unpublishing of some singleton models.

Often I use a singleton model to describe a page with fixed layout, and I pull the relevant variable into a static site generator (eg. on my contact.html.erb page I may use dato.contact_page).

I want these pages to use the publishing workflow so that my users can test out changes on staging before deploying to production. But if they unpublish one, the static site generator build will fail (unless I add a load of code to conditionally generate the pages, both per-page and in terms of navigation menu links and cross-page links, which as well as being time consuming and being a big potential source of bugs, doesn’t make sense as these pages are never meant to be unpublished).

It occurred to me that this could also be achieved by making ‘publish’ and ‘unpublish’ separate items in the role permissions section. Though you’d have to add a rule for every singleton you wanted to prevent publishing on.

1 Like

Another idea, probably much better than the above two: continue allowing users to unpublish singleton models as they please, but have the Dato gem just not throw errors when accessing fields on an unpublished singleton. You could then check a model’s published status and tell your site generator whether or not the page is to be generated.

So I guess this is more of a request for the Ruby library than a Dato request —

  • It would be great if accessing fields on an unpublished singleton model didn’t throw errors
  • It would be great if the ItemStatus from the GraphQL API was exposed to the Ruby library to check if an item is published (I couldn’t seem to find status, or published_at, or first_published_at in the Ruby library).
1 Like

Thank you for this. We’ll discuss your suggestions internally and see what we can do.

Hi @webworkshop the method contact_page is not created by the client if the page is unpublished, so to prevent your static site generator build to fail in this situation you should use

if dato.contact_page 
  create_post "src/contact.md" do
  frontmatter :yaml, {...}
end

To access the record’s status info call the method meta.status, for example dato.home_page.meta.status

1 Like