Jump to:

3372 Posts in 998 Topics by 712 members

Data Model Questions

SilverStripe Forums » Data Model Questions » ModelAdmin & Security - Users Can View But Not Edit

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

Page: 1 2
Go to End
Author Topic: 4274 Views
  • mspacemedia
    Avatar
    Community Member
    7 Posts

    Re: ModelAdmin & Security - Users Can View But Not Edit Link to this post

    So, in theory I could use these classes to allow a registered member to add a single listing to a dataObject directory on the site by logging their member ID into that dataObject when they sign up. Then when they log back in I could check for their ID in the DO if it appears then they only get a canEdit(), canDelete() option?

    If I wanted to allow them to upload something as long as they have paid - I guess I would need to create a separate field in their member details to state whether they had a paid subscription. If so, would the payments module be capable of populating that on return from the payment processor?

    Look forward to hearing from you guys/girls on the possibility...

  • Stefdv
    Avatar
    Community Member
    110 Posts

    Re: ModelAdmin & Security - Users Can View But Not Edit Link to this post

    Sorry for bumping in ...

    I have ( i think ) the same question.

    I have a

    Dog extends DataObject
    static $has_one = array ('Breeder' => 'Breeder')

    ----
    Breeder extends Member

    static $has_many = array('Dogs' =>'Dog');

    When a Breeder logs in to ModelAdmin i want him to be allowed to edit his own Dogs, but not the others.

    I think i need to do something with function CanEdit, but not sure how.

    any idea ?
    Never mind...Got it.

  • moloko_man
    Avatar
    Community Member
    72 Posts

    Re: ModelAdmin & Security - Users Can View But Not Edit Link to this post

    Stefdv, how did you end up getting canEdit to work?

  • swaiba
    Avatar
    Forum Moderator
    1769 Posts

    Re: ModelAdmin & Security - Users Can View But Not Edit Link to this post

    if it helps, this is how i do it...

    function getCMSFields() {
       $fields = parent::getCMSFields();
       ...
       $hasOneCTF = new HasOneComplexTableField($this,'HasOne','HasOne',null,null,'ID='.$this->HasOneID);
       $hasOneCTF->setPermissions(array('edit','show'));
       $hasOneCTF->Markable = false;
       $fields->addFieldToTab("Root.HasOne", $hasOneCTF);
       ...
       return $fields;
    }

  • Stefdv
    Avatar
    Community Member
    110 Posts

    Re: ModelAdmin & Security - Users Can View But Not Edit Link to this post

    Well, i'm not really sure how Swaiba does it. He helped me out a lot with all kind of things, but i just compare the current logged in breeder to the breeder of the current dog.

    function canEdit()
       {
                          if(!Permission::check('ADMIN'))
                          {
                      if($this->BreederID == Member::currentUserID())
                            { return true; }
                      }
                         else
                         {
                             if(Permission::check('ADMIN'))
                            {return true;}
                         }
       }

    hope this helps.

  • swaiba
    Avatar
    Forum Moderator
    1769 Posts

    Re: ModelAdmin & Security - Users Can View But Not Edit Link to this post

    I think I missed the point on this one (I do that alot too!) the code I've got is for when there is a has_one on the form as a drop down, but instead I want to allow them to edit the information.

  • SS_Learner
    Avatar
    Community Member
    18 Posts

    Re: ModelAdmin & Security - Users Can View But Not Edit Link to this post

    Hi Totalnet

    I have to added the permissions for my custom modules.I am trying to add more permission codes for delete, edit, view in a group in front of each module together to appear as checkboxes on the permissions tab for the user's group under security .So that depending on Edit/view/delete checkbox value i can add code into my module depending on what that group is allowed to do..
    Hope you can help me with this..
    Thanks

    4274 Views
Page: 1 2
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.