Hi
I’m extending the sugar controller for a custom module, in my class there I’ve added a check for the user role, but I cannot determine whether or not the user has clicked edit or create, I would like to direct to view ‘noaccess’ if create has been clicked. Can anyone help please?
$objACLRole = new ACLRole();
$roles = $objACLRole->getUserRoles($GLOBALS['current_user']->id);
if(in_array('Demographic',$roles) && CreateWasClicked) // I've tried isempty ($_REQUEST) from another post but this does not work
{
$this->view = 'noaccess';
}
else
{
$this->view = 'edit';
}
Many thanks
Luke
I’m not sure what method of the controller you are overwriting so don’t know exactly what you have access to and what will have been set at that point.
If you have access to the bean that is being created/edited you could look if the id is set or if fetched_row is set. The id should be self explanatory, fetched_row contains the information in the bean that was fetched from the database before the edit.
Hope that helps
Many thanks for the reply
I’m overriding editView (action_EditView). I’ve not used beans yet and am not sure how or if I could use them in this method?
I did get the desired behaviour by checking the $_REQUSET varaible as follows …
protected function action_EditView()
{
//Get the current user's role
$objACLRole = new ACLRole();
$roles = $objACLRole->getUserRoles($GLOBALS['current_user']->id);
if(in_array('Demographic',$roles) && is_null($_REQUEST["record"])) // if there is not record then it must be a create request, which we will deny
{
$this->view = 'noaccess';
}
else
{
$this->view = 'edit';
}
}
Kind Regards
Luke