Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

General Questions

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

how to prevent certain records from deletion?


Reply

2 Posts   294 Views

Avatar
woodb2

30 September 2012 at 4:23am Community Member, 48 Posts

I'm working in ModelAdmin with a couple of DataObjects, Project and Deliverables (Projects have many deliverables). I'm managing the Deliverables from inside Project with a DataObjectManager. Each Deliverables has a hidden field nondelete that if set to yes (1) the user should not be able to delete the record.

I thought that in my Deliveable class I could just set something like:

   function canDelete() {
      if($this->nondelete == 1) {
      return false;
      }
   }

I'm not sure how to prevent certain records from being deleted. I also tried a few things using OnBeforeDelete() in Deliverables, but had no luck with that either.

Any help would be appreciated,
Brian

Avatar
Willr

30 September 2012 at 5:54pm Forum Moderator, 5511 Posts

Does that canDelete code not work? I would assume it would, though if you've logged in as an administrator it probably overrides all permission checking. Perhaps structure it so the CMS users are not full admins but another user group which will then check against canDelete().