Skip to content

Commit d4241f9

Browse files
authored
fix(data-service, database-model, collection-model): Always merge db/colls from privileges into listDatabases/listCollections command result (#2579)
* fix(data-service, database-model, collection-model): Always merge db/colls from privileges into listDatabases/listCollections command result * fix(data-service): Don't return databases with no name from listDatabases
1 parent 909162b commit d4241f9

File tree

9 files changed

+1758
-1498
lines changed

9 files changed

+1758
-1498
lines changed

packages/collection-model/lib/model.js

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,6 @@ const CollectionCollection = AmpersandCollection.extend({
7272
* @returns {Promise<void>}
7373
*/
7474
async fetch({ dataService, fetchInfo = true }) {
75-
const listCollectionsAsync = promisify(
76-
dataService.listCollections.bind(dataService)
77-
);
78-
const listCollectionsNameOnlyAsync = promisify(
79-
dataService.listCollectionsNamesOnly.bind(dataService)
80-
);
81-
8275
const databaseName = this.parent && this.parent.getId();
8376

8477
if (!databaseName) {
@@ -87,20 +80,11 @@ const CollectionCollection = AmpersandCollection.extend({
8780
);
8881
}
8982

90-
let collections = [];
91-
92-
// When trying to fetch additional information about collections during
93-
// collection list fetch we want to fallback to the nameOnly method that
94-
// requires less privileges in case user is missing some required ones
95-
if (fetchInfo) {
96-
try {
97-
collections = await listCollectionsAsync(databaseName, {});
98-
} catch (e) {
99-
collections = await listCollectionsNameOnlyAsync(databaseName);
100-
}
101-
} else {
102-
collections = await listCollectionsNameOnlyAsync(databaseName);
103-
}
83+
const collections = await dataService.listCollections(
84+
databaseName,
85+
{},
86+
{ nameOnly: !fetchInfo }
87+
);
10488

10589
this.set(
10690
collections.filter((coll) => {

packages/compass-app-stores/src/stores/instance-store.spec.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,11 @@ describe('InstanceStore [Store]', () => {
2424
instance() {
2525
return Promise.resolve(instanceInfo);
2626
},
27-
listDatabases(_opts, cb) {
28-
cb(null, []);
29-
return;
27+
listDatabases() {
28+
return Promise.resolve([]);
3029
},
31-
listCollections(_dbName, cb) {
32-
cb(null, []);
33-
return;
30+
listCollections() {
31+
return Promise.resolve([]);
3432
}
3533
};
3634
}

0 commit comments

Comments
 (0)