From a0d16eec2340aacb8cfaa83070500395bfd50672 Mon Sep 17 00:00:00 2001 From: NV Date: Thu, 9 Feb 2017 11:41:41 +0900 Subject: [PATCH 1/4] Update README --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index c81948a..ebe19f6 100644 --- a/README.md +++ b/README.md @@ -116,6 +116,7 @@ Environment variables (will overwrite other server configs) | HMD_USECDN | `true` or `false` | set to use CDN resources or not (default is `true`) | | HMD_ALLOW_ANONYMOUS | `true` or `false` | set to allow anonymous usage (default is `true`) | | HMD_ALLOW_FREEURL | `true` or `false` | set to allow new note by accessing not exist note url | +| HMD_DEFAULT_PERMISSION | `freely`, `editable`, `limited`, `locked` or `private` | when creates new note, uses this permission (only applied when logged in) | | HMD_DB_URL | `mysql://localhost:3306/database` | set the db url | | HMD_FACEBOOK_CLIENTID | no example | Facebook API client id | | HMD_FACEBOOK_CLIENTSECRET | no example | Facebook API client secret | @@ -164,6 +165,7 @@ Application settings `config.json` | usecdn | `true` or `false` | set to use CDN resources or not (default is `true`) | | allowanonymous | `true` or `false` | set to allow anonymous usage (default is `true`) | | allowfreeurl | `true` or `false` | set to allow new note by accessing not exist note url | +| defaultpermission | `freely`, `editable`, `limited`, `locked` or `private` | when creates new note, uses this permission (only applied when logged in) | | dburl | `mysql://localhost:3306/database` | set the db url, if set this variable then below db config won't be applied | | db | `{ "dialect": "sqlite", "storage": "./db.hackmd.sqlite" }` | set the db configs, [see more here](http://sequelize.readthedocs.org/en/latest/api/sequelize/) | | sslkeypath | `./cert/client.key` | ssl key path (only need when you set usessl) | From 0a7adaf35d07efa658c040e789967acdc2eb32ff Mon Sep 17 00:00:00 2001 From: NV Date: Thu, 9 Feb 2017 13:24:40 +0900 Subject: [PATCH 2/4] Add default permission config --- lib/config.js | 4 ++++ lib/models/note.js | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/config.js b/lib/config.js index c037382..052a5d0 100644 --- a/lib/config.js +++ b/lib/config.js @@ -24,6 +24,9 @@ var allowanonymous = process.env.HMD_ALLOW_ANONYMOUS ? (process.env.HMD_ALLOW_AN var allowfreeurl = process.env.HMD_ALLOW_FREEURL ? (process.env.HMD_ALLOW_FREEURL === 'true') : !!config.allowfreeurl; +var defaultpermission = process.env.HMD_DEFAULT_PERMISSION || config.defaultpermission || 'editable'; +defaultpermission = (!allowanonymous && defaultpermission == 'freely') ? 'editable' : defaultpermission; + // db var dburl = config.dburl || process.env.HMD_DB_URL || process.env.DATABASE_URL; var db = config.db || {}; @@ -173,6 +176,7 @@ module.exports = { usecdn: usecdn, allowanonymous: allowanonymous, allowfreeurl: allowfreeurl, + defaultpermission: defaultpermission, dburl: dburl, db: db, sslkeypath: path.join(cwd, sslkeypath), diff --git a/lib/models/note.js b/lib/models/note.js index 8611297..8b38d3f 100644 --- a/lib/models/note.js +++ b/lib/models/note.js @@ -513,10 +513,10 @@ module.exports = function (sequelize, DataTypes) { } } } - // if no permission specified and have owner then give editable permission, else default permission is freely + // if no permission specified and have owner then give default permission in config, else default permission is freely if (!note.permission) { if (note.ownerId) { - note.permission = "editable"; + note.permission = config.defaultpermission; } else { note.permission = "freely"; } From 5375fe57790152bf97958bb54cef922f03b2b40e Mon Sep 17 00:00:00 2001 From: NV Date: Fri, 10 Feb 2017 11:46:10 +0900 Subject: [PATCH 3/4] Add validation to defaultpermission in config --- lib/config.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/config.js b/lib/config.js index 052a5d0..bdc2cbd 100644 --- a/lib/config.js +++ b/lib/config.js @@ -24,8 +24,13 @@ var allowanonymous = process.env.HMD_ALLOW_ANONYMOUS ? (process.env.HMD_ALLOW_AN var allowfreeurl = process.env.HMD_ALLOW_FREEURL ? (process.env.HMD_ALLOW_FREEURL === 'true') : !!config.allowfreeurl; -var defaultpermission = process.env.HMD_DEFAULT_PERMISSION || config.defaultpermission || 'editable'; -defaultpermission = (!allowanonymous && defaultpermission == 'freely') ? 'editable' : defaultpermission; +var permissions = ['editable', 'limited', 'locked', 'protected', 'private']; +if (allowanonymous) { + permissions.unshift('freely'); +} + +var defaultpermission = process.env.HMD_DEFAULT_PERMISSION || config.defaultpermission; +defaultpermission = permissions.indexOf(defaultpermission) != -1 ? defaultpermission : 'editable'; // db var dburl = config.dburl || process.env.HMD_DB_URL || process.env.DATABASE_URL; From 00d1543a1017a231761ac20aaa49627e5744d923 Mon Sep 17 00:00:00 2001 From: NV Date: Fri, 10 Feb 2017 11:49:45 +0900 Subject: [PATCH 4/4] simplified description --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index ebe19f6..7991117 100644 --- a/README.md +++ b/README.md @@ -116,7 +116,7 @@ Environment variables (will overwrite other server configs) | HMD_USECDN | `true` or `false` | set to use CDN resources or not (default is `true`) | | HMD_ALLOW_ANONYMOUS | `true` or `false` | set to allow anonymous usage (default is `true`) | | HMD_ALLOW_FREEURL | `true` or `false` | set to allow new note by accessing not exist note url | -| HMD_DEFAULT_PERMISSION | `freely`, `editable`, `limited`, `locked` or `private` | when creates new note, uses this permission (only applied when logged in) | +| HMD_DEFAULT_PERMISSION | `freely`, `editable`, `limited`, `locked` or `private` | set notes default permission (only applied on signed users) | | HMD_DB_URL | `mysql://localhost:3306/database` | set the db url | | HMD_FACEBOOK_CLIENTID | no example | Facebook API client id | | HMD_FACEBOOK_CLIENTSECRET | no example | Facebook API client secret | @@ -165,7 +165,7 @@ Application settings `config.json` | usecdn | `true` or `false` | set to use CDN resources or not (default is `true`) | | allowanonymous | `true` or `false` | set to allow anonymous usage (default is `true`) | | allowfreeurl | `true` or `false` | set to allow new note by accessing not exist note url | -| defaultpermission | `freely`, `editable`, `limited`, `locked` or `private` | when creates new note, uses this permission (only applied when logged in) | +| defaultpermission | `freely`, `editable`, `limited`, `locked` or `private` | set notes default permission (only applied on signed users) | | dburl | `mysql://localhost:3306/database` | set the db url, if set this variable then below db config won't be applied | | db | `{ "dialect": "sqlite", "storage": "./db.hackmd.sqlite" }` | set the db configs, [see more here](http://sequelize.readthedocs.org/en/latest/api/sequelize/) | | sslkeypath | `./cert/client.key` | ssl key path (only need when you set usessl) |