FrameworkSupertype decorator?

There was talk at one point of making a supertype decorator to allow the addition of methods to the supertype, I was wondering if anyone had done something like this yet?

I have a plugin called roleCheck.cfc with a method checkRole() that returns a Boolean result representing whether or not a user belongs to a particular role. I want to call that plugin’s method from my view, and I know I can do #getMyPlugin.checkRole(‘someRole’,session.User)# but I’d prefer to just do something sleek like #security(‘someRole’)# and have it call my plugin / method for me.

I need a method that I can call from views and layouts simply with:

<cfif #security(‘admin’)#>show something

I am using this to display partial content in a view depending on the roles the user has.

For handlers, etc I can just inject the plugin via wirebox and access it as an instance variable, and I suppose I could put the plugin into rc and call rc.myPlugin.checkRole() from my view, but I really would like to do it as I have illustrated above with the simple syntax.

To accomplish this, I added a method to the FrameworkSupertype.cfc:

<cfset local.args[‘role’] = arguments.role>

<cfif isDefined(“arguments.user”)>
<cfset local.args[‘user’] = arguments.user>

<cfreturn controller.getPlugin(argumentCollection=arguments).check(argumentCollection=local.args)>

This method is hard-coded to get my specific plugin (roleCheck) and then pass along the role and user arguments. The check() method of the plugin accepts two arguments, a role and a user to check the role on. If the user argument isn’t provided then the plugin tries to check session.User, and if session.User doesn’t exist, then the plugin returns false.

So this works fine when I add the above method to my FrameworkSupertype.cfc:

<cfif #security(‘admin’)#>show something

It calls the security() method, which gets the roleCheck plugin and runs the check() method of the plugin using the ‘admin’ role variable. The plugin defaults to session.User since I didn’t pass in a user argument and then returns true or false depending on if the session user has the provided role.

This:

<cfif #security(‘admin’,session.User)#>show something

Does the same thing, except since I provide the user argument, it is passed along to the plugin. (I do this so I can use non-session user objects to check roles for administrative purposes if I pass in the argument and just session user objects for actual permissions during a session if I don’t pass it in.)

Anyway, I have what I want working, but the part I need to think about is how to extend the supertype… if I update ColdBox, I’ll lose my new security() method, so I need this to be part of my application.

A FrameworkSupertype decorator seems to be the best fit, do we have a way to do this right now?

Look into the UDFLibraryFile configuration setting, which should do
exactly what you want.

If you are running 3.5 note that this setting can accept an array of
file paths too.

http://wiki.coldbox.org/wiki/ConfigurationFile.cfm#UDFLibraryFile

Thanks Brett!

I’ve never needed to use it before, now I know :slight_smile:

You can also use our new mixins() feature of WireBox for the Renderer plugin. You can define it in your binder and you can tell WireBox to mix in a set of UDf’s into the Renderer plugin or whatever object you like as well :slight_smile:

Luis F. Majano
CEO
Ortus Solutions, Corp
www.ortussolutions.com

ColdBox Platform: http://www.coldbox.org
Linked In: http://www.linkedin.com/pub/3/731/483
Blog: http://www.luismajano.com
IECFUG Manager: http://www.iecfug.com

Social: twitter.com/lmajano facebook.com/lmajano

Would that only inject them into layouts and views? What would be the
syntax to put in our binder configs?

Brett’s method worked like a charm, but I’ll give this a try tonight, very cool!

Brett, see here: http://wiki.coldbox.org/wiki/WireBox.cfm#Runtime_Mixins()

Search the page for udf or mixin…

Thanks. I'm not a wirebox ninja yet so hopefully I'll find some time
to play with this.

I'm curious how to use custom bindings to alter the way ColdBox builds
its internal components.

James,

Did you get it working? Maybe you can post it here for the masses?