Skip to content
This repository has been archived by the owner on Nov 7, 2020. It is now read-only.

simple event deletion interface. #444

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion lib/unhangout-routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ var _ = require("underscore"),
googleapis = require('googleapis'),
moment = require("moment-timezone"),
mandrill = require("mandrill-api"),
async = require("async");
async = require("async"),
util = require("util");

var ensureAuthenticated = utils.ensureAuthenticated;

Expand Down Expand Up @@ -972,6 +973,32 @@ module.exports = {
event.logAnalytics({action: "stop", user: req.user});
});

app.post("/admin/event/:id/delete", utils.ensureSuperuser, function(req, res) {
var event = db.events.get(req.params.id);
var connectedUsers = event.get("connectedUsers");
var title = event.get("title");
if (connectedUsers.length > 0) {
req.flash("danger", util.format("Cannot delete event %s: users still connected: %d", title, connectedUsers.length));
}
else {
var sessions = event.get('sessions');
// Using the .each() method won't work here, as detailed at
// http://stackoverflow.com/questions/10858935/cleanest-way-to-destroy-every-model-in-a-collection-in-backbone
var session;
var count = 0;
while (session = sessions.first()) {
session.destroy();
count++;
event.logAnalytics({action: "delete-session", user: req.user, session: req.params.id});
}
// This clears the event from users admin caches.
event.set("admins", {});
event.logAnalytics({action: "delete-event", user: req.user, event: event.id});
event.destroy();
req.flash("success", util.format("Event %s and %d related sessions deleted.", title, count));
}
res.redirect("/admin/");
});

app.get("/hangout/gadget.xml", function(req, res) {
var context = {
Expand Down
4 changes: 3 additions & 1 deletion lib/unhangout-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ var logging = require('./logging'),
moment = require('moment-timezone'),
fs = require('fs'),
memwatch = require("memwatch"),
slashes = require("connect-slashes");
slashes = require("connect-slashes"),
flash = require("flash");

// This is the primary class that represents the UnhangoutServer.
// I organize the server pieces into a class so we can more easily
Expand Down Expand Up @@ -199,6 +200,7 @@ exports.UnhangoutServer.prototype = {
store: redisSessionStore,
cookie: {maxAge:1000*60*60*24*2}
}));
this.app.use(flash());

if (this.options.mockAuth) {
var mockPassport = require("./passport-mock");
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"deep-copy": "^1.0.0",
"ejs": "1.0.0",
"express": "3.5.1",
"flash": "1.1.0",
"gapitoken": "0.1.3",
"googleapis": "0.7.0",
"mandrill-api": "1.0.41",
Expand Down
5 changes: 5 additions & 0 deletions public/js/admin.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
require(["jquery", "bootstrap", "auth"], function($) {
$("[rel=popover]").popover({container: "body", placement: "left"});
$("[title]").not("[rel=popover]").tooltip({container: "body"});
$(".delete-event").click(function(event) {
var id = $(this).attr("data-event");
var deleteEvent = confirm("Are you sure you want to delete event " + id + " and all associated sessions? This cannot be undone.");
return deleteEvent;
});
});
16 changes: 15 additions & 1 deletion views/admin.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,16 @@
<% var sessions; %>

<div class='container admin-container'>

<% while (data = flash.shift()) { %>
<div class="alert alert-<%= data.type %>">
<a href="#" class="close" data-dismiss="alert">&times;</a>
<% if (data.type == "danger") { %>
<strong>ERROR:</strong>
<% } %>
<%= data.message %>
</div>
<% } %>

<div class='row-fluid'>
<div class='span6' id='events'>
Expand Down Expand Up @@ -32,10 +42,14 @@
</form>
<% } else { %>
<form action="/admin/event/<%=event.id%>/start" method="post">
<button type="submit" class="btn btn btn-small start-event"
<button type="submit" class="btn btn-small start-event"
data-event='<%= event.id %>'>start</button>
</form>
<% } %>
<form action="/admin/event/<%=event.id%>/delete" method="post">
<button type="submit" class="btn btn-warning btn-small delete-event"
data-event='<%= event.id %>'>delete</button>
</form>
<a href="/admin/event/<%=event.id + '?destination=' + encodeURIComponent(destination)%>" class="btn btn-small">
<i class='fa fa-pencil' title='Edit'></i> edit
</a>
Expand Down