Skip to content

Commit

Permalink
only allow needed write operations on collections
Browse files Browse the repository at this point in the history
  • Loading branch information
Tim Adye authored and Tim Adye committed Apr 1, 2023
1 parent 6281646 commit ef660fb
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 18 deletions.
4 changes: 2 additions & 2 deletions client/lib/session.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ setAdminMode = function() {
});
}

setCurrentGame = function(gameName, onReadyPlayers=null) {
setCurrentGame = function (gameName, onReadyPlayers=null) {
if (debug >= 2) console.log('setCurrentGame', gameName);
const gameID = Session.get('gameID');
if (gameID) {
Expand All @@ -89,7 +89,7 @@ setCurrentGame = function(gameName, onReadyPlayers=null) {
}
}

joinGame = function(gameName, onReadyPlayers=null) {
joinGame = function (gameName, onReadyPlayers=null) {
MeteorSubs.subscribe('game', gameName, {
onReady: () => {
if (debug >= 2) console.log('joinGame games onReady', gameName);
Expand Down
30 changes: 14 additions & 16 deletions lib/collections.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,30 @@ collections = function() {
GamesHistory = new Mongo.Collection("gamesHistory");
TurnsHistory = new Mongo.Collection("turnsHistory");

var allowFunctions = {
insert: function (userId, doc) {
Games.allow({
update: (userId, doc, fields, modifier) => {
return true;
},
update: function (userId, doc, fields, modifier) {
});

Players.allow({
insert: (userId, doc) => {
return true;
},
remove: function (userId, doc) {
update: (userId, doc, fields, modifier) => {
return true;
},
};
remove: (userId, doc) => {
return true;
},
});

var denyFunctions = {
insert: function(userId, doc) {
Players.deny({
insert: (userId, doc) => {
doc.createdAt = new Date().valueOf();
return false;
},
};

Games.allow(allowFunctions);
Players.allow(allowFunctions);
GamesHistory.allow(allowFunctions);
TurnsHistory.allow(allowFunctions);

Games.deny(denyFunctions);
Players.deny(denyFunctions);
});
}

initialGame = function() {
Expand Down

0 comments on commit ef660fb

Please sign in to comment.