-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create Root folders for older persistence stores (#153)
- Loading branch information
1 parent
e22d35b
commit b654e8b
Showing
3 changed files
with
50 additions
and
38 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { | ||
createModelFromNamespaceDefinition, | ||
interpolateUsername | ||
} from './utils'; | ||
|
||
export default async function oldPersistenceFolderInterceptor(openmct, namespaces, ROOT_IDENTIFIERS) { | ||
let usersNamespace = namespaces.find((namespace) => namespace.containsNamespaces); | ||
usersNamespace = structuredClone(usersNamespace); | ||
|
||
const userTemplate = usersNamespace.childTemplate.key.split('$')[0]; | ||
const userKeyCheck = new RegExp(`^${userTemplate}([^:]+)$`); | ||
|
||
openmct.objects.addGetInterceptor({ | ||
appliesTo: (identifier, domainObject) => { | ||
const isMissing = !domainObject; | ||
const isNotUserRoot = identifier.key !== 'container'; | ||
const isUserFolderIdentifier = userKeyCheck.test(identifier.namespace); | ||
const nonUserRoots = ROOT_IDENTIFIERS.filter(rootId => rootId.key !== 'container'); | ||
const isRootFolder = nonUserRoots.find(rootId => openmct.objects.areIdsEqual(rootId, identifier)) !== undefined; | ||
|
||
// we will create domain objects for empty older persistence user or | ||
// root (ex: shared) folders, not for the user root or other folders | ||
return isMissing && isNotUserRoot && (isUserFolderIdentifier || isRootFolder); | ||
}, | ||
invoke: (identifier, object) => { | ||
const isUserNamespace = identifier.key === 'container'; | ||
|
||
const userId = identifier.namespace.match(userKeyCheck)[1]; | ||
let namespaceDefinition; | ||
|
||
if (isUserNamespace) { | ||
namespaceDefinition = interpolateUsername(usersNamespace.childTemplate, userId); | ||
namespaceDefinition.location = usersNamespace.id; | ||
} else { | ||
namespaceDefinition = namespaces.find(namespace => namespace.key === identifier.namespace); | ||
} | ||
|
||
const model = createModelFromNamespaceDefinition(userId, namespaceDefinition); | ||
|
||
openmct.objects.save(model); | ||
|
||
return model; | ||
} | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters