Skip to content

Commit cd24e75

Browse files
authored
Merge pull request #348 from nvsofts/add_default_permission
Add default permission config
2 parents a19163d + 00d1543 commit cd24e75

3 files changed

Lines changed: 13 additions & 2 deletions

File tree

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ Environment variables (will overwrite other server configs)
116116
| HMD_USECDN | `true` or `false` | set to use CDN resources or not (default is `true`) |
117117
| HMD_ALLOW_ANONYMOUS | `true` or `false` | set to allow anonymous usage (default is `true`) |
118118
| HMD_ALLOW_FREEURL | `true` or `false` | set to allow new note by accessing not exist note url |
119+
| HMD_DEFAULT_PERMISSION | `freely`, `editable`, `limited`, `locked` or `private` | set notes default permission (only applied on signed users) |
119120
| HMD_DB_URL | `mysql://localhost:3306/database` | set the db url |
120121
| HMD_FACEBOOK_CLIENTID | no example | Facebook API client id |
121122
| HMD_FACEBOOK_CLIENTSECRET | no example | Facebook API client secret |
@@ -164,6 +165,7 @@ Application settings `config.json`
164165
| usecdn | `true` or `false` | set to use CDN resources or not (default is `true`) |
165166
| allowanonymous | `true` or `false` | set to allow anonymous usage (default is `true`) |
166167
| allowfreeurl | `true` or `false` | set to allow new note by accessing not exist note url |
168+
| defaultpermission | `freely`, `editable`, `limited`, `locked` or `private` | set notes default permission (only applied on signed users) |
167169
| dburl | `mysql://localhost:3306/database` | set the db url, if set this variable then below db config won't be applied |
168170
| db | `{ "dialect": "sqlite", "storage": "./db.hackmd.sqlite" }` | set the db configs, [see more here](http://sequelize.readthedocs.org/en/latest/api/sequelize/) |
169171
| sslkeypath | `./cert/client.key` | ssl key path (only need when you set usessl) |

lib/config.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,14 @@ var allowanonymous = process.env.HMD_ALLOW_ANONYMOUS ? (process.env.HMD_ALLOW_AN
2424

2525
var allowfreeurl = process.env.HMD_ALLOW_FREEURL ? (process.env.HMD_ALLOW_FREEURL === 'true') : !!config.allowfreeurl;
2626

27+
var permissions = ['editable', 'limited', 'locked', 'protected', 'private'];
28+
if (allowanonymous) {
29+
permissions.unshift('freely');
30+
}
31+
32+
var defaultpermission = process.env.HMD_DEFAULT_PERMISSION || config.defaultpermission;
33+
defaultpermission = permissions.indexOf(defaultpermission) != -1 ? defaultpermission : 'editable';
34+
2735
// db
2836
var dburl = config.dburl || process.env.HMD_DB_URL || process.env.DATABASE_URL;
2937
var db = config.db || {};
@@ -173,6 +181,7 @@ module.exports = {
173181
usecdn: usecdn,
174182
allowanonymous: allowanonymous,
175183
allowfreeurl: allowfreeurl,
184+
defaultpermission: defaultpermission,
176185
dburl: dburl,
177186
db: db,
178187
sslkeypath: path.join(cwd, sslkeypath),

lib/models/note.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -513,10 +513,10 @@ module.exports = function (sequelize, DataTypes) {
513513
}
514514
}
515515
}
516-
// if no permission specified and have owner then give editable permission, else default permission is freely
516+
// if no permission specified and have owner then give default permission in config, else default permission is freely
517517
if (!note.permission) {
518518
if (note.ownerId) {
519-
note.permission = "editable";
519+
note.permission = config.defaultpermission;
520520
} else {
521521
note.permission = "freely";
522522
}

0 commit comments

Comments
 (0)