Skip to content

Commit

Permalink
server-node: Moved http arg in storage as the first
Browse files Browse the repository at this point in the history
  • Loading branch information
andersevenrud committed Nov 19, 2016
1 parent 94eb583 commit 9cb2626
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 27 deletions.
4 changes: 2 additions & 2 deletions src/server/node/core/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ module.exports.checkPermission = function(http, type, options) {
function checkPackagePermission(userGroups) {
return new Promise(function(resolve, reject) {
if ( type === 'package' ) {
_instance.getStorage().getBlacklist(username, http).then(function(blacklist) {
_instance.getStorage().getBlacklist(http, username).then(function(blacklist) {
if ( blacklist && blacklist.indexOf(options.path) !== -1 ) {
reject('Access Denied!');
} else {
Expand All @@ -158,7 +158,7 @@ module.exports.checkPermission = function(http, type, options) {
}

if ( checkGroups ) {
_instance.getStorage().getGroups(username, http).then(function(userGroups) {
_instance.getStorage().getGroups(http, username).then(function(userGroups) {
checkApiPermission(userGroups).then(function() {
checkMountPermission(userGroups).then(function() {
checkPackagePermission(userGroups).then(resolve).catch(reject);
Expand Down
2 changes: 1 addition & 1 deletion src/server/node/core/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ function createServer(env, resolve, reject) {
uploadDir: config.tmpdir
});

eorm.parse(request, function(err, fields, files) {
form.parse(request, function(err, fields, files) {
handleRequest(createHttpObject(request, response, path, fields, respond, session_id, files));
});
}
Expand Down
6 changes: 3 additions & 3 deletions src/server/node/modules/api/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ module.exports.login = function(http, data) {
function _proceed(userData) {
http.session.set('username', userData.username);

_instance.getStorage().getSettings(userData.username, http).then(function(userSettings) {
_instance.getStorage().getBlacklist(userData.username, http).then(function(blacklist) {
_instance.getStorage().getSettings(http, userData.username).then(function(userSettings) {
_instance.getStorage().getBlacklist(http, userData.username).then(function(blacklist) {
http.session.set('username', userData.username);

resolve({
Expand All @@ -71,7 +71,7 @@ module.exports.login = function(http, data) {

_instance.getAuth().login(http, data).then(function(userData) {
if ( typeof userData.groups === 'undefined' ) {
_instance.getStorage().getGroups(userData.username, http).then(function(groups) {
_instance.getStorage().getGroups(http, userData.username).then(function(groups) {
userData.groups = groups;
_proceed(userData);
}).catch(_fail);
Expand Down
2 changes: 1 addition & 1 deletion src/server/node/modules/api/storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,5 @@ const _instance = require('./../../core/instance.js');
module.exports.settings = function(http, data) {
const username = http.session.get('username');
const settings = data.settings;
return _instance.getStorage().setSettings(username, settings, http);
return _instance.getStorage().setSettings(http, username, settings);
};
10 changes: 5 additions & 5 deletions src/server/node/modules/storage/demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,31 +30,31 @@
/*eslint strict:["error", "global"]*/
'use strict';

module.exports.setSettings = function(username, data, http) {
module.exports.setSettings = function(http, username, data) {
return new Promise(function(resolve) {
resolve(true);
});
};

module.exports.getSettings = function(username, http) {
module.exports.getSettings = function(http, username) {
return new Promise(function(resolve) {
resolve({});
});
};

module.exports.getGroups = function(username, http) {
module.exports.getGroups = function(http, username) {
return new Promise(function(resolve) {
resolve(['admin']);
});
};

module.exports.getBlacklist = function(username, http) {
module.exports.getBlacklist = function(http, username) {
return new Promise(function(resolve) {
resolve([]);
});
};

module.exports.setBlacklist = function(username, list, http) {
module.exports.setBlacklist = function(http, username, list) {
return new Promise(function(resolve) {
resolve(true);
});
Expand Down
10 changes: 5 additions & 5 deletions src/server/node/modules/storage/mysql.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const _utils = require('./../../core/utils.js');

var pool;

module.exports.setSettings = function(username, settings) {
module.exports.setSettings = function(http, username, settings) {
return new Promise(function(resolve, reject) {
_utils.mysqlQuery(pool, 'UPDATE `users` SET `settings` = ? WHERE `username` = ? LIMIT 1;', [JSON.stringify(settings), username], function(err, row) {
if ( err ) {
Expand All @@ -47,7 +47,7 @@ module.exports.setSettings = function(username, settings) {
});
};

module.exports.getSettings = function(username) {
module.exports.getSettings = function(http, username) {
return new Promise(function(resolve, reject) {
_utils.mysqlQuery(pool, 'SELECT `settings` FROM `users` WHERE `username` = ? LIMIT 1;', [username], function(err, row) {
row = row || {};
Expand All @@ -64,7 +64,7 @@ module.exports.getSettings = function(username) {
});
};

module.exports.getGroups = function(username) {
module.exports.getGroups = function(http, username) {
return new Promise(function(resolve, reject) {
_utils.mysqlQuery(pool, 'SELECT `groups` FROM `users` WHERE `username` = ? LIMIT 1;', [username], function(err, row) {
row = row || {};
Expand All @@ -81,13 +81,13 @@ module.exports.getGroups = function(username) {
});
};

module.exports.getBlacklist = function(username) {
module.exports.getBlacklist = function(http, username) {
return new Promise(function(resolve) {
resolve([]);
});
};

module.exports.setBlacklist = function(username, list) {
module.exports.setBlacklist = function(http, username, list) {
return new Promise(function(resolve) {
resolve(true);
});
Expand Down
10 changes: 5 additions & 5 deletions src/server/node/modules/storage/system.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ function _readFile(username, path, resolve) {
});
}

module.exports.setSettings = function(username, settings) {
module.exports.setSettings = function(http, username, settings) {
const config = _instance.getConfig();
const path = _vfs.resolvePathArguments(config.modules.storage.system.settings, {
username: username
Expand All @@ -66,7 +66,7 @@ module.exports.setSettings = function(username, settings) {
});
};

module.exports.getSettings = function(username) {
module.exports.getSettings = function(http, username) {
const config = _instance.getConfig();
const path = _vfs.resolvePathArguments(config.modules.storage.system.settings, {
username: username
Expand All @@ -76,23 +76,23 @@ module.exports.getSettings = function(username) {
});
};

module.exports.getGroups = function(username) {
module.exports.getGroups = function(http, username) {
const config = _instance.getConfig();
const path = config.modules.storage.system.groups;
return new Promise(function(resolve) {
_readFile(username, path, resolve);
});
};

module.exports.getBlacklist = function(username) {
module.exports.getBlacklist = function(http, username) {
const config = _instance.getConfig();
const path = config.modules.storage.system.blacklist;
return new Promise(function(resolve) {
_readFile(username, path, resolve);
});
};

module.exports.setBlacklist = function(username, list) {
module.exports.setBlacklist = function(http, username, list) {
return new Promise(function(resolve) {
resolve(true);
});
Expand Down
10 changes: 5 additions & 5 deletions src/server/node/modules/storage/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,19 @@
/*eslint strict:["error", "global"]*/
'use strict';

module.exports.setSettings = function(username, data) {
module.exports.setSettings = function(http, username, data) {
return new Promise(function(resolve) {
resolve(true);
});
};

module.exports.getSettings = function(username) {
module.exports.getSettings = function(http, username) {
return new Promise(function(resolve) {
resolve({});
});
};

module.exports.getGroups = function(username) {
module.exports.getGroups = function(http, username) {
return new Promise(function(resolve) {
var groups = ({
normal: ['admin'],
Expand All @@ -53,7 +53,7 @@ module.exports.getGroups = function(username) {
});
};

module.exports.getBlacklist = function(username) {
module.exports.getBlacklist = function(http, username) {
return new Promise(function(resolve) {
if ( username === 'restricted' ) {
resolve(['default/CoreWM']);
Expand All @@ -63,7 +63,7 @@ module.exports.getBlacklist = function(username) {
});
};

module.exports.setBlacklist = function(username, list) {
module.exports.setBlacklist = function(http, username, list) {
return new Promise(function(resolve) {
resolve(true);
});
Expand Down

0 comments on commit 9cb2626

Please sign in to comment.