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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

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

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

Problem with permissions in DataObject


Go to End


2 Posts   553 Views

Avatar
alex_sm

Community Member, 19 Posts

12 April 2016 at 9:05pm

I have dataobject in Documents.php:

class Documents extends DataObject  {
	private static $db = array(
		'DocType' => 'Text',
		'ApprovalDate' => 'Date',
		'PublicationDate' => 'Date',
		'DocNumber' => 'Text',
		'DocTitle' => 'Text',
		'KeyWords' => 'Text'
	         );

	private static $has_one = array(
		'Member' => 'Member')
...
 static $api_access = true; 
		
    public function canEdit($member = null) {
       return (Member::currentUserID() == $this->MemberID) || parent::canEdit($member);
    }

    public function canDelete($member = null) {
       return (Member::currentUserID() == $this->MemberID) || parent::canDelete($member);
    }
	public function canView($member = null) {
		   return true;
   }

    public function canCreate($member = null) { 
                  return true; 
    } 

and MyAdmin.php:
class MyAdmin extends ModelAdmin {
  private static $managed_models = array(
  	'Documents'
  );

  private static $url_segment = 'documents';

  private static $menu_title = 'Документы';

I want all users could only view all documents and create new documents, and only owner (user with ID == MemberID) could edit and delete his documents.
It works OK when user tryes to edit or delete his documents. But when he tryes to create new document (push "create" button in CMS), a pop-up window "Forbidden" appeares : https://yadi.sk/i/bBbnYwa3qtxVy.
Please, give me any ideas.

Avatar
alex_sm

Community Member, 19 Posts

15 April 2016 at 8:43pm