Created
September 21, 2017 16:32
-
-
Save dmulvi/41a3ca4ae8fe68dabf9597b20dc862cf to your computer and use it in GitHub Desktop.
Prevent Access to module via Logic Hooks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| // add these hook definitions to any module you want to prevent access to | |
| <?php | |
| $hook_version = 1; | |
| $hook_array = Array(); | |
| $hook_array['before_delete'] = Array(); | |
| $hook_array['before_delete'][] = Array(1,'Prevent Delete','custom/PreventAccessHook.php','PreventAccessHook','preventAccess'); | |
| $hook_array['after_retrieve'] = Array(); | |
| $hook_array['after_retrieve'][] = Array(1,'Prevent Record Access','custom/PreventAccessHook.php','PreventAccessHook','preventAccess'); | |
| $hook_array['process_record'] = Array(); | |
| $hook_array['process_record'][] = Array(1,'Prevent List/Subpanel Access','custom/PreventAccessHook.php','PreventAccessHook','preventAccess'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| class PreventAccessHook | |
| { | |
| public function preventAccess($bean, $event, $args) { | |
| global $db, $current_user, $log; | |
| // allow admins to view records | |
| if ($current_user->is_admin && $event !== 'before_delete') { | |
| return; | |
| } | |
| // log this attempted access | |
| $log->fatal('Prevent Access Hook Triggered'."\n".' User: '.$current_user->user_name."\n".' Module: '.$bean->module_name."\n".' Event: '.$event); | |
| // pop up alert | |
| throw new SugarApiExceptionInvalidParameter('Access Denied'); | |
| // prevent further execution | |
| die(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment