Prevent users from removing block from content area

Vote:
 

Let's say I have a page with a content area, and there are couple of blocks predefined (e.g. by administrator). Is it possible to prevent regular editors (who can edit the page) from removing those block from content area?

They still should be able to create/add blocks, but I definitely don't want them to remove some of them.

#223999
Jun 09, 2020 9:31
Vote:
 

You could create a custom validator, as described here:
https://www.jondjones.com/learn-episerver-cms/episerver-developers-tutorials/episerver-content-areas/how-to-create-a-custom-content-area-validator-in-episerver/

I am not sure exactly what logic you want, but it the blocks should always be there, maybe (pseudo-code):

if (!user.isAdmin() && !contentArea.containsRequiredBlocks())
{
   return new ValidationError("Stop deleting the blocks, common user!");
}
#224007
Edited, Jun 09, 2020 9:49
Vote:
 

You could also place the content area on a tab only available to administrators. That way only administrators will be able to delete the blocks.

You can create another content area for the other users, on a tab where everyone can access the property.

Not sure if this fits your use case, though.

#224009
Edited, Jun 09, 2020 9:54
Vote:
 

You could hook into the OnSavingContent-event, then load the previous version of the page using IContentVersionRepository and then compare the content area of the different versions to see if any items have been removed. 

If you detect that an item has been removed that shouldn't have, you can trigger a validation error and cancel the save. 

#224010
Jun 09, 2020 9:57
Vote:
 

What would be the experience for the editor with the validator approach? I think he would be able to remove the block, validation error would occur and in order to be able to save the page, he would need to restore the block manually. Or revert page version. Correct?

#224011
Jun 09, 2020 9:57
Tomas Hensrud Gulla - Jun 09, 2020 10:03
Yes, I think that sums it up.
- Jun 09, 2020 10:36
If you take my approach, you could reset only the ContentArea-property to the previous version and issue a warning, without the editor having to manually do anything.
Vote:
 

I would personally just put the configuration of the default blocks somewhere other than the page then render them both out. I did this on a previous project and it worked well.

#224059
Jun 10, 2020 10:20
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.