问题
I like to second this question from the forum:
http://www.silverstripe.org/data-model-questions/show/23484
In short:
Is it possible to apply the permission methods:
canView, canEdit, canDelete, canCreate etc
via DataExtension?
I tried but couldnt succeed yet and i wonder if i am missing something?
Subclassing would probably do, but as there are empty permission methods in DataExtension, of what purpose are they?
public function canEdit($member) {
}
回答1:
Assuming SS3.0+ the short answer is, it depends.
The straight DataObject->can[Create|Edit|View|Delete]
methods can't be extended in that fashion, but descendants of SiteTree
mostly can.
The function of interest here is DataObject->extendedCan which is called by all the SiteTree
can* methods but not the DataObject can* methods.
Of course you can always ensure this method is called in your DataObject
sub-classes.
Be aware that this can get very complex if multiple extensions are extending these functions. Here is some important documentation from the DataObject
class:
Process tri-state responses from permission-alterting extensions. The extensions are expected to return one of three values:
- false: Disallow this permission, regardless of what other extensions say
- true: Allow this permission, as long as no other extensions return false
- NULL: Don't affect the outcome
It's also worth noting that any user with the ADMIN permissions will slip through all of these checks. The only way to change permissions on objects for ADMIN users is sub-classing DataObject
.
来源:https://stackoverflow.com/questions/16758844/dataextension-and-canview