Skip to content

Commit

Permalink
Restrictions (#95)
Browse files Browse the repository at this point in the history
Rewrite of bans / mutes
Added silent mutes
New restriction modal
Removed room.banUser and replaced with room.restrict.<restriction type>
(currently 'ban', 'mute' and 'silent_mute')
  • Loading branch information
explodingcamera committed Jun 14, 2016
1 parent 6bd8cd9 commit 35ea76c
Show file tree
Hide file tree
Showing 8 changed files with 656 additions and 353 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"update": "node ./mqp.js update"
},
"dependencies": {
"basic-logger": "^0.4.4",
"chalk": "^1.0.0",
"clean-css": "^3.4.9",
"compression": "^1.6.2",
Expand Down
24 changes: 18 additions & 6 deletions serverconfig.example.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,9 @@ config.db = {
'playlist.import': Ability to import playlists
'playlist.shuffle': Ability to shuffle playlists
'room.grantroles': Ability to change user roles (requires canGrantPerms property)
'room.banUser': Ability to ban and unban users
'room.restrict.ban': Ability to ban and unban users
'room.restrict.mute': Ability to mute and unmute users
'room.restrict.mute_silent': Ability to shadow mute and unmute users
'room.ratelimit.bypass': Will bypass ratelimit
'room.whois': Possibility to request additional information about a user
'room.whois.iphistory': Possibility to request all IP addresses that the user logged from since account creation
Expand Down Expand Up @@ -201,7 +203,9 @@ config.roles = {
'playlist.import',
'playlist.shuffle',
'room.grantroles',
'room.banUser',
'room.restrict.ban',
'room.restrict.mute',
'room.restrict.mute_silent',
'room.ratelimit.bypass',
'room.whois',
'room.whois.iphistory',
Expand Down Expand Up @@ -247,7 +251,9 @@ config.roles = {
'playlist.import',
'playlist.shuffle',
'room.grantroles',
'room.banUser',
'room.restrict.ban',
'room.restrict.mute',
'room.restrict.mute_silent',
'room.ratelimit.bypass',
'room.whois',
],
Expand Down Expand Up @@ -292,7 +298,9 @@ config.roles = {
'playlist.import',
'playlist.shuffle',
'room.grantroles',
'room.banUser',
'room.restrict.ban',
'room.restrict.mute',
'room.restrict.mute_silent',
'room.ratelimit.bypass',
'room.whois',
'room.whois.iphistory',
Expand Down Expand Up @@ -333,7 +341,9 @@ config.roles = {
'playlist.import',
'playlist.shuffle',
'room.grantroles',
'room.banUser',
'room.restrict.ban',
'room.restrict.mute',
'room.restrict.mute_silent',
'room.ratelimit.bypass',
'room.whois',
],
Expand All @@ -357,7 +367,9 @@ config.roles = {
'chat.send',
'chat.delete',
'chat.specialMention',
'room.banUser',
'room.restrict.ban',
'room.restrict.mute',
'room.restrict.mute_silent',
'room.ratelimit.bypass',
],
canGrantRoles: [],
Expand Down
37 changes: 21 additions & 16 deletions socketserver/db_mysql.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,14 +121,15 @@ var MysqlDB = function(){
`role` VARCHAR(32) NOT NULL\
);\
\
CREATE TABLE IF NOT EXISTS `bans` (\
CREATE TABLE IF NOT EXISTS `restrictions` (\
`slug` VARCHAR(32),\
`id` INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,\
`uid` INT(11) NOT NULL,\
`uid_by` INT(11) NOT NULL,\
`reason` VARCHAR(256) NULL,\
`start` DATETIME,\
`end` DATETIME,\
`type` VARCHAR(16),\
PRIMARY KEY (`id`)\
);\
\
Expand Down Expand Up @@ -262,8 +263,8 @@ MysqlDB.prototype.getRoom = function(slug, callback) {

var out = {
roles: {},
restrictions: {},
globalRoles: {},
bans: {},
history: [],
}

Expand Down Expand Up @@ -299,18 +300,19 @@ MysqlDB.prototype.getRoom = function(slug, callback) {
staffOverrides[res[ind].uid] = res[ind].role;
}
}

that.execute("SELECT `uid`, `uid_by`, `reason`, UNIX_TIMESTAMP(`start`), UNIX_TIMESTAMP(`end`), (SELECT `role` FROM `roles` WHERE `roles`.`uid` = `bans`.`uid_by` AND ?) as `role` FROM `bans` WHERE ?;", [ { slug: slug, }, { slug: slug, } ], function(err, res) {
that.execute("SELECT `uid`, `uid_by`, `reason`, UNIX_TIMESTAMP(`start`) as `start`, UNIX_TIMESTAMP(`end`) as `end`, (SELECT `role` FROM `roles` WHERE `roles`.`uid` = `restrictions`.`uid_by` AND ?) as `role`, `type` FROM `restrictions` WHERE ?;", [ { slug: slug, }, { slug: slug, } ], function(err, res) {
if(err) { callback(err); return; }

for(var ind in res){
var obj = res[ind];
out.bans[obj.uid] = {
out.restrictions[obj.uid] = out.restrictions[obj.uid] || {};
out.restrictions[obj.uid][obj.type] = {
uid: obj.uid,
start: obj.start * 1000,
end: obj.end * 1000,
reason: obj.reason,
bannedBy: {
source: {
uid: obj.uid_by,
role: obj.role,
}
Expand Down Expand Up @@ -371,8 +373,8 @@ MysqlDB.prototype.setRoom = function(slug, val, callback) {

callback = callback || function(){};

var outRoles = [], outBans = [], outHistory = [];

var outRoles = [], outRestrictions = [], outHistory = [];
for(var key in val.roles){
var globalUser = val.globalRoles[key] || [];
for(var ind in val.roles[key]) {
Expand All @@ -381,25 +383,28 @@ MysqlDB.prototype.setRoom = function(slug, val, callback) {
}
}
}
for(var key in val.bans){
var obj = val.bans[key];
outBans.push([ slug, key, obj.bannedBy.uid, obj.reason, new Date(obj.start), new Date(obj.end) ]);
for(var key in val.restrictions){
var obj = val.restrictions[key];
for(var type in obj){
var restobj = obj[type];
outRestrictions.push([ slug, key, restobj.source.uid, restobj.reason, new Date(restobj.start), new Date(restobj.end), type ]);
}
}
for(var ind in val.history){
var obj = val.history[ind];
outHistory.push([ slug, obj.user.uid, obj.song.cid, new Date(obj.start), obj.song.duration, obj.song.title, obj.votes.like, obj.votes.grab, obj.votes.dislike ]);
}

var query = "DELETE FROM `roles` WHERE ?; DELETE FROM `bans` WHERE ?;DELETE FROM `history_dj` WHERE ?;";
var query = "DELETE FROM `roles` WHERE ?; DELETE FROM `restrictions` WHERE ?;DELETE FROM `history_dj` WHERE ?;";
var params = [{ slug: slug, }, { slug: slug, }, { slug: slug, }];

if(outRoles.length){
query += "INSERT INTO `roles`(??) VALUES ?;";
params.push([ 'slug', 'uid', 'role' ], outRoles);
}
if(outBans.length){
query += "INSERT INTO `bans`(??) VALUES ?;";
params.push([ 'slug', 'uid', 'uid_by', 'reason', 'start', 'end' ], outBans);
if(outRestrictions.length){
query += "INSERT INTO `restrictions`(??) VALUES ?;";
params.push([ 'slug', 'uid', 'uid_by', 'reason', 'start', 'end', 'type' ], outRestrictions);
}
if(outHistory.length){
query += "INSERT INTO `history_dj`(??) VALUES ?;";
Expand Down
Loading

0 comments on commit 35ea76c

Please sign in to comment.