Add auth and blacklist APIs
This commit is contained in:
42
server/actions/removeFromBlacklist.js
Normal file
42
server/actions/removeFromBlacklist.js
Normal file
@ -0,0 +1,42 @@
|
||||
const validateNpmPackageName = require('validate-npm-package-name')
|
||||
const BlacklistAPI = require('../BlacklistAPI')
|
||||
|
||||
function removeFromBlacklist(req, res) {
|
||||
const packageName = req.params.packageName
|
||||
|
||||
const nameErrors = validateNpmPackageName(packageName).errors
|
||||
|
||||
// Disallow invalid package names.
|
||||
if (nameErrors) {
|
||||
const reason = nameErrors.join(', ')
|
||||
return res.status(403).send({
|
||||
error: `Invalid package name "${packageName}" (${reason})`
|
||||
})
|
||||
}
|
||||
|
||||
BlacklistAPI.removePackage(packageName).then(
|
||||
removed => {
|
||||
if (removed) {
|
||||
const userId = req.user.jti
|
||||
console.log(
|
||||
`Package "${packageName}" was removed from the blacklist by ${userId}`
|
||||
)
|
||||
}
|
||||
|
||||
res.send({
|
||||
ok: true,
|
||||
message: `Package "${packageName}" was ${removed
|
||||
? 'removed from'
|
||||
: 'not in'} the blacklist`
|
||||
})
|
||||
},
|
||||
error => {
|
||||
console.error(error)
|
||||
res.status(500).send({
|
||||
error: `Unable to remove "${packageName}" from the blacklist`
|
||||
})
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
module.exports = removeFromBlacklist
|
Reference in New Issue
Block a user