2012-10-04 13:05:31 -02:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using System.Runtime.Serialization;
|
2012-10-04 11:44:31 -02:00
|
|
|
|
using Umbraco.Core.Configuration;
|
2013-09-13 18:11:20 +10:00
|
|
|
|
using Umbraco.Core.Configuration.UmbracoSettings;
|
2012-10-04 11:44:31 -02:00
|
|
|
|
using Umbraco.Core.IO;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Umbraco.Core.Models
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Represents a Script file
|
|
|
|
|
|
/// </summary>
|
2012-10-04 13:05:31 -02:00
|
|
|
|
[Serializable]
|
|
|
|
|
|
[DataContract(IsReference = true)]
|
2012-10-04 11:44:31 -02:00
|
|
|
|
public class Script : File
|
|
|
|
|
|
{
|
2013-09-16 15:52:59 +10:00
|
|
|
|
private readonly IContentSection _contentConfig;
|
2013-09-13 18:11:20 +10:00
|
|
|
|
|
|
|
|
|
|
public Script(string path)
|
2013-09-25 19:23:41 +10:00
|
|
|
|
: this(path, UmbracoConfig.For.UmbracoSettings().Content)
|
2013-09-13 18:11:20 +10:00
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2013-09-16 15:52:59 +10:00
|
|
|
|
public Script(string path, IContentSection contentConfig)
|
2013-09-13 18:11:20 +10:00
|
|
|
|
: base(path)
|
2012-10-04 11:44:31 -02:00
|
|
|
|
{
|
2013-09-16 15:52:59 +10:00
|
|
|
|
_contentConfig = contentConfig;
|
2012-10-04 11:44:31 -02:00
|
|
|
|
base.Path = path;
|
|
|
|
|
|
}
|
Updates PartialView & PartialViewMacros models/services/repositories, streamlines their operations, fixes up other underlying problems with the FileRepository, fixes tree syncing for partial views, partial view macros and scripts, fixes scripts being created in folders, allows partial views and partial view macros to be managed and created in folders, fixes FileUnitOfWork to use a queue, publicizes some internal test classes, fixes tree syncing when dealing with invariant case, adds correct validation to the create dialogs of scripts and partial views (and partial view macros)
2014-10-22 16:44:45 +10:00
|
|
|
|
|
2012-10-04 11:44:31 -02:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Boolean indicating whether the file could be validated
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <remarks>
|
|
|
|
|
|
/// The validation logic was previsouly placed in the codebehind of editScript.aspx,
|
|
|
|
|
|
/// but has been moved to the script file so the validation is central.
|
|
|
|
|
|
/// </remarks>
|
|
|
|
|
|
/// <returns>True if file is valid, otherwise false</returns>
|
Updates PartialView & PartialViewMacros models/services/repositories, streamlines their operations, fixes up other underlying problems with the FileRepository, fixes tree syncing for partial views, partial view macros and scripts, fixes scripts being created in folders, allows partial views and partial view macros to be managed and created in folders, fixes FileUnitOfWork to use a queue, publicizes some internal test classes, fixes tree syncing when dealing with invariant case, adds correct validation to the create dialogs of scripts and partial views (and partial view macros)
2014-10-22 16:44:45 +10:00
|
|
|
|
//TODO: This makes no sense to be here, any validation methods should be at the service level,
|
|
|
|
|
|
// when we move Scripts to truly use IFileSystem, then this validation logic doesn't work anymore
|
2012-10-04 11:44:31 -02:00
|
|
|
|
public override bool IsValid()
|
|
|
|
|
|
{
|
|
|
|
|
|
//NOTE Since a script file can be both JS, Razor Views, Razor Macros and Xslt
|
|
|
|
|
|
//it might be an idea to create validations for all 3 and divide the validation
|
|
|
|
|
|
//into 4 private methods.
|
|
|
|
|
|
//See codeEditorSave.asmx.cs for reference.
|
|
|
|
|
|
|
2013-09-16 15:52:59 +10:00
|
|
|
|
var exts = _contentConfig.ScriptFileTypes.ToList();
|
2012-10-09 08:12:03 -02:00
|
|
|
|
/*if (UmbracoSettings.DefaultRenderingEngine == RenderingEngine.Mvc)
|
2012-10-04 11:44:31 -02:00
|
|
|
|
{
|
|
|
|
|
|
exts.Add("cshtml");
|
|
|
|
|
|
exts.Add("vbhtml");
|
2012-10-09 08:12:03 -02:00
|
|
|
|
}*/
|
2012-10-04 11:44:31 -02:00
|
|
|
|
|
|
|
|
|
|
var dirs = SystemDirectories.Scripts;
|
2012-10-09 08:12:03 -02:00
|
|
|
|
/*if (UmbracoSettings.DefaultRenderingEngine == RenderingEngine.Mvc)
|
|
|
|
|
|
dirs += "," + SystemDirectories.MvcViews;*/
|
2012-10-04 11:44:31 -02:00
|
|
|
|
|
|
|
|
|
|
//Validate file
|
2013-02-06 13:25:27 -01:00
|
|
|
|
var validFile = IOHelper.VerifyEditPath(Path, dirs.Split(','));
|
2012-10-04 11:44:31 -02:00
|
|
|
|
|
|
|
|
|
|
//Validate extension
|
2013-02-06 13:25:27 -01:00
|
|
|
|
var validExtension = IOHelper.VerifyFileExtension(Path, exts);
|
2012-10-04 11:44:31 -02:00
|
|
|
|
|
|
|
|
|
|
return validFile && validExtension;
|
|
|
|
|
|
}
|
2013-01-29 12:16:13 -01:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Indicates whether the current entity has an identity, which in this case is a path/name.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <remarks>
|
|
|
|
|
|
/// Overrides the default Entity identity check.
|
|
|
|
|
|
/// </remarks>
|
|
|
|
|
|
public override bool HasIdentity
|
|
|
|
|
|
{
|
|
|
|
|
|
get { return string.IsNullOrEmpty(Path) == false; }
|
|
|
|
|
|
}
|
2012-10-04 11:44:31 -02:00
|
|
|
|
}
|
|
|
|
|
|
}
|