Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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` | 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 |
Expand Down Expand Up @@ -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` | 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) |
Expand Down
9 changes: 9 additions & 0 deletions lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ 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 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;
var db = config.db || {};
Expand Down Expand Up @@ -173,6 +181,7 @@ module.exports = {
usecdn: usecdn,
allowanonymous: allowanonymous,
allowfreeurl: allowfreeurl,
defaultpermission: defaultpermission,
dburl: dburl,
db: db,
sslkeypath: path.join(cwd, sslkeypath),
Expand Down
4 changes: 2 additions & 2 deletions lib/models/note.js
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
Expand Down