From a7ef9fd2abbf1ae928f2b213fdc64d8aeed3a9ef Mon Sep 17 00:00:00 2001
From: dilannm
Date: Tue, 28 Jan 2020 15:05:26 +0530
Subject: [PATCH 01/76] fixes for INTGW-923
---
.../src/main/publisher/jagg/jagg.jag | 13 +-
.../publisher/modules/documentation/add.jag | 2 +-
.../site/blocks/documentation/ajax/docs.jag | 4 +-
.../documentation/inline-editor/js/inline.js | 2 +-
.../templates/item-design/js/api-design.js | 30 +++-
.../item-implement/js/api-implementation.js | 2 +-
.../wso2/templates/item-manage/template.jag | 4 +-
.../wso2/templates/listing/template.jag | 132 +++++++++++-------
.../wso2/templates/overview/template.jag | 2 +-
.../main/store/modules/subscription/list.jag | 22 +++
.../store/modules/subscription/module.jag | 3 +
.../blocks/api/api-info/ajax/api-info.jag | 6 +-
.../blocks/api/recently-added/ajax/list.jag | 2 +-
.../ajax/application-list.jag | 4 +-
.../application/application-view/block.jag | 7 +-
.../site/blocks/billing/ajax/billing.jag | 2 +-
.../comment/comment-add/ajax/comment-add.jag | 4 +-
.../store/site/blocks/sdk/ajax/sdk-create.jag | 2 +-
.../ajax/subscription-remove.jag | 58 +-------
.../site/blocks/tag/tag-cloud/ajax/list.jag | 2 +-
.../site/blocks/user/login/ajax/login.jag | 2 +-
.../store/site/themes/wso2/js/applications.js | 38 ++---
.../js/cloud-enjoyhint-script-data.js | 2 +-
.../api/api-listing-all/template.jag | 78 +++++++----
.../application/application-edit/template.jag | 2 +-
.../wso2/templates/user/sign-up/template.jag | 2 +-
.../templates/user/user-info/template.jag | 2 +-
27 files changed, 245 insertions(+), 184 deletions(-)
diff --git a/components/jaggery-apps/publisher/src/main/publisher/jagg/jagg.jag b/components/jaggery-apps/publisher/src/main/publisher/jagg/jagg.jag
index 63d9ab479..2b18d7d1c 100644
--- a/components/jaggery-apps/publisher/src/main/publisher/jagg/jagg.jag
+++ b/components/jaggery-apps/publisher/src/main/publisher/jagg/jagg.jag
@@ -748,7 +748,13 @@ var getThemeFile = function (path) {
print({ error :true , message:msg.error.csrfError});
return false;
}
- }
+ }
+
+ var validateForScript = function (content) {
+ var startPattern = //g;
+ var endPattern = /<\script>/g;
+ return content.replace(startPattern, "<script >").replace(endPattern, "<\script>");
+ };
return {
setUser:setUser,
@@ -795,8 +801,9 @@ var getThemeFile = function (path) {
getSiteContext:getSiteContext,
setCSRFToken:setCSRFToken,
isCSRFTokenValid:isCSRFTokenValid,
- getAbsoluteReqUrl:getAbsoluteReqUrl
+ getAbsoluteReqUrl:getAbsoluteReqUrl,
+ validateForScript:validateForScript
};
}());
-%>
+%>
\ No newline at end of file
diff --git a/components/jaggery-apps/publisher/src/main/publisher/modules/documentation/add.jag b/components/jaggery-apps/publisher/src/main/publisher/modules/documentation/add.jag
index 672302c79..d8f2834d6 100644
--- a/components/jaggery-apps/publisher/src/main/publisher/modules/documentation/add.jag
+++ b/components/jaggery-apps/publisher/src/main/publisher/modules/documentation/add.jag
@@ -38,7 +38,7 @@ var addInlineContent = function (api, doc) {
var log = new Log(),
provider = jagg.module("manager").getAPIProviderObj();
try {
- provider.addInlineContent(api.provider, api.name, api.version, doc.name, doc.content);
+ provider.addInlineContent(api.provider, api.name, api.version, doc.name, jagg.validateForScript(doc.content));
if (log.isDebugEnabled()) {
log.debug("addInlineContent for : " + doc.name + "with the content : " + doc.content);
}
diff --git a/components/jaggery-apps/publisher/src/main/publisher/site/blocks/documentation/ajax/docs.jag b/components/jaggery-apps/publisher/src/main/publisher/site/blocks/documentation/ajax/docs.jag
index ef29121f3..d0e6cd192 100644
--- a/components/jaggery-apps/publisher/src/main/publisher/site/blocks/documentation/ajax/docs.jag
+++ b/components/jaggery-apps/publisher/src/main/publisher/site/blocks/documentation/ajax/docs.jag
@@ -1,5 +1,7 @@
<%
include("/jagg/jagg.jag");
+var encode = require('encode');
+encode = new encode.Encode();
if(jagg.isCSRFTokenValid())
(function () {
@@ -52,7 +54,7 @@ if(jagg.isCSRFTokenValid())
if (result.error === true) {
obj = {
error:true,
- message:result.message
+ message:encode.forHtml(result.message)
};
response.status = 500;
} else {
diff --git a/components/jaggery-apps/publisher/src/main/publisher/site/themes/wso2/templates/documentation/inline-editor/js/inline.js b/components/jaggery-apps/publisher/src/main/publisher/site/themes/wso2/templates/documentation/inline-editor/js/inline.js
index a43a9d941..c4c184e5a 100644
--- a/components/jaggery-apps/publisher/src/main/publisher/site/themes/wso2/templates/documentation/inline-editor/js/inline.js
+++ b/components/jaggery-apps/publisher/src/main/publisher/site/themes/wso2/templates/documentation/inline-editor/js/inline.js
@@ -13,7 +13,7 @@ $('#summernote').summernote({
var docName = json.doc.provider.docName;
var apiName = json.doc.provider.apiName;
var docContent = json.doc.provider.content;
- $('#apiDeatils').empty().html(' ' + docName + '
');
+ $('#apiDeatils').empty().html(' ' + encodeURIComponent(docName) + '
');
if(localStorage.getItem("doc_auto_save"+apiName+provider+version+docName+"draft") == null) {
$("#summernote").summernote("code", docContent);
}else{
diff --git a/components/jaggery-apps/publisher/src/main/publisher/site/themes/wso2/templates/item-design/js/api-design.js b/components/jaggery-apps/publisher/src/main/publisher/site/themes/wso2/templates/item-design/js/api-design.js
index 67d472ee1..47ee4c7a3 100644
--- a/components/jaggery-apps/publisher/src/main/publisher/site/themes/wso2/templates/item-design/js/api-design.js
+++ b/components/jaggery-apps/publisher/src/main/publisher/site/themes/wso2/templates/item-design/js/api-design.js
@@ -587,7 +587,7 @@ APIDesigner.prototype.init_controllers = function(){
for(var method in pathObj){
if(pathObj.hasOwnProperty(method)){
var methodObj = pathObj[method];
-
+
//If the scope is added to the resource, remove it.
if(methodObj['x-scope'] && methodObj['x-scope'] === scopeKeyToDelete){
methodObj['x-scope'] = "";
@@ -662,7 +662,7 @@ APIDesigner.prototype.init_controllers = function(){
}
if (result.isRoleExist == false) {
jagg.message({
- content : "Role '" + $("#scopeRoles").val() + "' Does not exist.",
+ content : "Role '" + encodeURIComponent($("#scopeRoles").val()) + "' Does not exist.",
type : "error"
});
return;
@@ -1330,11 +1330,29 @@ $(document).ready(function(){
if((m = json.exec(jsonFile.file_name)) !== null){
var data = JSON.parse(jsonFile.result); //swagger file content
}
- var designer = APIDesigner();
- designer.load_api_document(data);
- $('#import_swagger').buttonLoader('stop');
- $("#swaggerUpload").modal('hide');
+
+ jagg.post("/site/blocks/item-design/ajax/add.jag", {
+ action: "validateSwagger",
+ swaggerDefinition: jsonFile.result
+ }, function (result) {
+ if (result.error) {
+ jagg.message({
+ content: i18n.t("API swagger definition is invalid. Please re-import valid swagger definition"),
+ type: "error"
+ });
+ $('#import_swagger').buttonLoader('stop');
+ } else {
+ var designer = APIDesigner();
+ designer.load_api_document(data);
+ $('#import_swagger').buttonLoader('stop');
+ $("#swaggerUpload").modal('hide');
+ }
+ }, "json");
} catch (err){
+ jagg.message({
+ content:i18n.t("API swagger definition is invalid JSON. Please re-import valid swagger definition"),
+ type: "error"
+ });
$('#swagger_file_help').show();
$('#import_swagger').buttonLoader('stop');
$('#fileErrorMsgClose').on('click', function (e) {
diff --git a/components/jaggery-apps/publisher/src/main/publisher/site/themes/wso2/templates/item-implement/js/api-implementation.js b/components/jaggery-apps/publisher/src/main/publisher/site/themes/wso2/templates/item-implement/js/api-implementation.js
index 68998aec4..d0cfbdc30 100644
--- a/components/jaggery-apps/publisher/src/main/publisher/site/themes/wso2/templates/item-implement/js/api-implementation.js
+++ b/components/jaggery-apps/publisher/src/main/publisher/site/themes/wso2/templates/item-implement/js/api-implementation.js
@@ -118,7 +118,7 @@ $(document).ready(function(){
$('#'+thisID).buttonLoader('stop');
$( "body" ).trigger( "api_saved" );
if(!$("#hiddenGoToManage").val()){
- $("#apiSaved").attr("style", "display: block ; position: fixed; height: 50px; width: 90% ; top: 20px; left: 5%; padding: 0px; list-style-type: none; z-index:999999999; text-align: center; padding-top : 15px");
+ $('#apiSaved').show();
}
setTimeout("hideMsg()", 3000);
} else {
diff --git a/components/jaggery-apps/publisher/src/main/publisher/site/themes/wso2/templates/item-manage/template.jag b/components/jaggery-apps/publisher/src/main/publisher/site/themes/wso2/templates/item-manage/template.jag
index c30eb9fcd..c3de08254 100644
--- a/components/jaggery-apps/publisher/src/main/publisher/site/themes/wso2/templates/item-manage/template.jag
+++ b/components/jaggery-apps/publisher/src/main/publisher/site/themes/wso2/templates/item-manage/template.jag
@@ -1473,7 +1473,7 @@
$('#sandboxTps').val(null);
}
thisID=$(this).attr('id');
- $("#apiSaved").attr("style", "display: block ; position: fixed; height: 50px; width: 90% ; top: 20px; left: 5%; padding: 0px; list-style-type: none; z-index:999999999; text-align: center; padding-top : 15px");
+ $('#apiSaved').show();
setTimeout("hideMsg()", 3000);
});
@@ -1595,4 +1595,4 @@
}, '<%=i18n.localize("Field contains special characters")%>');
-<% }); %>
+<% }); %>
\ No newline at end of file
diff --git a/components/jaggery-apps/publisher/src/main/publisher/site/themes/wso2/templates/listing/template.jag b/components/jaggery-apps/publisher/src/main/publisher/site/themes/wso2/templates/listing/template.jag
index 607917e71..90cf8ad27 100644
--- a/components/jaggery-apps/publisher/src/main/publisher/site/themes/wso2/templates/listing/template.jag
+++ b/components/jaggery-apps/publisher/src/main/publisher/site/themes/wso2/templates/listing/template.jag
@@ -1,7 +1,7 @@
<% jagg.template("listing", function(inputs, outputs, jagg) { %>
-
-