Skip to content
Permalink
Browse files

Merge branch 'hotfix-10.10.85' into stable

  • Loading branch information...
DominicWatson committed Jul 31, 2019
2 parents 9a88ee5 + c2efbb7 commit 8824339cc57ef7483f8c2236638df5742cbd3a25
@@ -132,7 +132,7 @@ component output="false" extends="tests.resources.HelperObjects.PresideTestCase"
permsService.$( "listPermissionKeys" ).$args( user=testUserId ).$results( [ "key.a", "key.b", "key.c" ] );
permsService.$( "listUserBenefits" ).$args( testUserId ).$results( [ "benefita", "benefitb", "benefitc" ] );
mockWebsiteLoginService.$( "getLoggedInUserId", testUserId );
mockCacheProvider.$( "getOrSet", { perma = true, permb = false, permc = true, permd = true } );
mockCacheProvider.$( "get", { perma = true, permb = false, permc = true, permd = true } );

super.assertFalse( permsService.hasPermission(
permissionKey = testPermissionKey
@@ -152,7 +152,7 @@ component output="false" extends="tests.resources.HelperObjects.PresideTestCase"
permsService.$( "listPermissionKeys" ).$args( user=testUserId ).$results( [ "key.a", "key.b", "key.c" ] );
permsService.$( "listUserBenefits" ).$args( testUserId ).$results( [ "benefita", "benefitb", "benefitc" ] );
mockWebsiteLoginService.$( "getLoggedInUserId", testUserId );
mockCacheProvider.$( "getOrSet", { perma = true, permb = false, permc = true, permd = true } );
mockCacheProvider.$( "get", { perma = true, permb = false, permc = true, permd = true } );

super.assert( permsService.hasPermission(
permissionKey = testPermissionKey
@@ -172,7 +172,7 @@ component output="false" extends="tests.resources.HelperObjects.PresideTestCase"
permsService.$( "listPermissionKeys" ).$args( user=testUserId ).$results( [ "key.a", "key.b", "key.c" ] );
permsService.$( "listUserBenefits" ).$args( testUserId ).$results( [ "benefita", "benefitb", "benefitc" ] );
mockWebsiteLoginService.$( "getLoggedInUserId", testUserId );
mockCacheProvider.$( "getOrSet", { perma = true, permb = false, "keyb_key.c_fred" = false, permc = true, permd = true } );
mockCacheProvider.$( "get", { perma = true, permb = false, "keyb_key.c_fred" = false, permc = true, permd = true } );

super.assertFalse( permsService.hasPermission(
permissionKey = testPermissionKey
@@ -192,7 +192,7 @@ component output="false" extends="tests.resources.HelperObjects.PresideTestCase"
permsService.$( "listPermissionKeys" ).$args( user=testUserId ).$results( [ "key.a", "key.b", "key.c" ] );
permsService.$( "listUserBenefits" ).$args( testUserId ).$results( [ "benefita", "benefitb", "benefitc" ] );
mockWebsiteLoginService.$( "getLoggedInUserId", testUserId );
mockCacheProvider.$( "getOrSet", { perma = true, permb = false, permc = true, "keyb_key.d_fred" = true, permd = true } );
mockCacheProvider.$( "get", { perma = true, permb = false, permc = true, "keyb_key.d_fred" = true, permd = true } );

super.assert( permsService.hasPermission(
permissionKey = testPermissionKey
@@ -212,7 +212,7 @@ component output="false" extends="tests.resources.HelperObjects.PresideTestCase"
permsService.$( "listPermissionKeys" ).$args( user=testUserId ).$results( [ "key.a", "key.b", "key.c" ] );
permsService.$( "listUserBenefits" ).$args( testUserId ).$results( [ "benefita", "benefitb", "benefitc" ] );
mockWebsiteLoginService.$( "getLoggedInUserId", testUserId );
mockCacheProvider.$( "getOrSet", { perma = true, permb = false, "keyb_key.c_benefita" = false, "keyb_key.c_benefitb" = true, "keyb_key.c_benefitc" = true, permc = true, permd = true } );
mockCacheProvider.$( "get", { perma = true, permb = false, "keyb_key.c_benefita" = false, "keyb_key.c_benefitb" = true, "keyb_key.c_benefitc" = true, permc = true, permd = true } );

super.assertFalse( permsService.hasPermission(
permissionKey = testPermissionKey
@@ -232,7 +232,7 @@ component output="false" extends="tests.resources.HelperObjects.PresideTestCase"
permsService.$( "listPermissionKeys" ).$args( user=testUserId ).$results( [ "key.a", "key.b", "key.c" ] );
permsService.$( "listUserBenefits" ).$args( testUserId ).$results( [ "benefita", "benefitb", "benefitc" ] );
mockWebsiteLoginService.$( "getLoggedInUserId", testUserId );
mockCacheProvider.$( "getOrSet", { perma = true, permb = false, permc = true, "keyb_key.d_benefita" = true, "keyb_key.d_benefitb" = false, "keyb_key.d_benefitc" = false, permd = true } );
mockCacheProvider.$( "get", { perma = true, permb = false, permc = true, "keyb_key.d_benefita" = true, "keyb_key.d_benefitb" = false, "keyb_key.d_benefitc" = false, permd = true } );

super.assert( permsService.hasPermission(
permissionKey = testPermissionKey
@@ -392,11 +392,15 @@ component displayName="Admin permissions service" {
, required string context
, required array contextKeys
) {
var args = arguments;
var userGroups = listUserGroups( arguments.userId );
var cacheKey = "ContextPermKeysForPermContextAndGroup: " & Hash( arguments.context & arguments.permissionKey & userGroups.toList() );
var cachedContextPerms = _getCacheProvider().getOrSet( objectKey=cacheKey, produce=function(){
var permsToCache = {};
var args = arguments;
var userGroups = listUserGroups( arguments.userId );
var cacheKey = "ContextPermKeysForPermContextAndGroup: " & Hash( arguments.context & arguments.permissionKey & userGroups.toList() );
var cache = _getCacheProvider();
var contextPerms = cache.get( cacheKey );

if ( IsNull( local.contextPerms ) ) {
contextPerms = {};

var permsFromDb = _getContextPermDao().selectData(
selectFields = [ "granted", "context_key" ]
, filter = { context = args.context, permission_key = args.permissionKey, security_group = userGroups }
@@ -405,20 +409,20 @@ component displayName="Admin permissions service" {
);

for( var perm in permsFromDb ){
permsToCache[ perm.context_key ] = perm.granted;
contextPerms[ perm.context_key ] = perm.granted;
}

return permsToCache;
} );
cache.set( cacheKey, contextPerms );
}


if ( cachedContextPerms.isEmpty() ) {
if ( contextPerms.isEmpty() ) {
return;
}

for( var key in arguments.contextKeys ){
if ( StructKeyExists( cachedContextPerms, key ) ) {
return cachedContextPerms[ key ];
if ( StructKeyExists( contextPerms, key ) ) {
return contextPerms[ key ];
}
}

@@ -431,12 +435,15 @@ component displayName="Admin permissions service" {
, required string context
, required array contextKeys
) {
var result = {};
var args = arguments;
var userGroups = listUserGroups( arguments.userId );
var cacheKey = "MultiContextPermKeysForPermContextAndGroup: " & Hash( arguments.context & arguments.permissionKeys.toList() & userGroups.toList() );
var cachedContextPerms = _getCacheProvider().getOrSet( objectKey=cacheKey, produce=function(){
var permsToCache = {};
var result = {};
var args = arguments;
var userGroups = listUserGroups( arguments.userId );
var cacheKey = "MultiContextPermKeysForPermContextAndGroup: " & Hash( arguments.context & arguments.permissionKeys.toList() & userGroups.toList() );
var cache = _getCacheProvider();
var contextPerms = cache.get( cacheKey );

if ( IsNull( local.contextPerms ) ) {
contextPerms = {};
var permsFromDb = _getContextPermDao().selectData(
selectFields = [ "granted", "context_key", "permission_key" ]
, filter = { context = args.context, permission_key = args.permissionKeys, security_group = userGroups }
@@ -445,22 +452,22 @@ component displayName="Admin permissions service" {
);

for( var perm in permsFromDb ){
permsToCache[ perm.context_key ] = permsToCache[ perm.context_key ] ?: {};
permsToCache[ perm.context_key ][ perm.permission_key ] = perm.granted;
contextPerms[ perm.context_key ] = contextPerms[ perm.context_key ] ?: {};
contextPerms[ perm.context_key ][ perm.permission_key ] = perm.granted;
}

return permsToCache;
} );
cache.set( cacheKey, contextPerms );
}

if ( cachedContextPerms.isEmpty() ) {
if ( contextPerms.isEmpty() ) {
return result;
}

for( var contextKey in arguments.contextKeys ){
if ( StructKeyExists( cachedContextPerms, contextKey ) ) {
for( var permKey in cachedContextPerms[ contextKey ] ) {
if ( StructKeyExists( contextPerms, contextKey ) ) {
for( var permKey in contextPerms[ contextKey ] ) {
if ( !StructKeyExists( result, permKey ) ) {
result[ permKey ] = cachedContextPerms[ contextKey ][ permKey ];
result[ permKey ] = contextPerms[ contextKey ][ permKey ];
}
}
}
@@ -416,10 +416,14 @@ component displayName="Website permissions service" {
, required string context
, required array contextKeys
) {
var cacheKey = "Context perms for context: " & arguments.context;
var cntext = arguments.context;
var cachedContextPerms = _getCacheProvider().getOrSet( objectKey=cacheKey, produce=function(){
var permsToCache = {};
var cntext = arguments.context;
var cache = _getCacheProvider();
var cacheKey = "Context perms for context: " & arguments.context;
var contextPerms = cache.get( cacheKey );

if ( IsNull( local.contextPerms ) ) {
contextPerms = {};

var permsFromDb = _getAppliedPermDao().selectData(
selectFields = [ "granted", "context_key", "permission_key", "benefit", "user" ]
, filter = "context = :context and ( benefit is not null or user is not null )"
@@ -428,27 +432,27 @@ component displayName="Website permissions service" {

for( var perm in permsFromDb ){
if ( IsNull( perm.benefit ) || !Len( Trim( perm.benefit ) ) ) {
permsToCache[ perm.context_key & "_" & perm.permission_key & "_" & perm.user ] = perm.granted;
contextPerms[ perm.context_key & "_" & perm.permission_key & "_" & perm.user ] = perm.granted;
} else {
permsToCache[ perm.context_key & "_" & perm.permission_key & "_" & perm.benefit ] = perm.granted;
contextPerms[ perm.context_key & "_" & perm.permission_key & "_" & perm.benefit ] = perm.granted;
}
}

return permsToCache;
} );
cache.set( cacheKey, contextPerms );
}

for( var key in arguments.contextKeys ){
// direct user context permission
cacheKey = key & "_" & arguments.permissionKey & "_" & arguments.userId;
if ( StructKeyExists( cachedContextPerms, cacheKey ) && IsBoolean( cachedContextPerms[ cacheKey ] ) ) {
return cachedContextPerms[ cacheKey ];
if ( StructKeyExists( contextPerms, cacheKey ) && IsBoolean( contextPerms[ cacheKey ] ) ) {
return contextPerms[ cacheKey ];
}

// context permission via user's benefits
for( var benefit in listUserBenefits( arguments.userId ) ){
cacheKey = key & "_" & arguments.permissionKey & "_" & benefit;
if ( StructKeyExists( cachedContextPerms, cacheKey ) && IsBoolean( cachedContextPerms[ cacheKey ] ) ) {
return cachedContextPerms[ cacheKey ];
if ( StructKeyExists( contextPerms, cacheKey ) && IsBoolean( contextPerms[ cacheKey ] ) ) {
return contextPerms[ cacheKey ];
}
}
}

0 comments on commit 8824339

Please sign in to comment.
You can’t perform that action at this time.