Jump to:

3459 Posts in 1064 Topics by 739 members

Data Model Questions

SilverStripe Forums » Data Model Questions » DataObject overwrite CanEdit() in Decorator

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

Page: 1
Go to End
Author Topic: 622 Views
  • Matze0681
    Avatar
    Community Member
    25 Posts

    DataObject overwrite CanEdit() in Decorator Link to this post

    Hi,

    I have a managed model "Product" which has a hasmany relation to "ProductVariations". Now i have the problem if the logged in user has not the FullAdministration right in his SecurityGroup, the ProductVariation records in the HasManyComplexTableFIeld are not Editable by that user.
    I know that i could make this editable by just placing an "function canEdit(){return true;}" in the ProductVariation DataObject. But for me this is no option cause this class is part of the EcommerceModule i dont want to change. This is why i use a DataObjectDecorator for the Variations.

    The problem now is, that it does not work if i place the 'canEdit' method in this decorator. The method is just not called at all.

    Changing the HasManyComplexTableField's permissions via setPermissions() doesnt make a difference too.

    Thanks in advance for your help.

    Cheers,
    Matze

  • lanks
    Avatar
    Community Member
    61 Posts

    Re: DataObject overwrite CanEdit() in Decorator Link to this post

    Hi

    Possibly the reason is that you added the canEdit method to your DataObjectDecorator without the parameter $member? e.g. canEdit ($member)

    Have a look at the API docs here for the method.

  • BenWu
    Avatar
    Community Member
    90 Posts

    Re: DataObject overwrite CanEdit() in Decorator Link to this post

    Hello Matze0681, don't think it works for me. I also tried to use a DataObjectExtension to set some permissions for a set of data models but with no success.

    Looking at the canEdit method in DataObject Class

    /**
        * @param Member $member
        * @return boolean
        */
       public function canEdit($member = null) {
          return Permission::check('ADMIN', 'any', $member);
       }

    if it has

    $this->extend ('updateCanEdit')

    we can just make the 'updateCanEdit' method in the decorator. But the core doesn't make the method extentable , only overwritable by sub-class it .

    622 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.