Skip to content

Commit

Permalink
Merge pull request #1691 from adaptlearning/issue/1502
Browse files Browse the repository at this point in the history
Fixes #1502
  • Loading branch information
taylortom authored Aug 11, 2017
2 parents cc19a42 + e79b020 commit f55057d
Show file tree
Hide file tree
Showing 28 changed files with 1,388 additions and 1,511 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ before_install:
- mongod --version
- npm install -g adapt-cli
- adapt --version
- npm install -g grunt-cli

install:
- npm config set spin false
Expand Down
18 changes: 5 additions & 13 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,17 +201,10 @@ module.exports = function(grunt) {
files: ['./test_frontend/*.js', '!./test_frontend/login.js']
},
mochaTest: {
test: {
options: {
reporter: 'dot',
timeout: 3500,
require: ['should'],
ui: 'bdd',
globals: ['app']
},
src: [
'test/*.js'
]
src: ['test/*.js'],
options: {
reporter: 'spec',
timeout: 3500
}
},
open: {
Expand Down Expand Up @@ -357,7 +350,6 @@ module.exports = function(grunt) {
}
});

grunt.registerTask('test', ['mochaTest'/*, 'casperjs'*/]);
grunt.registerTask('default', ['merge-json', 'requireBundle', 'less:dev', 'handlebars', 'watch']);
grunt.registerTask('test', ['mochaTest']);
grunt.registerTask('test-ui', ['casperjs']);
};
44 changes: 0 additions & 44 deletions Makefile

This file was deleted.

14 changes: 2 additions & 12 deletions lib/filestorage.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,6 @@
// LICENCE https://github.com/adaptlearning/adapt_authoring/blob/master/LICENSE
/**
* Module depencies
*/

var path = require('path'),
fs = require('fs'),
logger = require('./logger'),
EventEmitter = require('events').EventEmitter,
util = require('util'),
pluginmanager = require('./pluginmanager'),
configuration = require('./configuration');

var logger = require('./logger')
var pluginmanager = require('./pluginmanager');
/*
* CONSTANTS
*/
Expand Down
10 changes: 10 additions & 0 deletions lib/logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,16 @@ Log.prototype.add = function(transport, options) {
}
};

/**
* Function to change transpots log level
*/
Log.prototype.level = function(type, level) {
if(!this.logger.transports.hasOwnProperty(type)) {
return console.log("Unknown transport type", type);
}
this.logger.transports[type].level = level;
};

/**
* A wrapper for winston's clear method (removes all transports)
*
Expand Down
1 change: 1 addition & 0 deletions lib/permissions.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ var ignoreRoutes = [
/^\/\/?$/,
/^\/install\/?.*$/,
/^\/api\/login\/?$/,
/^\/api\/loginas\/?$/,
/^\/api\/logout\/?$/,
/^\/api\/authcheck\/?$/,
/^\/api\/register\/?$/,
Expand Down
21 changes: 10 additions & 11 deletions lib/rolemanager.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,16 +164,14 @@ var RoleManager = {
var self = this;
database.getDatabase(function(err, db){
// confirm the role exists and is there is only one of them
self.retrieveRole({ _id: roleId }, function (error, results) {
self.retrieveRole({ _id: roleId }, function (error, result) {
if (error) {
return callback(error);
}

if (results && results.length === 1) {
return db.destroy('role', { _id: roleId }, callback);
if (!result) {
return callback(new Error('No matching role record found'));
}

return callback(new Error('No matching role record found'));
return db.destroy('role', { _id: result._id }, callback);
});
}, configuration.getConfig('dbName'));
},
Expand Down Expand Up @@ -559,12 +557,13 @@ function syncDefaultRoles (options, next) {
}

// Apply the latest version of the roles to the master tenant
db.update('role', {name: role.name}, { version: role.version, statement: role.statement }, function (err, rec) {
if (err || !rec) {
// Log error, but continue
logger.log('warn', '- ' + role.name + ' update failed!', err);
db.update('role', { name: role.name }, { version: role.version, statement: role.statement }, function (err, rec) {
if (err) {
logger.log('warn', '- ' + role.name + ' update failed', err);
}
if (!rec) {
logger.log('warn', '- ' + role.name + ' doesn\'t exist, cannot update', err);
}

return callback(err);
});
},
Expand Down
77 changes: 44 additions & 33 deletions lib/tenantmanager.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@
/**
* Tenant management module
*/

var util = require('util'),
database = require('./database'),
logger = require('./logger'),
fs = require('fs'),
path = require('path'),
ncp = require('ncp'),
mkdirp = require('mkdirp'),
frameworkhelper = require('./frameworkhelper'),
configuration = require('./configuration');
var async = require('async');
var fs = require('fs-extra');
var mkdirp = require('mkdirp');
var ncp = require('ncp');
var path = require('path');
var util = require('util');

var configuration = require('./configuration');
var database = require('./database');
var frameworkhelper = require('./frameworkhelper');
var logger = require('./logger');

// Constants
var MODNAME = 'tenantmanager';
Expand Down Expand Up @@ -442,12 +443,12 @@ exports = module.exports = {
}

// only execute if we have a single matching record
self.retrieveTenant(search, function (error, result) {
self.retrieveTenant(search, function (error, tenantRec) {
if (error) {
return callback(error);
}

if (result) {
if (tenantRec) {
if (!update.updatedAt) {
update.updatedAt = new Date();
}
Expand All @@ -458,12 +459,12 @@ exports = module.exports = {
}

// Re-fetch the tenant
self.retrieveTenant(search, function(error, result) {
self.retrieveTenant(search, function(error, tenantRec) {
if (error) {
return callback(error);
}

return callback(null, result);
return callback(null, tenantRec);
});

});
Expand All @@ -489,18 +490,15 @@ exports = module.exports = {
logger.log('error', err);
return callback(err);
}

// confirm the tenant exists and is there is only one of them
self.retrieveTenant({ _id: tenantId }, function (error, results) {
// confirm the tenant exists
self.retrieveTenant({ _id: tenantId }, function (error, tenantRec) {
if (error) {
return callback(error);
}

if (results && results.length === 1) {
return self.updateTenant({ '_id': results[0]._id }, { _isDeleted: true }, callback);
if (!result) {
return callback(new Error('No matching tenant record found'));
}

return callback(new Error('No matching tenant record found'));
return self.updateTenant({ '_id': tenantRec._id }, { _isDeleted: true }, callback);
});
}, configuration.getConfig('dbName'));
},
Expand All @@ -515,27 +513,40 @@ exports = module.exports = {

deleteTenant: function (tenant, callback) {
var self = this;
database.getDatabase(function(err, db){
database.getDatabase(function(err, db) {
if (err) {
logger.log('error', err);
return callback(err);
}

// confirm the tenant exists and is there is only one of them
self.retrieveTenant(tenant, function (error, result) {
// confirm the tenant exists
self.retrieveTenant(tenant, function (error, tenantRec) {
if (error) {
return callback(error);
}

if (result) {
return db.destroy('tenant', tenant, callback);
if (!tenantRec) {
return callback(new Error('No matching tenant record found'));
}

return callback(new Error('No matching tenant record found'));
async.parallel([
function cleanDB(done) {
db.destroy('tenant', tenant, done);
},
function removeTemp(done) {
self.deleteTenantFilesystem(tenantRec, done);
}
], callback);
});
}, configuration.getConfig('dbName'));
},

/**
* Removes the tenant's working folders
* @param {object} tenant - a fully defined tenant object
* @param {function} callback - function of the form function (error)
*/
deleteTenantFilesystem: function(tenant, callback) {
fs.remove(path.join(configuration.tempDir, tenant._id.toString()), callback);
},

/**
* returns the database object for a named tenant
*
Expand All @@ -544,7 +555,7 @@ exports = module.exports = {
*/
getDatabaseConfig: function (tenantId, next) {
// just fetch up the tenant from the master db
this.retrieveTenant({ _id: tenantId }, function (err, tenant) {
this.retrieveTenant({ _id: tenantId }, function (err, tenantRec) {
if (err) {
return next(err);
}
Expand All @@ -554,7 +565,7 @@ exports = module.exports = {
}

// if database is not defined, the caller is expected to deal with item
return next(null, tenant.database);
return next(null, tenantRec.database);
});
}
};
Loading

0 comments on commit f55057d

Please sign in to comment.