datocms-plugin-prevent-unpublish
v0.1.2
Published
A plugin to prevent unpublishing of content in DatoCMS
Readme
Prevent Unpublish DatoCMS Plugin
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:
cd prevent-unpublish pnpm installStart the development server
pnpm devRegister the plugin in DatoCMS
- Go to your DatoCMS project > Settings > Plugins > Add new plugin
- Use the local development URL provided by
pnpm dev(usuallyhttp://localhost:5173)
Configure allowed roles
- In the plugin settings, enter a comma-separated list of role IDs in the
roleIdsfield (e.g.123,456,789). - Only users with these role IDs will be able to unpublish singleton models.
- In the plugin settings, enter a comma-separated list of role IDs in the
References
- Prevent unpublishing of singleton models (DatoCMS Community)
- DatoCMS Plugin SDK: Event Hooks
- DatoCMS Content Management API: Item Type
Development
- The main logic is in
src/main.tsx. - The plugin uses the DatoCMS Plugin SDK and React UI components.
For more details, see the code and comments in src/main.tsx.
