I’m trying to implement logic to block user from editing specific media files, but it seems I can’t stop user from deleting file itself? Can I achieve this somehow?
I also tried it in a clean setup using notifications:
public class MediaSaving() : INotificationHandler<MediaSavingNotification>
{
public void Handle(MediaSavingNotification notification)
{
foreach (var node in notification.SavedEntities)
{
node.ResetDirtyProperties();
notification.CancelOperation(new EventMessage("cancel", "cancel", EventMessageType.Error));
}
}
}
I believe your code handles MediaSavingNotification, which only intercepts save/edit operations. To block deletion, you could try to handle MediaDeletingNotification. So changing this line and testing with may put you on track:
public class MediaSaving() : INotificationHandler<MediaDeletingNotification>
Hi, thank you for your replies. Sadly no notification handles file deletion. So I went different route - I set file upload property to readonly using “SendingMediaNotification“ so that “Remove files“ option is removed. Only downside was that file upload property by default didn’t pass down readonly value, so I created copy of file upload file property which does this and it works great.