diff options
author | Simon Bartlett <simon@securitycompass.com> | 2015-02-21 16:16:09 -0500 |
---|---|---|
committer | Simon Bartlett <simon@securitycompass.com> | 2015-02-21 16:16:09 -0500 |
commit | 84981a6d2534445c00ea4e095c934e46943c0b1d (patch) | |
tree | e2e8bd6f809ba6864e639fd32f2c6420b61feff3 /app/core/files.js | |
parent | 1e7e6c0fde5b1c7bb4ecfebd59a28fe2cbd44be8 (diff) | |
download | lets-chat-84981a6d2534445c00ea4e095c934e46943c0b1d.zip lets-chat-84981a6d2534445c00ea4e095c934e46943c0b1d.tar.gz lets-chat-84981a6d2534445c00ea4e095c934e46943c0b1d.tar.bz2 |
Participants are stored for passworded rooms.
List methods for messages and files are protected.
Diffstat (limited to 'app/core/files.js')
-rw-r--r-- | app/core/files.js | 37 |
1 files changed, 31 insertions, 6 deletions
diff --git a/app/core/files.js b/app/core/files.js index 45923f3..a902af0 100644 --- a/app/core/files.js +++ b/app/core/files.js @@ -35,8 +35,8 @@ FileManager.prototype.create = function(options, cb) { } var File = mongoose.model('File'), - Room = mongoose.model('Room'), - User = mongoose.model('User'); + Room = mongoose.model('Room'), + User = mongoose.model('User'); if (settings.restrictTypes && settings.allowedTypes && @@ -96,6 +96,8 @@ FileManager.prototype.create = function(options, cb) { }; FileManager.prototype.list = function(options, cb) { + var Room = mongoose.model('Room'); + if (!enabled) { return cb(null, []); } @@ -147,14 +149,37 @@ FileManager.prototype.list = function(options, cb) { find.sort({ 'uploaded': 1 }); } - find - .limit(options.take) - .exec(function(err, files) { + Room.findById(options.room, function(err, room) { if (err) { console.error(err); return cb(err); } - cb(null, files); + + var opts = { + userId: options.userId, + password: options.password + }; + + room.canJoin(opts, function(err, canJoin) { + if (err) { + console.error(err); + return cb(err); + } + + if (!canJoin) { + return cb(null, []); + } + + find + .limit(options.take) + .exec(function(err, files) { + if (err) { + console.error(err); + return cb(err); + } + cb(null, files); + }); + }); }); }; |