This plugin prevents unpublishing of singleton models in DatoCMS unless the user's role is explicitly allowed. It uses the onBeforeItemsUnpublish event hook to intercept unpublish actions and block them for unauthorized roles.
Features
Blocks unpublishing of models for non-allowed roles
Allowlist of roles is configurable via plugin settings (comma-separated role IDs)
Shows an alert to the user if the action is blocked
Setup
Install dependencies
Go to the plugin directory:
Terminal window
1
cdprevent-unpublish
2
pnpminstall
Start the development server
Terminal window
1
pnpmdev
Register the plugin in DatoCMS
Go to your DatoCMS project > Settings > Plugins > Add new plugin
Use the local development URL provided by pnpm dev (usually http://localhost:5173)
Configure allowed roles
In the plugin settings, enter a comma-separated list of role IDs in the roleIds field (e.g. 123,456,789).
Only users with these role IDs will be able to unpublish singleton models.