From c1721850eb50c5ec8a2625cff0a2f0a0f641fadb Mon Sep 17 00:00:00 2001 From: alvaro <alvaro@alia.(none)> Date: Tue, 16 Oct 2012 00:24:15 -0700 Subject: [PATCH] Improving creation/deletion of files --- classes/modules/adminModule.php | 16 +++++++---- .../static/admin/js/editor.js | 28 +++++++++++-------- 2 files changed, 26 insertions(+), 18 deletions(-) diff --git a/classes/modules/adminModule.php b/classes/modules/adminModule.php index 111dee0d..af03ffc9 100644 --- a/classes/modules/adminModule.php +++ b/classes/modules/adminModule.php @@ -730,15 +730,19 @@ class AdminModule extends abstractModule{ exit(0); } $return_var = 0; - exec ("rm ".$path, &$output, $return_var); - if($return_var !== 0){ - echo json_encode(array('success' => false, path => $path)); + if(strpos($path, "components") === 0 && strpos($path, '..') === FALSE){ + exec ("rm ".$path, &$output, $return_var); + if($return_var !== 0){ + echo json_encode(array('success' => false, path => $path)); + }else{ + echo json_encode(array('success' => true, path => $path)); + } }else{ - echo json_encode(array('success' => true, path => $path)); + HTTPStatus::send406(); + exit(0); } }else{ - HTTPStatus::send406(); - exit(0); + echo json_encode(array('success' => false, path => $path)); } } diff --git a/doc/examples/originalComponents/static/admin/js/editor.js b/doc/examples/originalComponents/static/admin/js/editor.js index b4b52f41..6de85c63 100644 --- a/doc/examples/originalComponents/static/admin/js/editor.js +++ b/doc/examples/originalComponents/static/admin/js/editor.js @@ -94,18 +94,22 @@ $(document).ready(function(){ var fileName = ""; if($(this).hasClass("new-file-button-view")){ fileName = prompt("Please enter the name of the new view","json.template"); - fileName = /\w+\.template$/g.exec(fileName); + if(! /[^\/\s]+\.template$/g.test(fileName)){ + alert("File name is not valid. It has to end with a .template"); + return; + } }else{ fileName = prompt("Please enter the name of the new model","newModel.query"); - fileName = /\w+\.query$/g.exec(fileName); + if(! /^(endpoint\.[^\/\s]+\/)*[^\/\s]+\.query$/.test(fileName)){ + alert("File name is not valid. Format is [endpoint.ENDPOINTPREFIX/]*FILENAME.query"); + return; + } } if(fileName != null){ var url = "components/add/"+$(this).attr("data-component")+"/"+fileName; var data = {content: $("#template-editor").val()}; var msgId = "#component-msg"; executePost(url, data, {id:msgId, success: "Saved!", failure: "Can't create new file. Probably permissions problem or file already exists", error: "Error creating a new file!"}); - }else{ - alert("File name is not valid. It has to end with a .query for models and with .template for views"); } }); @@ -145,10 +149,10 @@ $(document).ready(function(){ $.each(data.models, function(i, item){ var modelUrl = relPos+componentType+"/"+componentName+"/queries/"+item; var modelFileUrl = componentType+"/"+componentName+"/queries/"+item; - $("#query-list").append("<li class='file-li'><button type='button' class='close hide lodspk-delete-file' data-parent='"+dataParent+"' data-file='"+modelFileUrl+"' style='align:left'>x</button><a href='#query-save-button' class='lodspk-query' data-url='"+modelUrl+"'>"+item+"</a></li>"); + $("#query-list").append("<li class='file-li'><button type='button' class='close hide lodspk-delete-file' data-parent='"+dataParent+"' data-file='"+modelFileUrl+"' style='align:left'>x</button><a href='#' class='lodspk-query' data-url='"+modelUrl+"'>"+item+"</a></li>"); $('html, body').stop().animate({ - scrollTop: $('#query-list').offset().top - }, 100); + scrollTop: $('#template-list').offset().top - 100 + }, 500); }); updateEvents(); $(".new-file-button").removeClass("hide"); @@ -223,8 +227,8 @@ $(document).ready(function(){ templateBuffer = data; $("#template-save-button").attr("data-url", fileUrl).addClass("disabled"); $('html, body').stop().animate({ - scrollTop: $('body').offset().top - }, 100); + scrollTop: $('body').offset().top-100 + }, 500); } }); }); @@ -239,9 +243,9 @@ $(document).ready(function(){ queryEditor.setValue(data); queryBuffer = data; $("#query-save-button").attr("data-url", fileUrl).addClass("disabled"); - $('#query-editor').stop().animate({ - scrollTop: $('body').offset().top - }, 100); + $('html, body').stop().animate({ + scrollTop: $('.bs-docs-query').offset().top-100 + }, 1000); } }); }); -- GitLab