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

How to make in CMS Back-End your own different tabs?


Go to End


3 Posts   1656 Views

Avatar
Bogoed Shamansky

Community Member, 12 Posts

20 October 2014 at 12:48pm

Edited: 20/10/2014 12:49pm

I have created second roles for groups with names "Support" and "Redactor".
My controller have second $aloweed_actions = ("SelectByMonth,"mineForm");

1) Support group members must have acces only to action with name "SelectByMonth".
2) Redactor group members must have acces to both actions in controller ("SelectByMonth" and "mineForm").

How to realize it?
Some code from my project:
Class for Database model (mysite/code/mineDataObject.php):

<?php 
class mineDataObject extends DataObject{	
	private static $db = array(
		'Name' => 'Varchar(256)',
		'Street' => 'Varchar(56)',
		'Telephone' => 'Varchar(11)'
	);
}
?>

Controller class (mysite/code/mineController.php):

<?php
class mine extends Page{}

class mine_Controller extends Page_Controller{
	private static $allowed_actions = array('mineForm');
	public function mineForm(){
		$fields = new FieldList(
			new TextField('Name', 'Name'),
			new TextField('Street', 'Street'),
			new PhoneNumberField('Telephone', 'Telephone')
		);
		$actions = new FieldList(
			new FormAction('doAdd','Submit')
		);
		$validator = new RequiredFields('Name', 'Street', 'Telephone'); 
		return new Form($this, 'mineForm', $fields, $actions, $validator);
	}
	
	public function doAdd($data, $form) {
		$submission = new mineDataObject();
		$form->saveInto($submission);
		$submission->write();
		return $this->redirectBack();
	}
}
?>

Avatar
Nivanka

Community Member, 400 Posts

20 October 2014 at 1:50pm

First I think it is not a good idea to extend group in order to give permissions like this. What you need it an extension to the group. With an enumerator.


class GroupExtension extends DataExtension {

     private static $db = array(
         "Type"  =>. "Enum('Support,Redactor'")
     );
}

Now you need to use the permissions to allow actions on your controller


class My_Controller extends Controller implements PermissionProvider {

   
  public function providePermissions() {
    return array(
      "SUPPORT " => "Access support sections site",
      "REDACTOR"  => "redactor permissions"
    );
  }


  function supportAction(){
                 if(!Permission::check("SUPPORT")) Security::permissionFailure();


      
   }


   function redactorAction(){

              if(!Permission::check("REDACTOR")) Security::permissionFailure();


   }

}

Hope. This will help, you can read more on the permissions provider on this link.
http://doc.silverstripe.org/framework/en/reference/permission

Cheers

Avatar
Bogoed Shamansky

Community Member, 12 Posts

27 October 2014 at 1:17am