PadMessageHandler: early return to reduce code depth.

Get rid of an else branch to simplify code layout. No functional changes at all.

==============

This series is an attempt to reduce the control structure depth of the code
base, maintaining at the same time its exact same behaviour, bugs included. It
is, in a sense, an initial attempt at a refactoring in the spirit of its
original definition [0].

The idea beyond this refactoring is that reducing the code depth and, sometimes,
inverting some conditions, bugs and logic errors may become easier to spot, and
the code easier to read.

When looked at ignoring whitespace changes, all of these diffs should appear
trivial.

[0] https://refactoring.com/
This commit is contained in:
muxator 2018-08-29 00:57:28 +02:00
parent 07bc163cb6
commit 324929ca2d

View file

@ -265,33 +265,34 @@ exports.handleMessage = function(client, message)
if(!sessioninfos[client.id].auth){ if(!sessioninfos[client.id].auth){
console.error("Auth was never applied to a session. If you are using the stress-test tool then restart Etherpad and the Stress test tool.") console.error("Auth was never applied to a session. If you are using the stress-test tool then restart Etherpad and the Stress test tool.")
return; return;
}else{ }
var auth = sessioninfos[client.id].auth;
var checkAccessCallback = function(err, statusObject)
{
if(ERR(err, callback)) return;
//access was granted var auth = sessioninfos[client.id].auth;
if(statusObject.accessStatus == "grant") var checkAccessCallback = function(err, statusObject)
{ {
callback(); if(ERR(err, callback)) return;
}
//no access, send the client a message that tell him why //access was granted
else if(statusObject.accessStatus == "grant")
{ {
client.json.send({accessStatus: statusObject.accessStatus}) callback();
}
};
//check if pad is requested via readOnly
if (auth.padID.indexOf("r.") === 0) {
//Pad is readOnly, first get the real Pad ID
readOnlyManager.getPadId(auth.padID, function(err, value) {
ERR(err);
securityManager.checkAccess(value, auth.sessionID, auth.token, auth.password, checkAccessCallback);
});
} else {
securityManager.checkAccess(auth.padID, auth.sessionID, auth.token, auth.password, checkAccessCallback);
} }
//no access, send the client a message that tell him why
else
{
client.json.send({accessStatus: statusObject.accessStatus})
}
};
//check if pad is requested via readOnly
if (auth.padID.indexOf("r.") === 0) {
//Pad is readOnly, first get the real Pad ID
readOnlyManager.getPadId(auth.padID, function(err, value) {
ERR(err);
securityManager.checkAccess(value, auth.sessionID, auth.token, auth.password, checkAccessCallback);
});
} else {
securityManager.checkAccess(auth.padID, auth.sessionID, auth.token, auth.password, checkAccessCallback);
} }
}, },
finalHandler finalHandler