Skip to content

Commit

Permalink
Defensive Coding for Permissions Migration (#597)
Browse files Browse the repository at this point in the history
* add defensive coding for migration which install wizard already seeds

* update changelog
  • Loading branch information
jclausen authored Dec 20, 2023
1 parent d4b30a1 commit 360ab6e
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 20 deletions.
2 changes: 1 addition & 1 deletion box.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name":"ContentBox Tester Site",
"version":"6.0.0",
"version":"6.0.1",
"author":"Ortus Solutions <[email protected]>",
"shortDescription":"A tester site for developing the ContentBox Modular CMS",
"type":"cms",
Expand Down
2 changes: 2 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* * *

## [Unreleased]
### Bugs
- [CONTENTBOX-1500](https://ortussolutions.atlassian.net/browse/CONTENTBOX-1500) Defensive coding for permissions migration on new instance

## [6.0.0] - 2023-12-18

Expand Down
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 360ab6e

Please sign in to comment.