How do we add a new module to the acl?
Adding new modules to support acl is acctually quite easy. It's getting them to enforce the acl rules that is the fun part.
So first lets tell the module that it supports ACLs:
So here is the code to do that inside MyModule.php:
Code:
function bean_implements($interface){
switch($interface){
case 'ACL':return true;
}
return false;
} Now lets get the module ready to respect ACLs:
use ACLController::checkAccess(Module Name, view (list, view, edit, import, export, access, delete), is current user owner) to check if a user has access to a module. Alternatively if you have instantiated a bean you can call $bean->ACLAccess(view, is_owner (it will check on it's own if you don't pass this parameter in)
In Menu.php
change the menu items to be like this
Code:
global $mod_strings;
if(ACLController::checkAccess('Cases', 'view', true)) $module_menu [] = Array("index.php?module=Cases&action=EditView&return_module=Cases&return_action=DetailView",$mod_strings['LNK_NEW_CASE'],"CreateCases");
if(ACLController::checkAccess('Cases', 'list', true))$module_menu [] = Array("index.php?module=Cases&action=index&return_module=Cases&return_action=DetailView", $mod_strings['LNK_CASE_LIST'],"Cases"); This will check if the user has access to see the menu items.
Now open DetailView.html and check to make sure the Delete button has the name 'Delete', the duplicate button has the Name 'Duplicate', and the Edit button has the name 'Edit'. This will allow them to automatically be disabled when the user doesn't have access to those views.
Now on the listview.html around the links that go to the detail view for your object change the Code:
<a> and </a> to {TAG.MAIN}
so if I had
<a href='index.php?module=MyModule&action=DetailView>Object Name</a>
it would become
<{TAG.MAIN} href='index.php?module=MyModule&action=DetailView>Object Name</{TAG.MAIN}> ]
depending on if a user has access to the object or not it will replace it with a tag of a or span. Now if you have relationships and the relationships show in the list view you will need to create more tags like if you had an account that shows in the ListView you would need to add {TAG.ACCOUNT} in replacement of the Then you would need to go into your module file MyModule.php and create a function as follows
Code:
function listviewACLHelper(){
$array_assign = parent::listviewACLHelper();
$is_owner = false;
if(!empty($this->account_id)){
if(!empty($this->account_id_owner)){
global $current_user;
$is_owner = $current_user->id == $this->account_id_owner;
}
}
if(!ACLController::moduleSupportsACL('Accounts') || ACLController::checkAccess('Accounts', 'view', $is_owner)){
$array_assign['ACCOUNT'] = 'a';
}else{
$array_assign['ACCOUNT'] = 'span';
}
return $array_assign;
} Now if you have a link to related account coming up on the detail view. You will need to add this to the detailview.php file
Code:
$xtpl->assign("TAG", $focus->listviewACLHelper()); and edit the DetailView.html in a similar fashion to what you have done for the ListView.html
That should get you on your way. There is one last thing once you have made the changes you need them to be installed. To do that login as admin and hit the following url on your site index.php?module=ACL&action=install_actions and now your module should appear in the admin section.
If I left out any information or you need more help please just let me know.
Thanks,
Majed
Bookmarks