Skip to content

Instantly share code, notes, and snippets.

@gpickin
Created August 13, 2017 02:52
Show Gist options
  • Save gpickin/35f0ac66e05b7191c217c9937086f070 to your computer and use it in GitHub Desktop.
Save gpickin/35f0ac66e05b7191c217c9937086f070 to your computer and use it in GitHub Desktop.
A ColdBox interceptor that listens for the appropriate Author ORM Interception points announced by CBORM from Hibernate, New function to be injected into every new or loaded Author Object. This new function checks for excluded permissions, before continuing to check permissions via the original ContentBox permission structure.
/**
* Listens for the appropriate Author ORM Interception points announced by CBORM from Hibernate.
* https://github.com/coldbox-modules/cbox-cborm/wiki/ORM-To-ColdBox-Interceptions
*/
component {
/**
* Configure Function
*/
void function configure(){
if( !propertyExists( "enabled" ) ){
setProperty( "enabled", true );
}
}
/**
* on ORMPostNew, this interceptor injects a new permission check method to wrap the normal check permission method in the Author entity.
*/
function ORMPostNew( event, interceptData, buffer, rc, prc ){
// verify turned on
if( !getProperty( "enabled" ) ){ return; }
if( arguments.interceptData.entityName == "cbAuthor" ){
arguments.interceptData.entity.checkRCPermission = this.checkPermissionPlus;
}
}
/**
* on ORMPostLoad, this interceptor injects a new permission check method to wrap the normal check permission method in the Author entity.
*/
function ORMPostLoad( event, interceptData, buffer, rc, prc ){
// verify turned on
if( !getProperty( "enabled" ) ){ return; }
if( arguments.interceptData.entityName == "cbAuthor" ){
arguments.interceptData.entity.checkRCPermission = this.checkPermissionPlus;
}
}
/**
* New function to be injected into every new or loaded Author Object.
* This function checks for excluded permissions, before continuing to check permissions via the original ContentBox permission structure.
* @permission The permission to be checked
*/
function checkPermissionPlus( permission='' ){
if( arguments.permission == "GLOBAL_SEARCH" ){
return false;
}
return checkPermission( arguments.permission );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment