hoodie-plugin-users
Advanced tools
Comparing version 2.2.2 to 3.0.0
# Contributing to Hoodie | ||
Please take a moment to review this document in order to make the contribution | ||
process easy and effective for everyone involved. | ||
![The Hoodie Mascot](https://avatars1.githubusercontent.com/u/1888826?v=3&s=200) | ||
Following these guidelines helps to communicate that you respect the time of | ||
the developers managing and developing this open source project. In return, | ||
they should reciprocate that respect in addressing your issue, assessing | ||
changes, and helping you finalize your pull requests. | ||
We are sorry to make you click one more time, but we are collecting [all contributing information | ||
in a single location](https://github.com/hoodiehq/hoodie/blob/master/CONTRIBUTING.md). And here it is: | ||
## Using the issue tracker | ||
First things first: **Do NOT report security vulnerablities in public issues!** Please disclose responsibly by letting [the Hoodie team](mailto:team@thehoodiefirm.com?subject=Security) know upfront. We will assess the issue as soon as possible on a best-effort basis and will give you an estimate for when we have a fix and release available for an eventual public disclosure. | ||
The issue tracker is the preferred channel for [bug reports](#bugs), | ||
[features requests](#features) and [submitting pull | ||
requests](#pull-requests), but please respect the following restrictions: | ||
* Please **do not** use the issue tracker for personal support requests. Use | ||
[#Hoodie](http://webchat.freenode.net/?channels=hoodie) on Freenode. | ||
* Please **do not** derail or troll issues. Keep the discussion on topic and | ||
respect the opinions of others. | ||
<a name="bugs"></a> | ||
## Bug reports | ||
A bug is a _demonstrable problem_ that is caused by the code in the repository. | ||
Good bug reports are extremely helpful - thank you! | ||
Guidelines for bug reports: | ||
1. **Use the GitHub issue search** — check if the issue has already been | ||
reported. | ||
2. **Check if the issue has been fixed** — try to reproduce it using the | ||
latest `master` or development branch in the repository. | ||
3. **Isolate the problem** — ideally create a [reduced test | ||
case](http://css-tricks.com/6263-reduced-test-cases/). | ||
A good bug report shouldn't leave others needing to chase you up for more | ||
information. Please try to be as detailed as possible in your report. What is | ||
your environment? What steps will reproduce the issue? What OS experiences the | ||
problem? What would you expect to be the outcome? All these details will help | ||
people to fix any potential bugs. | ||
Example: | ||
> Short and descriptive example bug report title | ||
> | ||
> A summary of the issue and the browser/OS environment in which it occurs. If | ||
> suitable, include the steps required to reproduce the bug. | ||
> | ||
> 1. This is the first step | ||
> 2. This is the second step | ||
> 3. Further steps, etc. | ||
> | ||
> `<url>` - a link to the reduced test case | ||
> | ||
> Any other information you want to share that is relevant to the issue being | ||
> reported. This might include the lines of code that you have identified as | ||
> causing the bug, and potential solutions (and your opinions on their | ||
> merits). | ||
<a name="features"></a> | ||
## Feature requests | ||
Feature requests are welcome. But take a moment to find out whether your idea | ||
fits with the scope and aims of the project. It's up to *you* to make a strong | ||
case to convince the project's developers of the merits of this feature. Please | ||
provide as much detail and context as possible. | ||
<a name="pull-requests"></a> | ||
## Pull requests | ||
Good pull requests - patches, improvements, new features - are a fantastic | ||
help. They should remain focused in scope and avoid containing unrelated | ||
commits. | ||
**Please ask first** before embarking on any significant pull request (e.g. | ||
implementing features, refactoring code), otherwise you risk spending a lot of | ||
time working on something that the project's developers might not want to merge | ||
into the project. | ||
Please adhere to the coding conventions used throughout a project (indentation, | ||
accurate comments, etc.) and any other requirements (such as test coverage). | ||
Adhering to the following this process is the best way to get your work | ||
included in the project: | ||
1. [Fork](http://help.github.com/fork-a-repo/) the project, clone your fork, | ||
and configure the remotes: | ||
```bash | ||
# Clone your fork of the repo into the current directory | ||
git clone https://github.com/<your-username>/hoodie.js | ||
# Navigate to the newly cloned directory | ||
cd Hoodie.js | ||
# Assign the original repo to a remote called "upstream" | ||
git remote add upstream https://github.com/hoodiehq/hoodie.js | ||
``` | ||
2. If you cloned a while ago, get the latest changes from upstream: | ||
```bash | ||
git checkout master | ||
git pull upstream master | ||
``` | ||
3. Create a new topic branch (off the main project development branch) to | ||
contain your feature, change, or fix: | ||
```bash | ||
git checkout -b <topic-branch-name> | ||
``` | ||
4. Make sure to update, or add to the tests when appropriate. Patches and | ||
features will not be accepted without tests. Run `npm test` to check that | ||
all tests pass after you've made changes. | ||
5. Commit your changes in logical chunks. Please adhere to these [git commit | ||
message guidelines](http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html) | ||
or your code is unlikely be merged into the main project. Use Git's | ||
[interactive rebase](https://help.github.com/articles/interactive-rebase) | ||
feature to tidy up your commits before making them public. | ||
6. Locally merge (or rebase) the upstream development branch into your topic branch: | ||
```bash | ||
git pull [--rebase] upstream master | ||
``` | ||
7. Push your topic branch up to your fork: | ||
```bash | ||
git push origin <topic-branch-name> | ||
``` | ||
8. [Open a Pull Request](https://help.github.com/articles/using-pull-requests/) | ||
with a clear title and description. | ||
9. If you are asked to amend your changes before they can be merged in, please | ||
use `git commit --amend` (or rebasing for multi-commit Pull Requests) and | ||
force push to your remote feature branch. You may also be asked to squash | ||
commits. | ||
**IMPORTANT**: By submitting a patch, you agree to license your work under the | ||
same license as that used by the project. | ||
<a name="triagers"></a> | ||
## Triagers | ||
There is a [defined process](TRIAGING.md) to manage issues, because this helps to speed up releases and minimizes user pain. | ||
Triaging is a great way to contribute to Hoodie without having to write code. | ||
If you are interested, please [leave a comment here](https://github.com/hoodiehq/discussion/issues/50) asking to join the triaging team. | ||
<a name="maintainers"></a> | ||
## Maintainers | ||
If you have commit access, please follow this process for merging patches and cutting new releases. | ||
### Reviewing changes | ||
1. Check that a change is within the scope and philosophy of the project. | ||
2. Check that a change has any necessary tests and a proper, descriptive commit message. | ||
3. Checkout the change and test it locally. | ||
4. If the change is good, and authored by someone who cannot commit to | ||
`master`, please try to avoid using GitHub's merge button. Apply the change | ||
to `master` locally (feel free to amend any minor problems in the author's | ||
original commit if necessary). | ||
5. If the change is good, and authored by another maintainer/collaborator, give | ||
them a "Ship it!" comment and let them handle the merge. | ||
### Submitting changes | ||
1. All non-trivial changes should be put up for review using GitHub Pull | ||
Requests. | ||
2. Your change should not be merged into `master` (or another feature branch), | ||
without at least one "Ship it!" comment from another maintainer/collaborator | ||
on the project. "Looks good to me" is not the same as "Ship it!". | ||
3. Try to avoid using GitHub's merge button. Locally rebase your change onto | ||
`master` and then push to GitHub. | ||
4. Once a feature branch has been merged into its target branch, please delete | ||
the feature branch from the remote repository. | ||
### Releasing a new version | ||
Releasing a new version is automated with `grunt release`. | ||
According to the semver spec the command tries to find the correct version based on changes made. | ||
You may still add flags to specify new versions explicitly. | ||
1. `grunt release:patch`: 0.0.1 => 0.0.2 | ||
2. `grunt release:minor`: 0.0.2 => 0.1.0 | ||
3. `grunt release:major`: 0.1.0 => 1.0.0 | ||
4. `grunt release --setversion=4.12.3-alpha.19`: 1.0.0 => 4.12.3-alpha.19 | ||
https://github.com/hoodiehq/hoodie/blob/master/CONTRIBUTING.md |
150
index.js
@@ -0,1 +1,3 @@ | ||
/* global emit */ // couchdb globals | ||
/** | ||
@@ -6,27 +8,28 @@ * Users plugin | ||
var removeAccount = require('./lib/remove_account'); | ||
var passwordReset = require('./lib/password_reset'); | ||
var changeUsername = require('./lib/change_username'); | ||
var signUp = require('./lib/signup'); | ||
var utils = require('./lib/utils'); | ||
var async = require('async') | ||
var changeUsername = require('./lib/change_username') | ||
var passwordReset = require('./lib/password_reset') | ||
var removeAccount = require('./lib/remove_account') | ||
var signUp = require('./lib/signup') | ||
var utils = require('./lib/utils') | ||
var sources = []; | ||
var sources = [] | ||
/** | ||
* Adds a database to the pool of task event sources | ||
* Makes sure it only happens once per database | ||
* Maybe move the dedupe logic to hoodie-plugins-manager | ||
*/ | ||
module.exports = function (hoodie, callback) { | ||
var addSource = function addSource (doc) { | ||
var dbName = utils.userDB(doc) | ||
/** | ||
* Adds a database to the pool of task event sources | ||
* Makes sure it only happens once per database | ||
* Maybe move the dedupe logic to hoodie-plugins-manager | ||
*/ | ||
var addSource = function addSource(doc) { | ||
var dbName = utils.userDB(doc); | ||
if(sources.indexOf(dbName) === -1) { | ||
if (sources.indexOf(dbName) === -1) { | ||
// not a source yet | ||
hoodie.task.addSource(dbName); | ||
sources.push(dbName); | ||
hoodie.task.addSource(dbName) | ||
sources.push(dbName) | ||
} | ||
}; | ||
} | ||
@@ -36,18 +39,17 @@ /** | ||
*/ | ||
function userChange(doc) { | ||
function userChange (doc) { | ||
if (doc.$error) { | ||
// don't do any further processing to user docs with $error | ||
return; | ||
return | ||
} | ||
else if (doc._deleted && !doc.$newUsername) { | ||
removeAccount(hoodie, doc); | ||
if (doc._deleted && !doc.$newUsername) { | ||
return removeAccount(hoodie, doc) | ||
} | ||
else if (doc.$newUsername) { | ||
changeUsername(hoodie, doc); | ||
if (doc.$newUsername) { | ||
return changeUsername(hoodie, doc) | ||
} | ||
else if (!signUp.isConfirmed(doc) && !signUp.isUnconfirmed(doc)) { | ||
signUp(hoodie, doc); | ||
} else { | ||
addSource(doc); | ||
if (!signUp.isConfirmed(doc) && !signUp.isUnconfirmed(doc)) { | ||
return signUp(hoodie, doc) | ||
} | ||
return addSource(doc) | ||
} | ||
@@ -65,26 +67,92 @@ | ||
if (error) { | ||
console.log('hoodie-plugin-users: can’t bootstrap existing accounts'); | ||
return done(error); | ||
} else { | ||
accounts.forEach(userChange); | ||
done(); | ||
console.log('hoodie-plugin-users: can’t bootstrap existing accounts') | ||
return done(error) | ||
} | ||
}); | ||
accounts.forEach(userChange) | ||
done() | ||
}) | ||
} | ||
hoodie.account.on('user:change', userChange) | ||
hoodie.account.on('user_anonymous:change', userChange) | ||
hoodie.account.on('user:change', userChange); | ||
hoodie.account.on('user_anonymous:change', userChange); | ||
hoodie.account.on('$passwordReset:change', function (doc) { | ||
if (!doc._deleted && !doc.$error) { | ||
passwordReset(hoodie, doc); | ||
passwordReset(hoodie, doc) | ||
} | ||
}); | ||
}) | ||
async.applyEachSeries([ | ||
exports.create_user_index, | ||
exports.create_user_index_by_created_at | ||
], hoodie, function (error) { | ||
if (error) { | ||
return callback(error) | ||
} | ||
/** | ||
* plugin initialization complete | ||
*/ | ||
handleExistingUsers(hoodie, callback) | ||
}) | ||
/** | ||
* plugin initialization complete | ||
*/ | ||
handleExistingUsers(hoodie, callback); | ||
// handleExistingUsers(hoodie, callback) | ||
} | ||
}; | ||
// create /_users/_design/hoodie%2fplugin%2fusers | ||
// with _view/by-name | ||
exports.create_user_index = function create_user_index (hoodie, callback) { | ||
var users_db = hoodie.database('_users') | ||
var index_name = 'by-name' | ||
var mapReduce = { | ||
map: function (doc) { | ||
var name = doc.name.split('/')[1] | ||
var state | ||
if (doc.roles.indexOf('error') !== -1) { | ||
state = 'error' | ||
} else { | ||
state = doc.roles.indexOf('confirmed') === -1 ? 'unconfirmed' : 'confirmed' | ||
} | ||
var result = { | ||
id: doc.id, | ||
name: name, | ||
createdAt: doc.createdAt, | ||
state: state | ||
} | ||
emit(name, result) | ||
} | ||
} | ||
users_db.addIndex(index_name, mapReduce, callback) | ||
} | ||
// create /_users/_design/hoodie%2fplugin%2fusers | ||
// with _view/by-created-at | ||
exports.create_user_index_by_created_at = function create_user_index_by_created_at (hoodie, callback) { | ||
var users_db = hoodie.database('_users') | ||
var index_name = 'by-created-at' | ||
var mapReduce = { | ||
map: function (doc) { | ||
var name = doc.name.split('/')[1] | ||
var state | ||
if (doc.roles.indexOf('error') !== -1) { | ||
state = 'error' | ||
} else { | ||
state = doc.roles.indexOf('confirmed') === -1 ? 'unconfirmed' : 'confirmed' | ||
} | ||
var result = { | ||
id: doc.id, | ||
name: name, | ||
createdAt: doc.createdAt, | ||
state: state | ||
} | ||
emit(doc.createdAt, result) | ||
} | ||
} | ||
users_db.addIndex(index_name, mapReduce, callback) | ||
} |
@@ -1,4 +0,4 @@ | ||
var utils = require('./utils'); | ||
var _ = require('lodash'); | ||
var _ = require('lodash') | ||
var utils = require('./utils') | ||
@@ -10,5 +10,5 @@ /** | ||
var exports = module.exports = function (hoodie, doc) { | ||
var callback = utils.logErrors('Error changing username'); | ||
exports.changeUsername(hoodie, doc, callback); | ||
}; | ||
var callback = utils.logErrors('Error changing username') | ||
exports.changeUsername(hoodie, doc, callback) | ||
} | ||
@@ -21,4 +21,4 @@ /** | ||
exports.success = function (hoodie, doc, callback) { | ||
return hoodie.account.remove(doc.type, doc.id, callback); | ||
}; | ||
return hoodie.account.remove(doc.type, doc.id, callback) | ||
} | ||
@@ -34,4 +34,4 @@ /** | ||
$error: props | ||
}, callback); | ||
}); | ||
}, callback) | ||
}) | ||
@@ -44,3 +44,3 @@ /** | ||
message: 'Failed to create new user account' | ||
}); | ||
}) | ||
@@ -54,19 +54,19 @@ /** | ||
exports.changeUsername = function (hoodie, old_user, callback) { | ||
var hook = 'plugin.user.confirm.changeUsername'; | ||
hoodie.env.hooks.runDynamicAsyncEvery(hook, [old_user], function(/*allowConfirm*/) { | ||
var new_doc = _.cloneDeep(old_user); | ||
delete new_doc._id; | ||
delete new_doc._rev; | ||
delete new_doc.name; | ||
delete new_doc.$newUsername; | ||
delete new_doc.$error; | ||
var hook = 'plugin.user.confirm.changeUsername' | ||
hoodie.env.hooks.runDynamicAsyncEvery(hook, [old_user], function (/* allowConfirm */) { | ||
var new_doc = _.cloneDeep(old_user) | ||
delete new_doc._id | ||
delete new_doc._rev | ||
delete new_doc.name | ||
delete new_doc.$newUsername | ||
delete new_doc.$error | ||
new_doc.id = old_user.$newUsername; | ||
new_doc.id = old_user.$newUsername | ||
hoodie.account.add('user', new_doc, function (err) { | ||
if (err) { | ||
return exports.createUserError(hoodie, old_user, callback); | ||
return exports.createUserError(hoodie, old_user, callback) | ||
} | ||
return exports.success(hoodie, old_user, callback); | ||
}); | ||
}); | ||
}; | ||
return exports.success(hoodie, old_user, callback) | ||
}) | ||
}) | ||
} |
@@ -1,9 +0,10 @@ | ||
var async = require('async'); | ||
var base58 = require('bs58'); | ||
var crypto = require('crypto'); | ||
var utils = require('./utils'); | ||
var _ = require('lodash'); | ||
var crypto = require('crypto') | ||
var _ = require('lodash') | ||
var async = require('async') | ||
var base58 = require('bs58') | ||
/** | ||
var utils = require('./utils') | ||
/* | ||
* Handles new $passwordReset user docs | ||
@@ -13,5 +14,5 @@ */ | ||
var exports = module.exports = function (hoodie, doc) { | ||
var callback = utils.logErrors('Error resetting password'); | ||
exports.passwordReset(hoodie, doc, callback); | ||
}; | ||
var callback = utils.logErrors('Error resetting password') | ||
exports.passwordReset(hoodie, doc, callback) | ||
} | ||
@@ -24,4 +25,4 @@ /** | ||
exports.success = function (hoodie, doc, callback) { | ||
hoodie.account.remove('$passwordReset', doc.id, callback); | ||
}; | ||
hoodie.account.remove('$passwordReset', doc.id, callback) | ||
} | ||
@@ -36,4 +37,4 @@ /** | ||
'$passwordReset', doc.id, {$error: props}, callback | ||
); | ||
}); | ||
) | ||
}) | ||
@@ -47,3 +48,3 @@ /** | ||
message: 'User could not be found' | ||
}); | ||
}) | ||
@@ -57,3 +58,3 @@ /** | ||
message: 'No email address found' | ||
}); | ||
}) | ||
@@ -66,3 +67,3 @@ /** | ||
message: 'Failed to send password reset email' | ||
}); | ||
}) | ||
@@ -74,4 +75,4 @@ /** | ||
exports.getResetUsername = function (reset_doc) { | ||
return reset_doc.name.split('/')[1]; | ||
}; | ||
return reset_doc.name.split('/')[1] | ||
} | ||
@@ -84,24 +85,24 @@ /** | ||
exports.passwordReset = function (hoodie, reset_doc, callback) { | ||
var name = exports.getResetUsername(reset_doc); | ||
var name = exports.getResetUsername(reset_doc) | ||
hoodie.account.find('user', name, function (err, user) { | ||
if (err) { | ||
return exports.notFoundError(hoodie, reset_doc, callback); | ||
return exports.notFoundError(hoodie, reset_doc, callback) | ||
} | ||
// do the password reset | ||
var email = exports.getUserEmail(user); | ||
var email = exports.getUserEmail(user) | ||
if (!email) { | ||
return exports.missingEmailError(hoodie, reset_doc, callback); | ||
return exports.missingEmailError(hoodie, reset_doc, callback) | ||
} | ||
exports.generatePassword(function (err, password) { | ||
if (err) { | ||
return callback(err); | ||
return callback(err) | ||
} | ||
var username = user.id; | ||
var username = user.id | ||
async.series([ | ||
exports.setPassword(hoodie, user, password), | ||
exports.sendPassword(hoodie, reset_doc, email, username, password) | ||
], callback); | ||
}); | ||
}); | ||
}; | ||
], callback) | ||
}) | ||
}) | ||
} | ||
@@ -129,4 +130,4 @@ /** | ||
) | ||
}; | ||
}; | ||
} | ||
} | ||
@@ -138,4 +139,4 @@ /** | ||
exports.setPassword = _.curry(function (hoodie, user, password, callback) { | ||
hoodie.account.update('user', user.id, {password: password}, callback); | ||
}); | ||
hoodie.account.update('user', user.id, {password: password}, callback) | ||
}) | ||
@@ -149,4 +150,4 @@ /** | ||
function (hoodie, reset_doc, recipient, username, password, callback) { | ||
var app_name = hoodie.config.get('app_name'); | ||
var sender = hoodie.config.get('email_from'); | ||
var app_name = hoodie.config.get('app_name') | ||
var sender = hoodie.config.get('email_from') | ||
var email = exports.createResetEmail({ | ||
@@ -158,11 +159,11 @@ to: recipient, | ||
password: password | ||
}); | ||
}) | ||
hoodie.sendEmail(email, function (err) { | ||
if (err) { | ||
return exports.sendEmailError(hoodie, reset_doc, callback); | ||
return exports.sendEmailError(hoodie, reset_doc, callback) | ||
} | ||
return exports.success(hoodie, reset_doc, callback); | ||
}); | ||
return exports.success(hoodie, reset_doc, callback) | ||
}) | ||
} | ||
); | ||
) | ||
@@ -177,7 +178,7 @@ /** | ||
// if the user id looks like an email address, use that | ||
return doc.id; | ||
return doc.id | ||
} | ||
// otherwise, return null | ||
return null; | ||
}; | ||
return null | ||
} | ||
@@ -190,4 +191,4 @@ /** | ||
crypto.randomBytes(10, function (err, buf) { | ||
return callback(err, !err && base58.encode(buf)); | ||
}); | ||
}; | ||
return callback(err, !err && base58.encode(buf)) | ||
}) | ||
} |
@@ -1,5 +0,7 @@ | ||
var utils = require('./utils'); | ||
var async = require('async'); | ||
var util = require('util'); | ||
var util = require('util') | ||
var async = require('async') | ||
var utils = require('./utils') | ||
/** | ||
@@ -10,8 +12,8 @@ * Handles user _delete events | ||
var exports = module.exports = function (hoodie, doc) { | ||
var callback = utils.logErrors('Error deleting user db'); | ||
var callback = utils.logErrors('Error deleting user db') | ||
async.applyEachSeries([ | ||
exports.deleteUserDB, | ||
exports.deleteAdditionalDBs | ||
], hoodie, doc, callback); | ||
}; | ||
], hoodie, doc, callback) | ||
} | ||
@@ -23,4 +25,4 @@ /** | ||
exports.deleteUserDB = function (hoodie, doc, callback) { | ||
hoodie.database.remove(utils.userDB(doc), callback); | ||
}; | ||
hoodie.database.remove(utils.userDB(doc), callback) | ||
} | ||
@@ -30,15 +32,13 @@ /** | ||
*/ | ||
exports.deleteAdditionalDBs = function(hoodie, doc, callback) { | ||
function deleteDatabase(db, cb) { | ||
var db_name = util.format('%s-%s', utils.userDB(doc), db); | ||
hoodie.database.remove(db_name, cb); | ||
exports.deleteAdditionalDBs = function (hoodie, doc, callback) { | ||
function deleteDatabase (db, cb) { | ||
var db_name = util.format('%s-%s', utils.userDB(doc), db) | ||
hoodie.database.remove(db_name, cb) | ||
} | ||
var additionalUserDbs = hoodie.config.get('additional_user_dbs'); | ||
var additionalUserDbs = hoodie.config.get('additional_user_dbs') | ||
if (util.isArray(additionalUserDbs)) { | ||
async.eachSeries(additionalUserDbs, deleteDatabase, callback); | ||
} else { | ||
callback(); | ||
return async.eachSeries(additionalUserDbs, deleteDatabase, callback) | ||
} | ||
}; | ||
callback() | ||
} |
@@ -1,5 +0,7 @@ | ||
var utils = require('./utils'); | ||
var async = require('async'); | ||
var util = require('util'); | ||
var util = require('util') | ||
var async = require('async') | ||
var utils = require('./utils') | ||
/** | ||
@@ -10,3 +12,3 @@ * Handles user change events for users not confirmed | ||
var exports = module.exports = function (hoodie, doc) { | ||
var callback = utils.logErrors('Error confirming user'); | ||
var callback = utils.logErrors('Error confirming user') | ||
return async.applyEachSeries( | ||
@@ -17,4 +19,4 @@ [exports.createUserDB, exports.createAdditionalDBs, exports.confirmUser], | ||
callback | ||
); | ||
}; | ||
) | ||
} | ||
@@ -25,5 +27,4 @@ /** | ||
exports.isConfirmed = utils.hasRole('confirmed'); | ||
exports.isConfirmed = utils.hasRole('confirmed') | ||
/** | ||
@@ -33,3 +34,3 @@ * Returns true if user as unconfirmed role, false otherwise | ||
exports.isUnconfirmed = utils.hasRole('unconfirmed'); | ||
exports.isUnconfirmed = utils.hasRole('unconfirmed') | ||
@@ -41,4 +42,4 @@ /** | ||
exports.createUserDB = function (hoodie, doc, callback) { | ||
hoodie.database.add(utils.userDB(doc), callback); | ||
}; | ||
hoodie.database.add(utils.userDB(doc), callback) | ||
} | ||
@@ -49,16 +50,15 @@ /* | ||
exports.createAdditionalDBs = function (hoodie, doc, callback) { | ||
// lil helper | ||
function createDatabase(db, cb) { | ||
var db_name = util.format('%s-%s', utils.userDB(doc), db); | ||
hoodie.database.add(db_name, cb); | ||
function createDatabase (db, cb) { | ||
var db_name = util.format('%s-%s', utils.userDB(doc), db) | ||
hoodie.database.add(db_name, cb) | ||
} | ||
var additionalUserDbs = hoodie.config.get('additional_user_dbs'); | ||
var additionalUserDbs = hoodie.config.get('additional_user_dbs') | ||
if (util.isArray(additionalUserDbs)) { | ||
async.eachSeries(additionalUserDbs, createDatabase, callback); | ||
async.eachSeries(additionalUserDbs, createDatabase, callback) | ||
} else { | ||
callback(); | ||
callback() | ||
} | ||
}; | ||
} | ||
@@ -71,3 +71,2 @@ /** | ||
exports.confirmUser = function (hoodie, doc, callback) { | ||
// runs all user.confirm hooks defined by plugins | ||
@@ -77,13 +76,13 @@ // if one of them returns false, we don’t confirm | ||
// If no hooks are defined, returns true as well. | ||
hoodie.env.hooks.runDynamicAsyncEvery('plugin.user.confirm', [doc], function(allowConfirm) { | ||
var hasRoles = function(doc) { | ||
return doc.roles && doc.roles.indexOf(doc.hoodieId) !== -1; | ||
}; | ||
hoodie.env.hooks.runDynamicAsyncEvery('plugin.user.confirm', [doc], function (allowConfirm) { | ||
var hasRoles = function (doc) { | ||
return doc.roles && doc.roles.indexOf(doc.hoodieId) !== -1 | ||
} | ||
var isAnonymousUser = function(doc) { | ||
return !!doc.name.match(/anonymous/); | ||
}; | ||
var isAnonymousUser = function (doc) { | ||
return !!doc.name.match(/anonymous/) | ||
} | ||
if(hasRoles && !isAnonymousUser) { | ||
return callback(); | ||
if (hasRoles && !isAnonymousUser) { | ||
return callback() | ||
} | ||
@@ -95,24 +94,24 @@ | ||
'hoodie:write:' + utils.userDB(doc) | ||
]; | ||
] | ||
if(allowConfirm || isAnonymousUser(doc)) { | ||
roles.push('confirmed'); | ||
if (allowConfirm || isAnonymousUser(doc)) { | ||
roles.push('confirmed') | ||
} else { | ||
roles.push('unconfirmed'); | ||
roles.push('unconfirmed') | ||
} | ||
var buildRole = function(prefix, user, database) { | ||
return util.format('%s%s-%s', prefix, user, database); | ||
}; | ||
var buildRole = function (prefix, user, database) { | ||
return util.format('%s%s-%s', prefix, user, database) | ||
} | ||
var additionalUserDbs = hoodie.config.get('additional_user_dbs'); | ||
var additionalUserDbs = hoodie.config.get('additional_user_dbs') | ||
if (util.isArray(additionalUserDbs)) { | ||
additionalUserDbs.forEach(function(db) { | ||
roles.push(buildRole('hoodie:read:', utils.userDB(doc), db)); | ||
roles.push(buildRole('hoodie:write:', utils.userDB(doc), db)); | ||
}); | ||
additionalUserDbs.forEach(function (db) { | ||
roles.push(buildRole('hoodie:read:', utils.userDB(doc), db)) | ||
roles.push(buildRole('hoodie:write:', utils.userDB(doc), db)) | ||
}) | ||
} | ||
hoodie.account.update(doc.type, doc.id, {roles: roles}, callback); | ||
}); | ||
}; | ||
hoodie.account.update(doc.type, doc.id, {roles: roles}, callback) | ||
}) | ||
} |
@@ -1,2 +0,2 @@ | ||
var _ = require('lodash'); | ||
var _ = require('lodash') | ||
@@ -9,10 +9,9 @@ /** | ||
return function (err) { | ||
if (err) { | ||
console.error(context + ': %s', err); | ||
console.error(err); | ||
return; | ||
} | ||
}; | ||
}; | ||
if (!err) return | ||
console.error(context + ': %s', err) | ||
console.error(err) | ||
} | ||
} | ||
/** | ||
@@ -23,4 +22,4 @@ * Returns user db name for given user doc | ||
exports.userDB = function (doc) { | ||
return 'user/' + doc.hoodieId; | ||
}; | ||
return 'user/' + doc.hoodieId | ||
} | ||
@@ -32,3 +31,3 @@ /** | ||
exports.hasRole = _.curry(function (role, doc) { | ||
return _.contains(doc.roles, role); | ||
}); | ||
return _.contains(doc.roles, role) | ||
}) |
{ | ||
"name": "hoodie-plugin-users", | ||
"version": "2.2.2", | ||
"description": "Hoodie plugin for handling user accounts and dbs", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/hoodiehq/hoodie-plugin-users.git" | ||
"dependencies": { | ||
"async": "^1.5.0", | ||
"bs58": "^3.0.0", | ||
"lodash": "^3.10.1", | ||
"simplesmtp": "^0.3.32" | ||
}, | ||
"devDependencies": { | ||
"chai": "~1.9.0", | ||
"grunt": "^0.4.5", | ||
"grunt-continue": "0.0.1", | ||
"grunt-contrib-clean": "^0.6.0", | ||
"grunt-contrib-coffee": "^0.11.1", | ||
"grunt-contrib-compass": "^0.9.1", | ||
"grunt-contrib-concat": "^0.5.0", | ||
"grunt-contrib-copy": "^0.5.0", | ||
"grunt-contrib-cssmin": "^0.10.0", | ||
"grunt-contrib-handlebars": "^0.8.0", | ||
"grunt-contrib-htmlmin": "^0.3.0", | ||
"grunt-contrib-imagemin": "^0.8.1", | ||
"grunt-contrib-jshint": "^0.9.2", | ||
"grunt-contrib-uglify": "^0.5.1", | ||
"grunt-contrib-watch": "^0.6.0", | ||
"grunt-env": "^0.4.1", | ||
"grunt-hoodie": "^0.5.4", | ||
"grunt-mocha-browser": "0.0.4", | ||
"grunt-release-hoodie": "latest", | ||
"grunt-shell": "^0.6.4", | ||
"grunt-simple-mocha": "^0.4.0", | ||
"grunt-usemin": "^0.1.9", | ||
"hoodie-server": "^3.1.0", | ||
"load-grunt-tasks": "^0.6.0", | ||
"mocha": "~1.17.1" | ||
"semantic-release": "^4.3.5", | ||
"standard": "^5.3.1" | ||
}, | ||
"hoodie": { | ||
"plugins": [ | ||
"hoodie-plugin-users" | ||
] | ||
"publishConfig": { | ||
"tag": "next" | ||
}, | ||
"dependencies": { | ||
"async": "^0.9.0", | ||
"bs58": "^1.2.0", | ||
"lodash": "^2.4.1", | ||
"simplesmtp": "^0.3.32" | ||
"release": { | ||
"branch": "next", | ||
"fallbackTags": { | ||
"next": "latest" | ||
} | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/hoodiehq/hoodie-plugin-users.git" | ||
}, | ||
"scripts": { | ||
"test:own": "grunt test", | ||
"test": "grunt ci --verbose" | ||
"semantic-release": "semantic-release pre && npm publish && semantic-release post", | ||
"test": "standard" | ||
}, | ||
"codename": "rad-giant-panda" | ||
"version": "3.0.0" | ||
} |
@@ -0,43 +1,5 @@ | ||
# hoodie-plugin-users | ||
[![Build Status](https://travis-ci.org/hoodiehq/hoodie-plugin-users.svg)](https://travis-ci.org/hoodiehq/hoodie-plugin-users) | ||
[![Dependency Status](https://david-dm.org/hoodiehq/hoodie-plugin-users.svg)](https://david-dm.org/hoodiehq/hoodie-plugin-users) | ||
[![devDependency Status](https://david-dm.org/hoodiehq/hoodie-plugin-users/dev-status.svg)](https://david-dm.org/hoodiehq/hoodie-plugin-users#info=devDependencies) | ||
# Hoodie Plugin Template | ||
This is a template layout for a Hoodie plugin. It contains a Gruntfile with | ||
appropriate tasks for running jshint, unit tests and browser tests against | ||
a Hoodie server. | ||
You'll need to have phantomjs and grunt installed: | ||
``` | ||
npm install -g phantomjs grunt-cli | ||
``` | ||
## To run tests / linting | ||
Install dev dependencies: | ||
``` | ||
npm install | ||
``` | ||
Then run the 'test' task | ||
``` | ||
grunt test | ||
``` | ||
You can also run `test:unit` or `test:browser` individually. | ||
If your plugin depends on other plugins being present (usually it will at | ||
least depend on the hoodie users plugin), then make sure they're included | ||
in your devDependencies in package.json and listed in the hoodie.plugins | ||
property. This way, they'll also get started when the browser tests are | ||
run. | ||
NOTE: When running the browser tests, the grunt tasks will remove the local | ||
Hoodie 'data' directory completely so you get a clean database to test | ||
against. Be careful you don't use this path for any data you may want to | ||
keep! |
102
TRIAGING.md
@@ -1,100 +0,8 @@ | ||
# Triage new issues/PRs on github | ||
# Triaging new issues or Pull Requests on this repository | ||
This document illustrates the steps the Hoodie community is taking to triage issues. The labels are used later on for [planning releases](#assigning-work). If you want to help by sorting issues please [leave a comment here](https://github.com/hoodiehq/discussion/issues/50) asking to join the triaging team. | ||
![The Hoodie Mascot](https://avatars1.githubusercontent.com/u/1888826?v=3&s=200) | ||
## Triaging Process | ||
We are sorry to make you click one more time, but we are collecting [all triaging information | ||
in a single location](https://github.com/hoodiehq/hoodie/blob/master/TRIAGING.md). And here it is: | ||
This process based on the idea of minimizing user pain | ||
[from this blog post](http://www.lostgarden.com/2008/05/improving-bug-triage-with-user-pain.html). | ||
1. Open the list of [non triaged issues](https://github.com/organizations/hoodiehq/dashboard/issues/repos?direction=desc&milestone=none&page=1&sort=created&state=open) | ||
* Sort by submit date, with the newest issues first | ||
* You don't have to do issues in order; feel free to pick and choose issues as you please. | ||
* You can triage older issues as well | ||
* Triage to your heart's content | ||
1. Assign yourself: Pick an issue that is not assigned to anyone and assign it to you | ||
1. Understandable? - verify if the description of the request is clear. | ||
* If not, [close it][] according to the instructions below and go to the last step. | ||
1. Duplicate? | ||
* If you've seen this issue before [close it][], and go to the last step. | ||
* Check if there are comments that link to a dupe. If so verify that this is indeed a dupe, [close it][], and go to the last step. | ||
1. Bugs: | ||
* Label `Type: Bug` | ||
* Reproducible? - Steps to reproduce the bug are clear. If they are not, ask for a clarification. If there's no reply after a week, [close it][]. | ||
* Reproducible on master? | ||
1. Non bugs: | ||
* Label `Type: Feature`, `Type: Chore`, or `Type: Perf` | ||
* Belongs in core? – Often new features should be implemented as a plugin rather than an addition to the core. | ||
If this doesn't belong, [close it][], and go to the last step. | ||
* Label `needs: breaking change` - if needed | ||
* Label `needs: public api` - if the issue requires introduction of a new public API | ||
1. Label `frequency: *` – How often does this issue come up? How many developers does this affect? | ||
* low - obscure issue affecting a handful of developers | ||
* moderate - impacts a common usage pattern | ||
* high - impacts most or all Hoodie apps | ||
1. Label `severity: *` - How bad is the issue? | ||
* regression | ||
* memory leak | ||
* broken expected use - it's hard or impossible for a developer using Hoodie to accomplish something that Hoodie should be able to do | ||
* confusing - unexpected or inconsistent behavior; hard-to-debug | ||
* inconvenience - causes ugly/boilerplate code in apps | ||
1. Label `starter` - These issues are good targets for PRs from the open source community. Apply to issues where the problem and solution are well defined in the comments, and it's not too complex. | ||
1. Label `milestone: *` – Assign a milestone: | ||
* Backlog - triaged fixes and features, should be the default choice | ||
* x.y.z - e.g. 0.3.0 | ||
1. Unassign yourself from the issue | ||
## Closing an Issue or PR | ||
We're grateful to anyone who takes the time to submit an issue, even if we ultimately decide not to act on it. | ||
Be kind and respectful as you close issues. Be sure to follow the [code of conduct][]. | ||
1. Always thank the person who submitted it. | ||
1. If it's a duplicate, link to the older or more descriptive issue that supersedes the one you are closing. | ||
1. Let them know if there's some way for them to follow-up. | ||
* When the issue is unclear or reproducible, note that you'll reopen it if they can clarify or provide a better example. Mention [plunker] or [fiddle] for examples. Watch your notifications and follow-up if they do provide clarification. :) | ||
* If appropriate, suggest implementing a feature as a third-party module. | ||
If in doubt, ask a core team member what to do. | ||
**Example:** | ||
> Thanks for submitting this issue! | ||
> Unfortunately, we don't think this functionality belongs in core. | ||
> The good news is that you could easily implement this as a plugin and publish it to npm with the `hoodie-plugin` keyword. | ||
## Assigning Work | ||
These criteria are then used to calculate a "user pain" score. | ||
Work is assigned weekly to core team members starting with the highest pain, descending down to the lowest. | ||
``` | ||
pain = severity × frequency | ||
``` | ||
**severity:** | ||
- regression (5) | ||
- memory leak (4) | ||
- broken expected use (3) | ||
- confusing (2) | ||
- inconvenience (1) | ||
**frequency:** | ||
- low (1) | ||
- moderate (2) | ||
- high (3) | ||
**Note:** Regressions and memory leaks should almost always be set to `frequency: high`. | ||
[close it]: #closing-an-issue-or-pr | ||
[code of conduct]: http://hood.ie/code-of-conduct.html | ||
[plunker]: http://plnkr.co/ | ||
[fiddle]: http://jsfiddle.net/ | ||
https://github.com/hoodiehq/hoodie/blob/master/TRIAGING.md |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 2 instances in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
2
0
28271
15
486
6
+ Addedasync@1.5.2(transitive)
+ Addedbase-x@1.1.0(transitive)
+ Addedbs58@3.1.0(transitive)
+ Addedlodash@3.10.1(transitive)
- Removedasync@0.9.2(transitive)
- Removedbs58@1.2.1(transitive)
- Removedlodash@2.4.2(transitive)
Updatedasync@^1.5.0
Updatedbs58@^3.0.0
Updatedlodash@^3.10.1