Skip to content

Commit 6ef2f81

Browse files
Merge pull request #2447 from CanStudios/issue/2444
Display error information on plugin upload modal
2 parents d3bd586 + 972a4c8 commit 6ef2f81

4 files changed

Lines changed: 20 additions & 17 deletions

File tree

frontend/src/core/helpers.js

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -172,12 +172,6 @@ define(function(require){
172172
return new Handlebars.SafeString(html + '</ul>');
173173
},
174174

175-
decodeHTML: function(html) {
176-
var el = document.createElement('div');
177-
el.innerHTML = html;
178-
return el.childNodes.length === 0 ? "" : el.childNodes[0].nodeValue;
179-
},
180-
181175
ifHasPermissions: function(permissions, block) {
182176
var hasPermission = Origin.permissions.hasPermissions(permissions.split(','));
183177
return hasPermission ? block.fn(this) : block.inverse(this);

frontend/src/modules/pluginManagement/views/pluginManagementUploadView.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ define(function(require){
6161
Origin.Notify.alert({
6262
type: 'error',
6363
title: Origin.l10n.t('app.uploadpluginerror'),
64-
text: Helpers.decodeHTML(message)
64+
text: message
6565
});
6666
Origin.router.navigateTo('pluginManagement/upload');
6767
},

plugins/content/bower/index.js

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -813,7 +813,7 @@ function addPackage (plugin, packageInfo, options, cb) {
813813
if (results && 0 !== results.length) {
814814
// don't add duplicate
815815
if (options.strict) {
816-
return addCb(new PluginPackageError("Can't add plugin: plugin already exists!"));
816+
return addCb(new PluginPackageError(app.polyglot.t('app.versionexists')));
817817
}
818818
return addCb(null);
819819
}
@@ -1058,7 +1058,7 @@ function handleUploadedPlugin (req, res, next) {
10581058

10591059
var file = files.file;
10601060
if (!file || !file.path) {
1061-
return next(new PluginPackageError('File upload failed!'));
1061+
return next(new PluginPackageError(app.polyglot.t('app.fileuploaderror')));
10621062
}
10631063

10641064
// try unzipping
@@ -1104,17 +1104,19 @@ function handleUploadedPlugin (req, res, next) {
11041104

11051105
}, function(hasResults) {
11061106
if (!hasResults) {
1107-
return next(new PluginPackageError('Cannot find expected bower.json file in the plugin root, please check the structure of your zip file and try again.'));
1107+
return next(app.polyglot.t('app.cannotfindbower'));
11081108
}
11091109

11101110
if (!packageJson) {
1111-
return next(new PluginPackageError('Unrecognized plugin - a plugin should have a bower.json file'));
1111+
return next(app.polyglot.t('app.unrecognisedplugin'));
11121112
}
11131113

11141114
// extract the plugin type from the package
11151115
var pluginType = extractPluginType(packageJson);
11161116
if (!pluginType) {
1117-
return next(new PluginPackageError('Unrecognized plugin type for package ' + packageJson.name));
1117+
return next(new PluginPackageError(app.polyglot.t('app.unrecognisedpluginforpackage', {
1118+
package: packageJson.name
1119+
})));
11181120
}
11191121

11201122
// mark as a locally installed package
@@ -1132,7 +1134,9 @@ function handleUploadedPlugin (req, res, next) {
11321134
}
11331135
// Check if the framework has been defined on the plugin and that it's not compatible
11341136
if (packageInfo.pkgMeta.framework && !semver.satisfies(semver.clean(frameworkVersion), packageInfo.pkgMeta.framework, { includePrerelease: true })) {
1135-
return next(new PluginPackageError('This plugin is incompatible with version ' + frameworkVersion + ' of the Adapt framework'));
1137+
return next(new PluginPackageError(app.polyglot.t('app.incompatibleframework', {
1138+
framework: frameworkVersion
1139+
})));
11361140
}
11371141
app.contentmanager.getContentPlugin(pluginType, function (error, contentPlugin) {
11381142
if (error) {
@@ -1145,10 +1149,9 @@ function handleUploadedPlugin (req, res, next) {
11451149

11461150
function sendResponse() {
11471151
res.statusCode = 200;
1148-
return res.json({
1149-
success: true,
1150-
pluginType: pluginType,
1151-
message: 'successfully added new plugin'
1152+
return res.json({
1153+
success: true,
1154+
pluginType: pluginType
11521155
});
11531156
}
11541157

routes/lang/en-application.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,5 +410,11 @@
410410
"app.searchByMail": "Search by email",
411411
"app.maxfileuploadsize": "Maximum upload file size: %{size}.",
412412
"app.uploadsizeerror": "File size limit exceeded. Expected no more than %{max}, received %{size}.",
413+
"app.fileuploaderror": "File upload failed.",
414+
"app.cannotfindbower": "Cannot find expected bower.json file in the plugin root, please check the structure of your zip file and try again.",
415+
"app.unrecognisedplugin": "Unrecognised plugin - a plugin should have a bower.json file.",
416+
"app.unrecognisedpluginforpackage": "Unrecognised plugin type for package %{package}.",
417+
"app.incompatibleframework": "This plugin is incompatible with version %{framework} of the Adapt framework.",
418+
"app.versionexists": "You already have this version of the plugin installed.",
413419
"app.unknownuser": "Unknown User"
414420
}

0 commit comments

Comments
 (0)