Skip to content
Closed
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
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,12 @@ Configuration options reference

If the endpoint doesn't provide the email address for the user, allow empty emails to authenticate anyway. Note that GitHub authentication usually requires this to be `true` (unless all wiki users have public email addresses on their GitHub accounts).

#### authorization.moderatorsFile (string: "")

Absolute path for your moderators YAML file. If used, this file must contain a list of `usernames` and `emails` for users who have write access to the wiki. A user who has a match in either the `usernames` or `emails` list will have right access.

If this field is left blank, all logged in users will have write access to the wiki.

#### pages.index (string: "Home")

Defines the page name for the index of the wiki
Expand Down
18 changes: 17 additions & 1 deletion lib/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,23 @@ module.exports.initialize = function (config) {
}
}

app.all('/pages/*', requireAuthentication)
function requireModerator (req, res, next) {
requireAuthentication(req, res, function(){
if (!res.locals.user.moderator) {
res.locals.title = '403 - Permission denied'
res.statusCode = 403
res.render('403.pug')
} else {
next()
}
})
}

if (app.locals.config.get('authorization').moderators) {
app.all('/pages/*', requireModerator)
} else {
app.all('/pages/*', requireAuthentication)
}

if (!app.locals.config.get('authorization').anonRead) {
app.all('/wiki', requireAuthentication)
Expand Down
8 changes: 7 additions & 1 deletion lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ module.exports = (function () {
}
}

// Load moderators from moderatorsFile
if (config.authorization.moderatorsFile){
config.authorization.moderators = yaml.load(fs.readFileSync(config.authorization.moderatorsFile).toString())
}

return true
},

Expand Down Expand Up @@ -121,7 +126,8 @@ module.exports = (function () {
anonRead: true,
validMatches: '.+',
// Breaking changes in Jingo 1.5 (when this parameter has been added): the default for new servers is to NOT allow empty emails to validate
emptyEmailMatches: false
emptyEmailMatches: false,
moderatorsFile: ''
},

// Defaults for the pages key are compatible with Jingo < 1 (which means
Expand Down
13 changes: 13 additions & 0 deletions routes/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,19 @@ passport.deserializeUser(function (user, done) {
user.email = 'jingouser'
}

// Check moderator status
user.moderator = false
var moderators = app.locals.config.get('authorization').moderators
if (moderators){
if (moderators.usernames.indexOf(user.displayName) > -1 ||
moderators.emails.indexOf(user.email) > -1){
user.moderator = true
}
} else {
// If no moderators file supplied everyone is a 'moderator'
user.moderator = true
}

user.asGitAuthor = user.displayName + ' <' + user.email + '>'
done(undefined, user)
})
Expand Down
7 changes: 7 additions & 0 deletions views/403.pug
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
extends layout

block content
#content
.jumbotron
h2 #{title}
p You do not have permission to perform this action