public function requireDefaultRecords()
    {
        // Readers
        $readersGroup = DataObject::get(Group::class)->filter(array(
            'Code' => 'restfulapi-readers',
        ));

        if (!$readersGroup->count()) {
            $readerGroup = new Group();
            $readerGroup->Code = 'restfulapi-readers';
            $readerGroup->Title = 'RESTful API Readers';
            $readerGroup->Sort = 0;
            $readerGroup->write();
            Permission::grant($readerGroup->ID, 'RESTfulAPI_VIEW');
        }

        // Editors
        $editorsGroup = DataObject::get(Group::class)->filter(array(
            'Code' => 'restfulapi-editors',
        ));

        if (!$editorsGroup->count()) {
            $editorGroup = new Group();
            $editorGroup->Code = 'restfulapi-editors';
            $editorGroup->Title = 'RESTful API Editors';
            $editorGroup->Sort = 0;
            $editorGroup->write();
            Permission::grant($editorGroup->ID, 'RESTfulAPI_VIEW');
            Permission::grant($editorGroup->ID, 'RESTfulAPI_EDIT');
            Permission::grant($editorGroup->ID, 'RESTfulAPI_CREATE');
        }

        // Admins
        $adminsGroup = DataObject::get(Group::class)->filter(array(
            'Code' => 'restfulapi-administrators',
        ));

        if (!$adminsGroup->count()) {
            $adminGroup = new Group();
            $adminGroup->Code = 'restfulapi-administrators';
            $adminGroup->Title = 'RESTful API Administrators';
            $adminGroup->Sort = 0;
            $adminGroup->write();
            Permission::grant($adminGroup->ID, 'RESTfulAPI_VIEW');
            Permission::grant($adminGroup->ID, 'RESTfulAPI_EDIT');
            Permission::grant($adminGroup->ID, 'RESTfulAPI_CREATE');
            Permission::grant($adminGroup->ID, 'RESTfulAPI_DELETE');
        }
    }
public function requireDefaultRecords()
    {
        // Readers
        $readersGroup = DataObject::get(Group::class)->filter(array(
            'Code' => 'restfulapi-readers',
        ));

        if (!$readersGroup->count()) {
            $readerGroup = new Group();
            $readerGroup->Code = 'restfulapi-readers';
            $readerGroup->Title = 'RESTful API Readers';
            $readerGroup->Sort = 0;
            $readerGroup->write();
            Permission::grant($readerGroup->ID, 'RESTfulAPI_VIEW');
        }

        // Editors
        $editorsGroup = DataObject::get(Group::class)->filter(array(
            'Code' => 'restfulapi-editors',
        ));

        if (!$editorsGroup->count()) {
            $editorGroup = new Group();
            $editorGroup->Code = 'restfulapi-editors';
            $editorGroup->Title = 'RESTful API Editors';
            $editorGroup->Sort = 0;
            $editorGroup->write();
            Permission::grant($editorGroup->ID, 'RESTfulAPI_VIEW');
            Permission::grant($editorGroup->ID, 'RESTfulAPI_EDIT');
            Permission::grant($editorGroup->ID, 'RESTfulAPI_CREATE');
        }

        // Admins
        $adminsGroup = DataObject::get(Group::class)->filter(array(
            'Code' => 'restfulapi-administrators',
        ));

        if (!$adminsGroup->count()) {
            $adminGroup = new Group();
            $adminGroup->Code = 'restfulapi-administrators';
            $adminGroup->Title = 'RESTful API Administrators';
            $adminGroup->Sort = 0;
            $adminGroup->write();
            Permission::grant($adminGroup->ID, 'RESTfulAPI_VIEW');
            Permission::grant($adminGroup->ID, 'RESTfulAPI_EDIT');
            Permission::grant($adminGroup->ID, 'RESTfulAPI_CREATE');
            Permission::grant($adminGroup->ID, 'RESTfulAPI_DELETE');
        }
    }
public function requireDefaultRecords ( ) { // Readers $ readersGroup = DataObject :: get ( Group :: class ) -> filter ( array ( 'Code' => 'restfulapi-readers' , ) ) ; if ( ! $ readersGroup -> count ( ) ) { $ readerGroup = new Group ( ) ; $ readerGroup -> Code = 'restfulapi-readers' ; $ readerGroup -> Title = 'RESTful API Readers' ; $ readerGroup -> Sort = 0 ; $ readerGroup -> write ( ) ; Permission :: grant ( $ readerGroup -> ID , 'RESTfulAPI_VIEW' ) ; } // Editors $ editorsGroup = DataObject :: get ( Group :: class ) -> filter ( array ( 'Code' => 'restfulapi-editors' , ) ) ; if ( ! $ editorsGroup -> count ( ) ) { $ editorGroup = new Group ( ) ; $ editorGroup -> Code = 'restfulapi-editors' ; $ editorGroup -> Title = 'RESTful API Editors' ; $ editorGroup -> Sort = 0 ; $ editorGroup -> write ( ) ; Permission :: grant ( $ editorGroup -> ID , 'RESTfulAPI_VIEW' ) ; Permission :: grant ( $ editorGroup -> ID , 'RESTfulAPI_EDIT' ) ; Permission :: grant ( $ editorGroup -> ID , 'RESTfulAPI_CREATE' ) ; } // Admins $ adminsGroup = DataObject :: get ( Group :: class ) -> filter ( array ( 'Code' => 'restfulapi-administrators' , ) ) ; if ( ! $ adminsGroup -> count ( ) ) { $ adminGroup = new Group ( ) ; $ adminGroup -> Code = 'restfulapi-administrators' ; $ adminGroup -> Title = 'RESTful API Administrators' ; $ adminGroup -> Sort = 0 ; $ adminGroup -> write ( ) ; Permission :: grant ( $ adminGroup -> ID , 'RESTfulAPI_VIEW' ) ; Permission :: grant ( $ adminGroup -> ID , 'RESTfulAPI_EDIT' ) ; Permission :: grant ( $ adminGroup -> ID , 'RESTfulAPI_CREATE' ) ; Permission :: grant ( $ adminGroup -> ID , 'RESTfulAPI_DELETE' ) ; } }
Create the default Groups
and add default admin to admin group
Create the default Groups and add default admin to admin group