Skip to content

Commit

Permalink
Merge pull request #766 from adaptlearning/issue/736-2
Browse files Browse the repository at this point in the history
Resolves #736
  • Loading branch information
brian-learningpool committed Jul 24, 2015
2 parents d6014b3 + 1f8300e commit 0bd6c18
Show file tree
Hide file tree
Showing 5 changed files with 419 additions and 292 deletions.
1 change: 0 additions & 1 deletion frontend/src/core/project/views/projectDetailView.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ define(function(require) {
},
success: _.bind(function(model, response, options) {

Origin.trigger('editingOverlay:views:hide');
if (this.isNew) {
return Backbone.history.navigate('#/editor/' + response._id + '/menu', {trigger: true});
}
Expand Down
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
"email": ""
},
{
"name": "Rob Moore",
"email": ""
"name": "Rob Moore",
"email": ""
},
{
"name": "Ryan Adams",
Expand All @@ -46,7 +46,7 @@
},
{
"name": "Sven Laux",
"email": "[email protected]"
"email": "[email protected]"
},
{
"name": "Petra Nussdorfer",
Expand Down Expand Up @@ -86,10 +86,10 @@
"grunt-mocha-test": "~0.7.0",
"grunt-open": "~0.2.2",
"grunt-requirejs-bundle": "~0.0.7",
"matchdep": "~0.3.0",
"handlebars-form-helpers": "0.1.3",
"hbs": "2.4.0",
"json-schema-mapper": "0.0.2",
"matchdep": "~0.3.0",
"mime": "1.2.x",
"mkdirp": "0.3.5",
"moment": "^2.9.0",
Expand All @@ -103,7 +103,7 @@
"prompt": "0.2.14",
"request": "^2.53.0",
"rimraf": "~2.2.5",
"semver": "^2.3.1",
"semver": "^2.3.2",
"underscore": "~1.5.2",
"unzip": "0.1.8",
"validator": "3.3.0",
Expand Down
55 changes: 45 additions & 10 deletions plugins/content/bower/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ var origin = require('../../../'),
path = require('path'),
unzip = require('unzip'),
exec = require('child_process').exec,
IncomingForm = require('formidable').IncomingForm;
IncomingForm = require('formidable').IncomingForm,
version = require('../../../version.json');

// errors
function PluginPackageError (msg) {
Expand Down Expand Up @@ -166,6 +167,7 @@ function extractPackageInfo (plugin, pkgMeta, schema) {
displayName: pkgMeta.displayName,
description: pkgMeta.description,
version: pkgMeta.version,
framework: pkgMeta.framework ? pkgMeta.framework : null,
isLocalPackage: pkgMeta.isLocalPackage ? pkgMeta.isLocalPackage : false,
properties: schema.properties
};
Expand Down Expand Up @@ -269,7 +271,9 @@ BowerPlugin.prototype.initialize = function (plugin) {
if (err) {
return next(err);
}
return next(null,results)

res.statusCode = 200;
return res.json(results);
});
}

Expand Down Expand Up @@ -460,6 +464,7 @@ BowerPlugin.prototype.fetchInstalledPackages = function (plugin, options, next)
},
function (err) {
if (err) {
logger.log('error', err);
return next(err);
}

Expand Down Expand Up @@ -562,19 +567,19 @@ function addPackage (plugin, packageInfo, options, cb) {
rimraf(destination, function(err) {
if (err) {
// can't continue
return logger.log('error', err.message, err);
return logger.log('error', err);
}

mkdirp(destination, function (err) {
if (err) {
return logger.log('error', err.message, err);
return logger.log('error', err);
}

// move from the cache to the versioned dir
ncp(packageInfo.canonicalDir, destination, function (err) {
if (err) {
// don't double call callback
return logger.log('error', err.message, err);
return logger.log('error', err);
}

// temporary hack to get stuff moving
Expand All @@ -595,12 +600,12 @@ function addPackage (plugin, packageInfo, options, cb) {
// remove older version first
rimraf(tenantPluginPath, function (err) {
if (err) {
return logger.log('error', err.message, err);
return logger.log('error', err);
}

ncp(packageInfo.canonicalDir, tenantPluginPath, function (err) {
if (err) {
return logger.log('error', err.message, err);
return logger.log('error', err);
}

// done
Expand All @@ -617,12 +622,14 @@ function addPackage (plugin, packageInfo, options, cb) {
// add the package to the modelname collection
database.getDatabase(function (err, db) {
if (err) {
logger.log('error', err);
return cb(err);
}

// don't duplicate component.name, component.version
db.retrieve(plugin.type, { name: package.name, version: package.version }, function (err, results) {
if (err) {
logger.log('error', err);
return cb(err);
}

Expand Down Expand Up @@ -761,8 +768,18 @@ BowerPlugin.prototype.updatePackages = function (plugin, options, cb) {
// add details for each to the db
async.eachSeries(
Object.keys(packageInfo),
function (key, next) {
addPackage(plugin, packageInfo[key], options, next);
function (key, next) {
if (packageInfo[key].pkgMeta.framework) {
// If the plugin defines a framework, ensure that it is compatible
if (semver.satisfies(semver.clean(version.adapt_framework), packageInfo[key].framework)) {
addPackage(plugin, packageInfo[key], options, next);
} else {
logger.log('warn', 'Unable to install ' + packageInfo[key].pkgMeta.name + ' as it is not supported in the current version of of the Adapt framework');
next();
}
} else {
addPackage(plugin, packageInfo[key], options, next);
}
},
cb);
});
Expand Down Expand Up @@ -797,7 +814,19 @@ function checkIfHigherVersionExists (package, options, cb) {
if (Object.getOwnPropertyNames(info).length == 0 || !info[packageName].pkgMeta) {
return cb(null, false);
}
return cb(null, true);

// Semver check that the plugin is compatibile with the installed version of the framework
if (info[packageName].pkgMeta.framework) {
// Check which version of the framework we're running
if (semver.satisfies(semver.clean(version.adapt_framework), info[packageName].pkgMeta.framework)) {
return cb(null, true);
} else {
logger.log('warn', 'A later version of ' + packageName + ' is available but is not supported by the installed version of the Adapt framework');
return cb(null, false);
}
} else {
return cb(null, true);
}
});
}

Expand Down Expand Up @@ -882,6 +911,12 @@ function handleUploadedPlugin (req, res, next) {
canonicalDir: canonicalDir,
pkgMeta: packageJson
};

// Check if the framework has been defined on the plugin and that it's not compatible
if (packageInfo.pkgMeta.framework && !semver.satisfies(semver.clean(version.adapt_framework), packageInfo.pkgMeta.framework)) {
return next(new PluginPackageError('This plugin is incompatible with version ' + version.adapt_framework + ' of the Adapt framework'));
}

app.contentmanager.getContentPlugin(pluginType, function (error, contentPlugin) {
if (error) {
return next(error);
Expand Down
Loading

0 comments on commit 0bd6c18

Please sign in to comment.