Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 5 additions & 10 deletions packages/collection-model/lib/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -417,18 +417,13 @@ const CollectionCollection = AmpersandCollection.extend(
}
);

const showHiddenNamespaces = instanceModel.shouldShowHiddenNamespaces();

this.set(
collections
.filter((coll) => {
// TODO: This is not the best place to do this kind of
// filtering, but for now this preserves the current behavior
// and changing it right away will expand the scope of the
// refactor significantly. We can address this in COMPASS-5211
return (
getNamespaceInfo(coll._id).system === false ||
getNamespaceInfo(coll._id).collection === 'system.profile'
);
})
.filter(
(coll) => showHiddenNamespaces || !getNamespaceInfo(coll._id).system
)
.map(({ _id, ...rest }) => {
return {
_id,
Expand Down
36 changes: 28 additions & 8 deletions packages/collection-model/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ describe('mongodb-collection-model', function () {
});

describe('CollectionCollection#fetch', function () {
function createFakeDatabase() {
function createFakeDatabase({ showHiddenNamespaces }) {
var instance = {
modelType: 'Instance',
shouldFetchNamespacesFromPrivileges() {
Expand All @@ -21,6 +21,9 @@ describe('mongodb-collection-model', function () {
shouldFetchDbAndCollStats() {
return false;
},
shouldShowHiddenNamespaces() {
return showHiddenNamespaces;
},
auth: { privileges: null, roles: null },
emit: function () {},
};
Expand All @@ -34,12 +37,8 @@ describe('mongodb-collection-model', function () {
};
}

it('hides system collections but keeps system.profile', async function () {
var collections = new CollectionCollection([], {
parent: createFakeDatabase(),
});

var dataService = {
function createDataService() {
return {
listCollections: async function () {
return [
{ _id: 'test.foo' },
Expand All @@ -49,8 +48,14 @@ describe('mongodb-collection-model', function () {
];
},
};
}

await collections.fetch({ dataService: dataService });
it('hides system collections by default, but keeps system.profile', async function () {
var collections = new CollectionCollection([], {
parent: createFakeDatabase({ showHiddenNamespaces: false }),
});

await collections.fetch({ dataService: createDataService() });

assert.deepStrictEqual(
collections.map(function (coll) {
Expand All @@ -59,5 +64,20 @@ describe('mongodb-collection-model', function () {
['test.bar', 'test.foo', 'test.system.profile']
);
});

it('keeps system collections when showHiddenNamespaces is enabled', async function () {
var collections = new CollectionCollection([], {
parent: createFakeDatabase({ showHiddenNamespaces: true }),
});

await collections.fetch({ dataService: createDataService() });

assert.deepStrictEqual(
collections.map(function (coll) {
return coll._id;
}),
['test.bar', 'test.foo', 'test.system.profile', 'test.system.views']
);
});
});
});
13 changes: 6 additions & 7 deletions packages/compass-app-stores/src/stores/instance-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -286,14 +286,13 @@ export function createInstancesStore(
}
);

preferences.onPreferenceValueChanged('inferNamespacesFromPrivileges', () => {
const connectedConnectionIds = Array.from(
instancesManager.listMongoDBInstances().keys()
);
for (const connectionId of connectedConnectionIds) {
function reload() {
for (const [connectionId] of instancesManager.listMongoDBInstances())
void refreshDatabases({ connectionId });
}
});
}

preferences.onPreferenceValueChanged('inferNamespacesFromPrivileges', reload);
preferences.onPreferenceValueChanged('showHiddenNamespaces', reload);

on(connections, 'disconnected', function (connectionInfoId: string) {
try {
Expand Down
12 changes: 12 additions & 0 deletions packages/compass-preferences-model/src/preferences-schema.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ export type UserConfigurablePreferences = PermanentFeatureFlags &
enableCreatingNewConnections: boolean;
proxy: string;
inferNamespacesFromPrivileges?: boolean;
showHiddenNamespaces: boolean;
// Features that are enabled by default in Date Explorer, but are disabled in Compass
maxTimeMSEnvLimit?: number;
};
Expand Down Expand Up @@ -1130,6 +1131,17 @@ export const storedUserPreferencesProps: Required<{
validator: z.boolean().default(true),
type: 'boolean',
},
showHiddenNamespaces: {
ui: true,
cli: true,
global: true,
description: {
short: 'Show Hidden Namespaces',
long: 'Show internal (__mdb_internal_) databases and system collections in the sidebar.',
},
validator: z.boolean().default(false),
type: 'boolean',
},
maxTimeMSEnvLimit: {
ui: true,
cli: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const generalFields = [
'enableShowDialogOnQuit',
'enableDbAndCollStats',
'inferNamespacesFromPrivileges',
'showHiddenNamespaces',
'legacyUUIDDisplayEncoding',
] as const;

Expand Down
10 changes: 3 additions & 7 deletions packages/database-model/lib/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -262,15 +262,11 @@ const DatabaseCollection = AmpersandCollection.extend(
roles: instanceModel.auth.roles,
});

const showHiddenNamespaces = instanceModel.shouldShowHiddenNamespaces();

this.set(
dbs
.filter((db) => {
const ns = toNS(db._id);
// TODO(COMPASS-10954): This is indisputably the wrong way and place to handle namespace filtering.
// There is a namespace that now _must_ be revealed again to users so they can repair it in unfortunate circumstances.
// We will instead reveal all internal namespaces under a setting removing this filter altogether in COMPASS-10954.
return !ns.internal || ns.database === '__mdb_internal_search';
})
.filter((db) => showHiddenNamespaces || !toNS(db._id).internal)
.map(({ _id, name, inferred_from_privileges }) => ({
_id,
name,
Expand Down
48 changes: 37 additions & 11 deletions packages/database-model/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,39 +8,65 @@ describe('mongodb-database-model', function () {
});

describe('DatabaseCollection#fetch', function () {
function createFakeInstance() {
function createFakeInstance({ showHiddenNamespaces }) {
return {
modelType: 'Instance',
shouldFetchNamespacesFromPrivileges() {
return false;
},
shouldShowHiddenNamespaces() {
return showHiddenNamespaces;
},
auth: { privileges: null, roles: null },
emit: function () {},
};
}

it('filters out internal (__mdb_internal_) databases from the list except search', async function () {
var databases = new Database.Collection([], {
parent: createFakeInstance(),
});

var dataService = {
function createDataService() {
return {
listDatabases: async function () {
return [
{ _id: 'admin' },
{ _id: 'test' },
{ _id: '__mdb_internal_atlas' },
{ _id: '__mdb_internal_search' },
{ _id: 'config' },
{ _id: 'local' },
{ _id: '__mdb_internal_search' },
{ _id: '__mdb_internal_atlas' },
];
},
};
}

it('hides internal (__mdb_internal_) databases by default', async function () {
var databases = new Database.Collection([], {
parent: createFakeInstance({ showHiddenNamespaces: false }),
});

await databases.fetch({ dataService: createDataService() });

assert.deepStrictEqual(
databases.map(({ _id }) => _id),
['admin', 'config', 'local', 'test']
);
});

it('keeps internal (__mdb_internal_) databases when showHiddenNamespaces is enabled', async function () {
var databases = new Database.Collection([], {
parent: createFakeInstance({ showHiddenNamespaces: true }),
});

await databases.fetch({ dataService: dataService });
await databases.fetch({ dataService: createDataService() });

assert.deepStrictEqual(
databases.map(({ _id }) => _id),
['__mdb_internal_search', 'admin', 'local', 'test']
[
'__mdb_internal_atlas',
'__mdb_internal_search',
'admin',
'config',
'local',
'test',
]
);
Comment thread
nbbeeken marked this conversation as resolved.
});
});
Expand Down
4 changes: 4 additions & 0 deletions packages/instance-model/lib/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,10 @@ const InstanceModel = AmpersandModel.extend(
return this.preferences.getPreferences().inferNamespacesFromPrivileges;
},

shouldShowHiddenNamespaces() {
return this.preferences.getPreferences().showHiddenNamespaces;
},

removeAllListeners() {
InstanceModel.removeAllListeners(this);
},
Expand Down
Loading