Skip to content

Commit

Permalink
Merge pull request #34 from hoodiehq/admins
Browse files Browse the repository at this point in the history
admins
  • Loading branch information
janl committed Dec 22, 2015
2 parents 736e27a + d2a8288 commit 8150a93
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 26 deletions.
1 change: 0 additions & 1 deletion README.md
Expand Up @@ -15,7 +15,6 @@ var PouchDB = require('PouchDB')
var hapiAccount = require('hoodie-server-account')

PouchDB.plugin(require('pouchdb-users'))
PouchDB.plugin(require('pouchdb-admins'))

var db = new PouchDB('http://localhost:5984/_users')
db.useAsAuthenticationDB().then(function () {
Expand Down
26 changes: 3 additions & 23 deletions api/README.md
Expand Up @@ -22,7 +22,8 @@ var AccountApi = require('hoodie-server-account/api')
var PouchDB = require('pouchdb')

PouchDB.plugin(require('pouchdb-users'))
PouchDB.plugin(require('pouchdb-admins'))

var db = new PouchDB('http://localhost:5984/_users')

var api = new AccountApi({
db: db,
Expand Down Expand Up @@ -70,12 +71,6 @@ If you see any inconsistencies, please [create an issue](https://github.com/hood

### Constructor

---

🐕 **TO BE DONE**: _create issue and link it here_

---

```js
new AccountApi(options)
```
Expand Down Expand Up @@ -107,15 +102,6 @@ new AccountApi(options)
</td>
<td>Yes</td>
</tr>
<tr>
<th align="left"><code>options.admins</code></th>
<td>Object</td>
<td>
Map of admin accounts, same format as CouchDB’s <code>admins</code>
configuration
</td>
<td>No</td>
</tr>
</table>

Returns an `api` instance.
Expand All @@ -139,12 +125,6 @@ db.useAsAuthenticationDB().then(function () {

### api.sessions.add()

---

🐕 **TO BE DONE**: [#26](https://github.com/hoodiehq/hoodie-server-account/issues/26)

---

Admins can create a session for any user.

```js
Expand Down Expand Up @@ -476,7 +456,7 @@ is kept, and sessions are hash based

---

🐕 **TO BE DONE**: _create issue and link it here_
🐕 **TO BE DONE**: [#27](https://github.com/hoodiehq/hoodie-server-account/issues/27)

---

Expand Down
16 changes: 15 additions & 1 deletion plugin/index.js
Expand Up @@ -18,6 +18,8 @@ function hapiAccount (server, options, next) {
var routeOptions = merge({}, options)
routeOptions.sessionTimeout = options.sessionTimeout || TIMEOUT_14_DAYS

options.usersDb.constructor.plugin(require('pouchdb-admins'))

var users = getApi({
db: options.usersDb,
secret: options.secret,
Expand Down Expand Up @@ -46,7 +48,19 @@ function hapiAccount (server, options, next) {
}))

async.parallel([
options.usersDb.put.bind(options.usersDb, usersDesignDoc),
putUsersDesignDoc.bind(null, options.usersDb, usersDesignDoc),
server.register.bind(server, plugins)
], next)
}

function putUsersDesignDoc (db, designDoc, callback) {
db.put(designDoc)

.catch(function (error) {
if (error.name !== 'conflict') {
throw error
}
})

.then(callback.bind(null, null), callback)
}
1 change: 0 additions & 1 deletion tests/integration/utils/get-server.js
Expand Up @@ -32,7 +32,6 @@ function getServer (callback) {
}])

PouchDB.plugin(require('pouchdb-users'))
PouchDB.plugin(require('pouchdb-admins'))

var usersDb = new PouchDB('http://localhost:5984/_users')
usersDb.installUsersBehavior()
Expand Down

0 comments on commit 8150a93

Please sign in to comment.