Skip to content

Commit

Permalink
CONTENTBOX-1500 #resolve
Browse files Browse the repository at this point in the history
Defensive Coding Needed for 2023_12_12_164002_EditorsCanClearCaches.cfc Migration
  • Loading branch information
lmajano committed Dec 20, 2023
1 parent 60e0f99 commit 21da1bb
Showing 1 changed file with 49 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,31 @@ component {
function up( schema, qb ){
var today = now();
var permID = createUUID();
qb.newQuery()
.from( "cb_permission" )
.insert( {
"permissionID" : permID,
"createdDate" : today,
"modifiedDate" : today,
"isDeleted" : 0,
"permission" : "RELOAD_CACHES",
"description" : "Ability to reload caches"
} );
systemOutput( "√ - Reload Caches permission created", true );
if (
!qb.newQuery()
.from( "cb_permission" )
.where( "permission", "RELOAD_CACHES" )
.count()
) {
qb.newQuery()
.from( "cb_permission" )
.insert( {
"permissionID" : permID,
"createdDate" : today,
"modifiedDate" : today,
"isDeleted" : 0,
"permission" : "RELOAD_CACHES",
"description" : "Ability to reload caches"
} );
systemOutput( "√ - Reload Caches permission created", true );
} else {
var permId = qb
.newQuery()
.from( "cb_permission" )
.where( "permission", "RELOAD_CACHES" )
.first()
.permissionID;
}

// Assign to Editors and Administrators
var admin = qb
Expand All @@ -36,10 +50,18 @@ component {
.where( "role", "Administrator" )
.first();

qb.newQuery()
.from( "cb_rolePermissions" )
.insert( { "FK_roleID" : admin.roleID, "FK_permissionID" : permID } );
systemOutput( "√ - Admin role updated with new permissions", true );
if (
!qb.newQuery()
.from( "cb_rolePermissions" )
.where( "FK_permissionID", permID )
.where( "FK_roleID", admin.roleID )
.count()
) {
qb.newQuery()
.from( "cb_rolePermissions" )
.insert( { "FK_roleID" : admin.roleID, "FK_permissionID" : permID } );
systemOutput( "√ - Admin role updated with new permissions", true );
}

var editor = qb
.newQuery()
Expand All @@ -48,10 +70,18 @@ component {
.where( "role", "Editor" )
.first();

qb.newQuery()
.from( "cb_rolePermissions" )
.insert( { "FK_roleID" : editor.roleID, "FK_permissionID" : permID } );
systemOutput( "√ - Editor role updated with new permissions", true );
if (
!qb.newQuery()
.from( "cb_rolePermissions" )
.where( "FK_permissionID", permID )
.where( "FK_roleID", editor.roleID )
.count()
) {
qb.newQuery()
.from( "cb_rolePermissions" )
.insert( { "FK_roleID" : editor.roleID, "FK_permissionID" : permID } );
systemOutput( "√ - Editor role updated with new permissions", true );
}
}

function down( schema, qb ){
Expand Down

0 comments on commit 21da1bb

Please sign in to comment.