Added moderator based actions

This commit is contained in:
Chris Blanchard 2015-10-20 23:40:40 +01:00
parent 1e53aad63b
commit 86e22c1315
5 changed files with 73 additions and 4 deletions

View file

@ -72,7 +72,7 @@ module.exports = namespace => {
socket.on('message:delete', data => {
var id = data.id;
if (id === undefined || !socket._user.admin) return;
if (id === undefined || !socket._user.isChatAdmin()) return;
Message.update({_id: id}, {deleted: true}, (error, message) => {
if (error) {

View file

@ -102,7 +102,7 @@ module.exports = function (namespace) {
socket.on("gather:leave", function (data) {
if (data && data.gatherer) {
// Remove gatherer defined by ID (admins only)
if (!socket._user.admin) return;
if (!socket._user.isGatherAdmin()) return;
removeGatherer({ id: data.gatherer, cooldown: true });
} else {
// Remove gatherer attached to socket
@ -181,7 +181,7 @@ module.exports = function (namespace) {
});
socket.on("gather:reset", function () {
if (socket._user.admin) {
if (socket._user.isGatherAdmin()) {
Gather.reset();
refreshGather();
}

View file

@ -67,7 +67,7 @@ module.exports = namespace => {
});
socket.on("users:authorize", data => {
if (!socket._user.admin) return;
if (!socket._user.isUserAdmin()) return;
var id = parseInt(data.id, 10);
if (isNaN(id)) return;
User.find(id, (error, user) => {

View file

@ -21,6 +21,7 @@ function User (user) {
this.time_zone = user['time_zone'];
this.avatar = enslClient.baseUrl + user['avatar'];
this.admin = user['admin'];
this.moderator = user['moderator'];
this.team = user['team'];
this.bans = user['bans'];
this.steam = {
@ -38,6 +39,18 @@ function User (user) {
}
}
User.prototype.isChatAdmin = function () {
return this.admin || this.moderator;
};
User.prototype.isGatherAdmin = function () {
return this.admin || this.moderator;
};
User.prototype.isUserAdmin = function () {
return this.admin || this.moderator;
};
User.prototype.getSteamId = function () {
if (this.steam.url === null) return null;
var urlId = this.steam.url.match(/\d*$/);

View file

@ -48,6 +48,62 @@ describe("User", () => {
});
});
describe("Abilities", () => {
describe("isChatAdmin", () => {
it ("returns true if admin", () => {
user.admin = true;
user.moderator = false;
assert.isTrue(user.isChatAdmin());
});
it ("returns true if moderator", () => {
user.admin = false;
user.moderator = true;
assert.isTrue(user.isChatAdmin());
});
it ("returns true if neither admin nor moderator", () => {
user.admin = false;
user.moderator = false;
assert.isFalse(user.isChatAdmin());
});
});
describe("isGatherAdmin", () => {
it ("returns true if admin", () => {
user.admin = true;
user.moderator = false;
assert.isTrue(user.isGatherAdmin());
});
it ("returns true if moderator", () => {
user.admin = false;
user.moderator = true;
assert.isTrue(user.isGatherAdmin());
});
it ("returns true if neither admin nor moderator", () => {
user.admin = false;
user.moderator = false;
assert.isFalse(user.isGatherAdmin());
});
});
describe("isUserAdmin", () => {
it ("returns true if admin", () => {
user.admin = true;
user.moderator = false;
assert.isTrue(user.isUserAdmin());
});
it ("returns true if moderator", () => {
user.admin = false;
user.moderator = true;
assert.isTrue(user.isUserAdmin());
});
it ("returns true if neither admin nor moderator", () => {
user.admin = false;
user.moderator = false;
assert.isFalse(user.isUserAdmin());
});
});
});
describe("#updateProfile", () => {
var profile, user;