mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2025-12-14 07:27:01 +03:00
Don't revive segments for videos marked with noSegment when un-banning a user
This commit is contained in:
@@ -3,6 +3,7 @@ var db = databases.db;
|
||||
var privateDB = databases.privateDB;
|
||||
|
||||
var getHash = require('../utils/getHash.js');
|
||||
const logger = require('../utils/logger.js');
|
||||
|
||||
module.exports = async function shadowBanUser(req, res) {
|
||||
let userID = req.query.userID;
|
||||
@@ -47,7 +48,7 @@ module.exports = async function shadowBanUser(req, res) {
|
||||
|
||||
//find all previous submissions and hide them
|
||||
if (unHideOldSubmissions) {
|
||||
db.prepare('run', "UPDATE sponsorTimes SET shadowHidden = 1 WHERE userID = ?", [userID]);
|
||||
db.prepare('run', "UPDATE sponsorTimes SET shadowHidden = 1 WHERE userID = ?", [userID]);
|
||||
}
|
||||
} else if (!enabled && row.userCount > 0) {
|
||||
//remove them from the shadow ban list
|
||||
@@ -55,7 +56,14 @@ module.exports = async function shadowBanUser(req, res) {
|
||||
|
||||
//find all previous submissions and unhide them
|
||||
if (unHideOldSubmissions) {
|
||||
db.prepare('run', "UPDATE sponsorTimes SET shadowHidden = 0 WHERE userID = ?", [userID]);
|
||||
let segmentsToIgnore = db.prepare('all', "SELECT uuid FROM sponsorTimes st JOIN noSegments ns on st.videoID = ns.videoID AND st.category = ns.category WHERE st.userID = ?", [userID]).map((item) => item.UUID);
|
||||
let allSegments = db.prepare('all', "SELECT uuid FROM sponsorTimes st WHERE st.userID = ?", [userID]).map((item) => item.UUID);
|
||||
|
||||
allSegments.filter((item) => {
|
||||
return segmentsToIgnore.indexOf(item) === -1;
|
||||
}).forEach((uuid) => {
|
||||
db.prepare('run', "UPDATE sponsorTimes SET shadowHidden = 0 WHERE uuid = ?", [uuid]);
|
||||
});
|
||||
}
|
||||
}
|
||||
} else if (hashedIP) {
|
||||
|
||||
@@ -7,13 +7,13 @@ var getHash = require('../../src/utils/getHash.js');
|
||||
describe('getSkipSegments', () => {
|
||||
before(() => {
|
||||
let startOfQuery = "INSERT INTO sponsorTimes (videoID, startTime, endTime, votes, UUID, userID, timeSubmitted, views, category, shadowHidden, hashedVideoID) VALUES";
|
||||
db.exec(startOfQuery + "('testtesttest', 1, 11, 2, '1-uuid-0', 'testman', 0, 50, 'sponsor', 0, '" + getHash('testtesttest', 0) + "')");
|
||||
db.exec(startOfQuery + "('testtesttest', 20, 33, 2, '1-uuid-2', 'testman', 0, 50, 'intro', 0, '" + getHash('testtesttest', 0) + "')");
|
||||
db.exec(startOfQuery + "('testtesttest,test', 1, 11, 2, '1-uuid-1', 'testman', 0, 50, 'sponsor', 0, '" + getHash('testtesttest,test', 0) + "')");
|
||||
db.exec(startOfQuery + "('test3', 1, 11, 2, '1-uuid-4', 'testman', 0, 50, 'sponsor', 0, '" + getHash('test3', 0) + "')");
|
||||
db.exec(startOfQuery + "('test3', 7, 22, -3, '1-uuid-5', 'testman', 0, 50, 'sponsor', 0, '" + getHash('test3', 0) + "')");
|
||||
db.exec(startOfQuery + "('multiple', 1, 11, 2, '1-uuid-6', 'testman', 0, 50, 'intro', 0, '" + getHash('multiple', 0) + "')");
|
||||
db.exec(startOfQuery + "('multiple', 20, 33, 2, '1-uuid-7', 'testman', 0, 50, 'intro', 0, '" + getHash('multiple', 0) + "')");
|
||||
db.exec(startOfQuery + "('testtesttest', 1, 11, 2, '1-uuid-0', 'testman', 0, 50, 'sponsor', 0, '" + getHash('testtesttest', 1) + "')");
|
||||
db.exec(startOfQuery + "('testtesttest', 20, 33, 2, '1-uuid-2', 'testman', 0, 50, 'intro', 0, '" + getHash('testtesttest', 1) + "')");
|
||||
db.exec(startOfQuery + "('testtesttest,test', 1, 11, 2, '1-uuid-1', 'testman', 0, 50, 'sponsor', 0, '" + getHash('testtesttest,test', 1) + "')");
|
||||
db.exec(startOfQuery + "('test3', 1, 11, 2, '1-uuid-4', 'testman', 0, 50, 'sponsor', 0, '" + getHash('test3', 1) + "')");
|
||||
db.exec(startOfQuery + "('test3', 7, 22, -3, '1-uuid-5', 'testman', 0, 50, 'sponsor', 0, '" + getHash('test3', 1) + "')");
|
||||
db.exec(startOfQuery + "('multiple', 1, 11, 2, '1-uuid-6', 'testman', 0, 50, 'intro', 0, '" + getHash('multiple', 1) + "')");
|
||||
db.exec(startOfQuery + "('multiple', 20, 33, 2, '1-uuid-7', 'testman', 0, 50, 'intro', 0, '" + getHash('multiple', 1) + "')");
|
||||
});
|
||||
|
||||
|
||||
|
||||
79
test/cases/unBan.js
Normal file
79
test/cases/unBan.js
Normal file
@@ -0,0 +1,79 @@
|
||||
var request = require('request');
|
||||
|
||||
var utils = require('../utils.js');
|
||||
const getHash = require('../../src/utils/getHash.js');
|
||||
|
||||
var databases = require('../../src/databases/databases.js');
|
||||
const logger = require('../../src/utils/logger.js');
|
||||
var db = databases.db;
|
||||
|
||||
describe('unBan', () => {
|
||||
before(() => {
|
||||
db.exec("INSERT INTO shadowBannedUsers VALUES('testMan-unBan')");
|
||||
db.exec("INSERT INTO shadowBannedUsers VALUES('testWoman-unBan')");
|
||||
db.exec("INSERT INTO shadowBannedUsers VALUES('testEntity-unBan')");
|
||||
|
||||
db.exec("INSERT INTO vipUsers (userID) VALUES ('" + getHash("VIPUser-unBan") + "')");
|
||||
db.exec("INSERT INTO noSegments (userID, videoID, category) VALUES ('" + getHash("VIPUser-unBan") + "', 'unBan-videoID-1', 'sponsor')");
|
||||
|
||||
let startOfInsertSegmentQuery = "INSERT INTO sponsorTimes (videoID, startTime, endTime, votes, UUID, userID, timeSubmitted, views, category, shadowHidden, hashedVideoID) VALUES";
|
||||
db.exec(startOfInsertSegmentQuery + "('unBan-videoID-0', 1, 11, 2, 'unBan-uuid-0', 'testMan-unBan', 0, 50, 'sponsor', 1, '" + getHash('unBan-videoID-0', 1) + "')");
|
||||
db.exec(startOfInsertSegmentQuery + "('unBan-videoID-1', 1, 11, 2, 'unBan-uuid-1', 'testWoman-unBan', 0, 50, 'sponsor', 1, '" + getHash('unBan-videoID-1', 1) + "')");
|
||||
db.exec(startOfInsertSegmentQuery + "('unBan-videoID-1', 1, 11, 2, 'unBan-uuid-2', 'testEntity-unBan', 0, 60, 'sponsor', 1, '" + getHash('unBan-videoID-1', 1) + "')");
|
||||
db.exec(startOfInsertSegmentQuery + "('unBan-videoID-2', 1, 11, 2, 'unBan-uuid-3', 'testEntity-unBan', 0, 60, 'sponsor', 1, '" + getHash('unBan-videoID-2', 1) + "')");
|
||||
});
|
||||
|
||||
it('Should be able to unban a user and re-enable shadow banned segments', (done) => {
|
||||
request.post(utils.getbaseURL() + "/api/shadowBanUser?userID=testMan-unBan&adminUserID=VIPUser-unBan&enabled=false", null, (err, res, body) => {
|
||||
if (err) done(err);
|
||||
else if (res.statusCode === 200) {
|
||||
let result = db.prepare('all', 'SELECT * FROM sponsorTimes WHERE videoID = ? AND userID = ? AND shadowHidden = ?', ['unBan-videoID-0', 'testMan-unBan', 1]);
|
||||
if (result.length !== 0) {
|
||||
console.log(result);
|
||||
done("Expected 0 banned entrys in db, got " + result.length);
|
||||
} else {
|
||||
done();
|
||||
}
|
||||
} else {
|
||||
console.log(body);
|
||||
done("Status code was " + res.statusCode);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
it('Should be able to unban a user and re-enable shadow banned segments without noSegment entrys', (done) => {
|
||||
request.post(utils.getbaseURL() + "/api/shadowBanUser?userID=testWoman-unBan&adminUserID=VIPUser-unBan&enabled=false", null, (err, res, body) => {
|
||||
if (err) done(err);
|
||||
else if (res.statusCode === 200) {
|
||||
let result = db.prepare('all', 'SELECT * FROM sponsorTimes WHERE videoID = ? AND userID = ? AND shadowHidden = ?', ['unBan-videoID-1', 'testWoman-unBan', 1]);
|
||||
if (result.length !== 1) {
|
||||
console.log(result);
|
||||
done("Expected 1 banned entry1 in db, got " + result.length);
|
||||
} else {
|
||||
done();
|
||||
}
|
||||
} else {
|
||||
console.log(body);
|
||||
done("Status code was " + res.statusCode);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
it('Should be able to unban a user and re-enable shadow banned segments with a mix of noSegment entrys', (done) => {
|
||||
request.post(utils.getbaseURL() + "/api/shadowBanUser?userID=testEntity-unBan&adminUserID=VIPUser-unBan&enabled=false", null, (err, res, body) => {
|
||||
if (err) done(err);
|
||||
else if (res.statusCode === 200) {
|
||||
let result = db.prepare('all', 'SELECT * FROM sponsorTimes WHERE userID = ? AND shadowHidden = ?', ['testEntity-unBan', 1]);
|
||||
if (result.length !== 1) {
|
||||
console.log(result);
|
||||
done("Expected 1 banned entry1 in db, got " + result.length);
|
||||
} else {
|
||||
done();
|
||||
}
|
||||
} else {
|
||||
console.log(body);
|
||||
done("Status code was " + res.statusCode);
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user