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

Commit

Permalink
Only allow and reveal CREATE SESSION for admins
Browse files Browse the repository at this point in the history
  • Loading branch information
yourcelf committed Jun 28, 2016
1 parent fbc4411 commit d2ea5bc
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 46 deletions.
12 changes: 12 additions & 0 deletions lib/unhangout-sockets.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,18 @@ _.extend(UnhangoutSocketManager.prototype, events.EventEmitter.prototype, {
mgr.on("create-session", _.bind(function(socket, args) {
var event = this.getEvent(args.roomId);
if (event && socket.user) {
if (event.get("adminProposedSessions")) {
if (!socket.user.isAdminOf(event)) {
return mgr.writeErr(socket, "Not an admin.");
}
} else if (event.get("randomizedSessions")) {
return mgr.writeErr(socket, "Can't create sessions in randomized mode.");
} else {
if (!socket.user.isAdminOf(event) && args.approved) {
return mgr.writeErr(socket, "Only admins can approve sessions");
}
}

var joinCap = parseInt(args.joinCap ||
models.ServerSession.prototype.MAX_ATTENDEES);
if (isNaN(joinCap) || joinCap < 2 || joinCap > 10) {
Expand Down
27 changes: 3 additions & 24 deletions public/js/event-app.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,9 @@ $(document).ready(function() {
this.topLeft.show(this.youtubeEmbedView);

this.centerLeft.show(this.sessionListView);
this.sessionListView.onRender();
this.main.show(this.topicListView);
this.topicListView.onRender();

this.dialogs.show(this.dialogView);
this.top.show(this.aboutView);
Expand All @@ -166,32 +168,9 @@ $(document).ready(function() {
$('#session_name').focus();
});

/*
When the app loads show or hide the breakout
rooms list view controls accordingly
*/
if(curEvent.get("randomizedSessions")) {
$("#btn-propose-session").hide();
$("#btn-create-session").hide();
$("#btn-group-me").show();
$("#random-list").show();
$("#topic-list").hide();
} else {
$("#random-list").hide();
$("#btn-group-me").hide();
if(!curEvent.get("adminProposedSessions")) {
$("#btn-propose-session").show();
$("#btn-create-session").hide();
$("#topic-list").show();
} else {
$("#btn-propose-session").hide();
$("#btn-create-session").show();
$("#topic-list").hide();
}
}

if(IS_ADMIN) {
curEvent.on("change:adminProposedSessions change:sessionsOpen change:open", _.bind(function() {
curEvent.on("change:adminProposedSessions change:randomizedSessions change:sessionsOpen change:open", _.bind(function() {
this.adminButtonView.render();
}, this));
}
Expand Down
44 changes: 22 additions & 22 deletions public/js/event-views.js
Original file line number Diff line number Diff line change
Expand Up @@ -559,8 +559,8 @@ views.SessionListView = Backbone.Marionette.CollectionView.extend({

initialize: function() {
this.renderControls();
this.listenTo(this.options.event, 'change:adminProposedSessions', this.render, this);
this.listenTo(this.options.event, 'change:randomizedSessions', this.render, this);
this.listenTo(this.options.event, 'change:adminProposedSessions', this.onRender, this);
this.listenTo(this.options.event, 'change:randomizedSessions', this.onRender, this);
this.listenTo(this.options.event.get("sessions"), 'change:assignedParticipants', this.render, this);
this.listenTo(this.options.event.get("sessions"), 'remove', this.render, this);
},
Expand Down Expand Up @@ -611,26 +611,27 @@ views.SessionListView = Backbone.Marionette.CollectionView.extend({
},

onRender: function() {
/*
When the app loads show or hide the breakout
rooms list view controls accordingly
*/
if(this.options.event.get("randomizedSessions")) {
$("#btn-propose-session").hide();
$("#btn-create-session").hide();
$("#btn-group-me").show();
var thisEventAssign = this.getMySessionAssignment();
if(thisEventAssign) {
$("#btn-group-me").find(".text").text("REGROUP ME");
} else {
$("#btn-group-me").find(".text").text("GROUP ME");
}
$("#random-list").show();
} else if (this.options.event.get("adminProposedSessions")) {
$("#btn-propose-session").hide();
$("#btn-create-session").toggle(IS_ADMIN);
$("#btn-group-me").hide();
$("#random-list").hide();
} else {
// participant proposed
$("#btn-propose-session").show();
$("#btn-create-session").hide();
$("#btn-group-me").hide();
if(this.options.event.get("adminProposedSessions")) {
$("#btn-propose-session").hide();
$("#btn-create-session").show();
} else {
$("#btn-propose-session").show();
$("#btn-create-session").hide();
}
}
$("#random-list").hide();
}
}
});

Expand All @@ -652,12 +653,11 @@ views.TopicListView = Backbone.Marionette.CollectionView.extend({
onRender: function() {
if(this.options.event.get("randomizedSessions")) {
$("#topic-list").hide();
} else {
if(this.options.event.get("adminProposedSessions")) {
$("#topic-list").hide();
} else {
$("#topic-list").show();
}
} else if (this.options.event.get("adminProposedSessions")) {
$("#topic-list").hide();
} else {
// participant proposed
$("#topic-list").show();
}
},
});
Expand Down

0 comments on commit d2ea5bc

Please sign in to comment.