Skip to content

Commit

Permalink
refactor: merge plugins manager into server
Browse files Browse the repository at this point in the history
  • Loading branch information
christophwitzko committed Aug 5, 2015
1 parent 0688f55 commit ecdec7f
Show file tree
Hide file tree
Showing 23 changed files with 1,498 additions and 6 deletions.
2 changes: 1 addition & 1 deletion lib/core/plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ var path = require('path')
var async = require('async')
var clc = require('cli-color')

var plugins_manager = require('hoodie-plugins-manager/lib/index')
var plugins_manager = require('../plugins/manager')
var configStore = require('./config_store')

/**
Expand Down
62 changes: 62 additions & 0 deletions lib/plugins/manager/account_manager.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
var events = require('events')

var couchr = require('couchr')

exports.start = function (manager, callback) {
var am = {}

var ev = new events.EventEmitter()
am.emit = function () {
ev.emit.apply(ev, arguments)
}
am.on = function () {
ev.on.apply(ev, arguments)
}

var user_db = manager._resolve('_users')
var feed = couchr.changes(user_db, {include_docs: true})

feed.on('change', function (change) {
am.emit('change', change)
})

am.stop = function (callback) {
feed.once('error', function (err) {
// ignore connection errors during stopping of feed
if (err.code !== 'ECONNREFUSED' &&
err.code !== 'ECONNRESET') {
throw err
}
})
feed.once('stop', callback)
feed.stop()
}

// CouchDB 1.4.0 has a introduced the requirement that user fields be explicitly declared public for them to be
// returned. In the case of admins, this filtering should not be applied, but there's a bug.
// BUG: https://issues.apache.org/jira/browse/COUCHDB-1888
var couchRoot = manager._resolve('')

couchr.get(couchRoot, function (err, result) {
if (err) {
return callback(err, null)
}

if (result.version === '1.4.0') {
var config_db = manager._resolve('_config')

var publicFields = [
'_id', '_rev', 'name', 'password_sha', 'password_scheme', 'iterations',
'name', 'roles', 'derived_key', 'salt', 'database', 'hoodieId',
'updatedAt', 'signedUpAt', 'type'
]

couchr.put(config_db + '/couch_httpd_auth/public_fields', JSON.stringify(publicFields.join(',')), function () {
callback(null, am)
})
} else {
callback(null, am)
}
})

}
Loading

0 comments on commit ecdec7f

Please sign in to comment.