Skip to content

Commit

Permalink
Address sixth round of PR review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
jportner committed Apr 7, 2020
1 parent 65fac79 commit ec7fc3e
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/core/server/saved_objects/service/lib/repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1354,8 +1354,16 @@ export class SavedObjectsRepository {
return omit(savedObject, 'namespace');
}

/**
* Check to ensure that a raw document exists in a namespace. If the document is not a multi-namespace type, then this returns `true` as
* we rely on the guarantees of the document ID format. If the document is a multi-namespace type, this checks to ensure that the
* document's `namespaces` value includes the string representation of the given namespace.
*
* WARNING: This should only be used for documents that were retrieved from Elasticsearch. Otherwise, the guarantees of the document ID
* format mentioned above do not apply.
*/
private rawDocExistsInNamespace(raw: SavedObjectsRawDoc, namespace?: string) {
const rawDocType = raw._source.type as string;
const rawDocType = raw._source.type;

// if the type is namespace isolated, or namespace agnostic, we can continue to rely on the guarantees
// of the document ID format and don't need to check this
Expand Down Expand Up @@ -1465,6 +1473,7 @@ function getExpectedVersionProperties(version?: string, document?: SavedObjectsR

/**
* Returns the string representation of a namespace.
* The default namespace is undefined, and is represented by the string 'default'.
*/
function getNamespaceString(namespace?: string) {
return namespace ?? 'default';
Expand All @@ -1483,7 +1492,7 @@ function getSavedObjectNamespaces(
document?: SavedObjectsRawDoc
): string[] | undefined {
if (document) {
return document._source.namespaces;
return document._source?.namespaces;
}
return [getNamespaceString(namespace)];
}
Expand Down

0 comments on commit ec7fc3e

Please sign in to comment.