add new logic for restricted wikis

This commit is contained in:
Robert Best
2024-09-20 21:26:32 -04:00
committed by 3wc
parent b28d90fcc3
commit 5d7c53d1a2

View File

@ -385,24 +385,31 @@ module.exports = exports = (log, loga, argv) ->
# see http://ward.asia.wiki.org/login-to-view.html
if argv.restricted?
allowedToView = (req) ->
allowed = []
if argv.allowed_domains?
if Array.isArray(argv.allowed_domains)
allowed = argv.allowed_domains
else
# accommodate copy bug to be fixed soon
# https://github.com/fedwiki/wiki/blob/4c6eee69e78c1ba3f3fc8d61f4450f70afb78f10/farm.coffee#L98-L103
for k, v of argv.allowed_domains
allowed.push v
# emails = [ { value: 'ward.cunningham@gmail.com', type: 'account' } ]
emails = req.session?.passport?.user?.google?.emails
return false unless emails
for entry in emails
have = entry.value.split('@')[1]
for want in allowed
return true if want == have
try
allowed_domains = argv.allowed_domains
emails = req.session.passport.user.google.emails
for entry in emails
have = entry.value.split('@')[1]
for want in allowed_domains
return true if want == have
catch error
if emails?
console.log "argv.allowed_domains exists, but there was an error. Make sure it's value is an array in your config."
if argv.allowed_ids?
try
allowed_ids = argv.allowed_ids
idProvider = _.head(_.keys(req.session.passport.user))
switch idProvider
when 'github', 'twitter', 'oauth2'
id = req.session.passport.user[idProvider].id
return true if (allowed_ids.length == 1 and allowed_ids[0] == "*")
for want in allowed_ids
return true if want == id
catch error
if idProvider?
console.log "argv.allowed_ids exists, but there was an error. Make sure it's value is an array in your config."
false
app.all '*', (req, res, next) ->