From 9b1f704abeff591fcc2b6b9a972b3294bf9411e3 Mon Sep 17 00:00:00 2001 From: haad Date: Sun, 10 Dec 2017 13:30:39 +0100 Subject: [PATCH] Fix a bug where creator of the database was not added to the list of writers --- src/OrbitDB.js | 2 +- test/create-open.test.js | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/OrbitDB.js b/src/OrbitDB.js index bfc8d44..16bdf96 100644 --- a/src/OrbitDB.js +++ b/src/OrbitDB.js @@ -202,7 +202,7 @@ class OrbitDB { // accessController.add('admin', this.key.getPublic('hex')) // } // Add keys that can write to the database - if (options && options.write) { + if (options && options.write && options.write.length > 0) { options.write.forEach(e => accessController.add('write', e)) } else { // Default is to add ourselves as the admin of the database diff --git a/test/create-open.test.js b/test/create-open.test.js index b4f7906..1054441 100644 --- a/test/create-open.test.js +++ b/test/create-open.test.js @@ -218,6 +218,12 @@ describe('orbit-db - Create & Open', function() { assert.equal(db.address.toString().indexOf('abc'), 56) }) + it('opens a database and adds the creator as the only writer', async () => { + db = await orbitdb.open('abc', { create: true, type: 'feed', overwrite: true, write: [] }) + assert.equal(db.access.write.length, 1) + assert.equal(db.access.write[0], db.key.getPublic('hex')) + }) + it('doesn\'t open a database if we don\'t have it locally', async () => { const address = new OrbitDBAddress(db.address.root.slice(0, -1) + 'A', 'non-existent') return new Promise((resolve, reject) => {