Implemented admin kicks

This commit is contained in:
Chris Blanchard 2015-09-17 13:36:18 +01:00
parent c5b2d10356
commit 1fd8835d20
2 changed files with 40 additions and 7 deletions

View File

@ -66,11 +66,22 @@ module.exports = function (namespace) {
});
});
socket.on("gather:leave", function (data) {
let removeGatherer = user => {
let gather = Gather.current;
if (gather.can("removeGatherer")) gather.removeGatherer(socket._user);
winston.info("Gather Leaver", JSON.stringify(socket._user));
if (gather.can("removeGatherer")) gather.removeGatherer(user);
winston.info("Gather Leaver", JSON.stringify(user));
refreshGather();
}
socket.on("gather:leave", function (data) {
if (data.gatherer) {
// Remove gatherer defined by ID (admins only)
if (!socket._user.admin) return;
removeGatherer({ id: data.gatherer });
} else {
// Remove gatherer attached to socket
removeGatherer(socket._user);
}
});
socket.on("gather:select", function (data) {

View File

@ -549,6 +549,7 @@ var Gather = React.createClass({
componentDidMount() {
var self = this;
socket.on("users:update", data => self.setProps({user: data.currentUser}));
socket.on("gather:refresh", (data) => {
self.checkForStateChange(data);
self.setProps(data)
@ -607,17 +608,22 @@ var Gather = React.createClass({
});
var Gatherers = React.createClass({
componentDidMount() {
$('[data-toggle="tooltip"]').tooltip()
},
joinGather(e) {
e.preventDefault();
socket.emit("gather:join");
},
bootGatherer(e) {
e.preventDefault();
socket.emit("gather:leave", {
gatherer: parseInt(e.target.value, 10) || null
});
},
render() {
var self = this;
var user = this.props.user;
var admin = (user && user.admin);
var gatherers = this.props.gather.gatherers
.sort((a, b) => {
return (b.user.hive.skill || 1000) - (a.user.hive.skill || 1000);
@ -691,6 +697,21 @@ var Gatherers = React.createClass({
})
}
var adminOptions;
if (admin) {
adminOptions = [
<dt>Admin</dt>,
<dd>
<button
className="btn btn-xs btn-danger"
value={gatherer.user.id}
onClick={this.bootGatherer}>
Boot from Gather
</button>
</dd>
]
}
return (
<div className="panel panel-success gatherer-panel" key={gatherer.user.id} data-userid={gatherer.user.id}>
<div className="panel-heading">
@ -719,6 +740,7 @@ var Gatherers = React.createClass({
<dd>{team}</dd>
<dt>Hive Stats</dt>
<dd>{hive}</dd>
{adminOptions}
</dl>
</div>
</div>