Refactor checkViewPermission to fix limited & protected permission check bug and fix code style
This commit is contained in:
parent
e00daee6c0
commit
1473437295
2 changed files with 31 additions and 23 deletions
|
@ -363,6 +363,22 @@ function interruptConnection(socket, note, user) {
|
|||
connectNextSocket();
|
||||
}
|
||||
|
||||
function checkViewPermission(req, note) {
|
||||
if (note.permission == 'private') {
|
||||
if (req.user && req.user.logged_in && req.user.id == note.owner)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
} else if (note.permission == 'limited' || note.permission == 'protected') {
|
||||
if(req.user && req.user.logged_in)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
var isConnectionBusy = false;
|
||||
var connectionSocketQueue = [];
|
||||
var isDisconnectBusy = false;
|
||||
|
@ -374,14 +390,10 @@ function finishConnection(socket, note, user) {
|
|||
return interruptConnection(socket, note, user);
|
||||
}
|
||||
// check view permission
|
||||
if (note.permission == 'limited' || note.permission == 'protected' || note.permission == 'private') {
|
||||
if (socket.request.user && socket.request.user.logged_in && socket.request.user.id == note.owner) {
|
||||
//na
|
||||
} else {
|
||||
if (!checkViewPermission(socket.request, note)) {
|
||||
interruptConnection(socket, note, user);
|
||||
return failConnection(403, 'connection forbidden', socket);
|
||||
}
|
||||
}
|
||||
// update user color to author color
|
||||
if (note.authors[user.userid]) {
|
||||
user.color = users[socket.id].color = note.authors[user.userid].color;
|
||||
|
@ -790,10 +802,7 @@ function connection(socket) {
|
|||
var sock = note.socks[i];
|
||||
if (typeof sock !== 'undefined' && sock) {
|
||||
// check view permission
|
||||
if (permission == 'limited' || permission == 'protected' || permission == 'private') {
|
||||
if (sock.request.user && sock.request.user.logged_in && sock.request.user.id == note.owner) {
|
||||
//na
|
||||
} else {
|
||||
if (!checkViewPermission(sock.request, note)) {
|
||||
sock.emit('info', {
|
||||
code: 403
|
||||
});
|
||||
|
@ -803,7 +812,6 @@ function connection(socket) {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}).catch(function (err) {
|
||||
return logger.error('update note permission failed: ' + err);
|
||||
});
|
||||
|
|
|
@ -127,9 +127,9 @@ function checkViewPermission(req, note) {
|
|||
else
|
||||
return true;
|
||||
} else if (note.permission == 'limited' || note.permission == 'protected') {
|
||||
if( !req.isAuthenticated() ) {
|
||||
if(!req.isAuthenticated())
|
||||
return false;
|
||||
}
|
||||
else
|
||||
return true;
|
||||
} else {
|
||||
return true;
|
||||
|
|
Loading…
Reference in a new issue