Remove blacklist code
This commit is contained in:
@ -1,47 +0,0 @@
|
||||
import validateNpmPackageName from 'validate-npm-package-name';
|
||||
|
||||
import { addPackage } from '../utils/blacklist';
|
||||
|
||||
export default function addToBlacklist(req, res) {
|
||||
const packageName = req.body.packageName;
|
||||
|
||||
if (!packageName) {
|
||||
return res
|
||||
.status(403)
|
||||
.send({ error: 'Missing "packageName" body parameter' });
|
||||
}
|
||||
|
||||
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})`
|
||||
});
|
||||
}
|
||||
|
||||
addPackage(packageName).then(
|
||||
added => {
|
||||
if (added) {
|
||||
const userId = req.user.jti;
|
||||
console.log(
|
||||
`Package "${packageName}" was added to the blacklist by ${userId}`
|
||||
);
|
||||
}
|
||||
|
||||
res.send({
|
||||
ok: true,
|
||||
message: `Package "${packageName}" was ${
|
||||
added ? 'added to' : 'already in'
|
||||
} the blacklist`
|
||||
});
|
||||
},
|
||||
error => {
|
||||
console.error(error);
|
||||
res.status(500).send({
|
||||
error: `Unable to add "${packageName}" to the blacklist`
|
||||
});
|
||||
}
|
||||
);
|
||||
}
|
@ -1,10 +1,6 @@
|
||||
import { createToken } from '../utils/auth';
|
||||
|
||||
const defaultScopes = {
|
||||
blacklist: {
|
||||
read: true
|
||||
}
|
||||
};
|
||||
const defaultScopes = {};
|
||||
|
||||
export default function createAuth(req, res) {
|
||||
createToken(defaultScopes).then(
|
||||
|
@ -1,50 +0,0 @@
|
||||
import validateNpmPackageName from 'validate-npm-package-name';
|
||||
|
||||
import { removePackage } from '../utils/blacklist';
|
||||
|
||||
export default function removeFromBlacklist(req, res) {
|
||||
// TODO: Remove req.packageName when DELETE
|
||||
// /_blacklist/:packageName API is removed
|
||||
const packageName = req.body.packageName || req.packageName;
|
||||
|
||||
if (!packageName) {
|
||||
return res
|
||||
.status(403)
|
||||
.send({ error: 'Missing "packageName" body parameter' });
|
||||
}
|
||||
|
||||
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})`
|
||||
});
|
||||
}
|
||||
|
||||
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`
|
||||
});
|
||||
}
|
||||
);
|
||||
}
|
@ -1,15 +0,0 @@
|
||||
import { getPackages } from '../utils/blacklist';
|
||||
|
||||
export default function showBlacklist(req, res) {
|
||||
getPackages().then(
|
||||
blacklist => {
|
||||
res.send({ blacklist });
|
||||
},
|
||||
error => {
|
||||
console.error(error);
|
||||
res.status(500).send({
|
||||
error: 'Unable to fetch blacklist'
|
||||
});
|
||||
}
|
||||
);
|
||||
}
|
Reference in New Issue
Block a user