Skip to content

Commit

Permalink
For framework-one#205 cleanup / scriptify role service.
Browse files Browse the repository at this point in the history
  • Loading branch information
seancorfield committed May 18, 2014
1 parent df435cf commit 6f9b82a
Showing 1 changed file with 21 additions and 32 deletions.
53 changes: 21 additions & 32 deletions examples/userManagerAccessControl/model/services/role.cfc
@@ -1,20 +1,14 @@
<cfcomponent output="false">
component {

<cfproperty name="beanFactory" />
function init( beanFactory ) {
variables.beanFactory = beanFactory;
variables.roles = { };

<cfset variables.roles = structNew()>

<cffunction name="init" access="public" output="false" returntype="any">
<cfargument name="beanFactory"/>
<cfset variables.beanFactory = arguments.beanFactory/>
<cfscript>
var role = "";

// since services are cached role data we'll be persisted
// since services are cached role data will be persisted
// ideally, this would be saved elsewhere, e.g. database

// FIRST
role = variables.beanFactory.getBean("roleBean");
var role = variables.beanFactory.getBean("roleBean");
role.setId("1");
role.setName("Admin");

Expand All @@ -26,27 +20,22 @@
role.setName("User");

variables.roles[role.getId()] = role;
</cfscript>

<cfreturn this>
</cffunction>

<cffunction name="get" access="public" output="false" returntype="any">
<cfargument name="id" type="string" required="true">

<cfset var result = "">

<cfif len(id) AND structKeyExists(variables.roles, id)>
<cfset result = variables.roles[id]>
<cfelse>
<cfset result = variables.beanFactory.getBean( "roleBean" )>
</cfif>
return this;
}

<cfreturn result>
</cffunction>
function get( string id ) {
var result = 0;
if ( len( id ) && structKeyExists( variables.roles, id ) ) {
result = variables.roles[ id ];
} else {
result = variables.beanFactory.getBean( "roleBean" );
}
return result;
}

<cffunction name="list" access="public" output="false" returntype="struct">
<cfreturn variables.roles>
</cffunction>
function list() {
return variables.roles;
}

</cfcomponent>
}

0 comments on commit 6f9b82a

Please sign in to comment.