From 3b71a6c3a5e68d0fc31e036dbd3c153d5aafa4f0 Mon Sep 17 00:00:00 2001 From: Shannon Date: Thu, 27 Feb 2014 10:16:30 +0100 Subject: [PATCH] asfsafd --- .../Install/Controllers/InstallController.cs | 10 ++ .../Install/HttpInstallAuthorizeAttribute.cs | 12 +- .../Install/InstallAuthorizeAttribute.cs | 7 +- src/Umbraco.Web/Install/InstallHelper.cs | 114 ++++++++---------- .../InstallSteps/StarterKitCleanupStep.cs | 9 ++ .../InstallSteps/StarterKitDownloadStep.cs | 9 ++ .../InstallSteps/StarterKitInstallStep.cs | 6 +- .../Install/InstallSteps/UserStep.cs | 8 +- .../Install/Models/InstallStatus.cs | 8 +- 9 files changed, 102 insertions(+), 81 deletions(-) diff --git a/src/Umbraco.Web/Install/Controllers/InstallController.cs b/src/Umbraco.Web/Install/Controllers/InstallController.cs index 12b02c72bf..a4520c4c4e 100644 --- a/src/Umbraco.Web/Install/Controllers/InstallController.cs +++ b/src/Umbraco.Web/Install/Controllers/InstallController.cs @@ -35,6 +35,16 @@ namespace Umbraco.Web.Install.Controllers // It's not considered an upgrade if the ConfigurationStatus is missing or empty. if (string.IsNullOrWhiteSpace(GlobalSettings.ConfigurationStatus) == false) { + Version current; + if (Version.TryParse(GlobalSettings.ConfigurationStatus, out current)) + { + //check if we are on the current version, and not let the installer execute + if (current == UmbracoVersion.Current) + { + return Redirect(SystemDirectories.Umbraco.EnsureEndsWith('/')); + } + } + var result = _umbracoContext.Security.ValidateCurrentUser(false); switch (result) diff --git a/src/Umbraco.Web/Install/HttpInstallAuthorizeAttribute.cs b/src/Umbraco.Web/Install/HttpInstallAuthorizeAttribute.cs index 504d50ad4d..bab2bddc40 100644 --- a/src/Umbraco.Web/Install/HttpInstallAuthorizeAttribute.cs +++ b/src/Umbraco.Web/Install/HttpInstallAuthorizeAttribute.cs @@ -65,16 +65,6 @@ namespace Umbraco.Web.Install return false; } } - - ///// - ///// Override to throw exception instead of returning 401 result - ///// - ///// - //protected override void HandleUnauthorizedRequest(AuthorizationContext filterContext) - //{ - // //they aren't authorized but the app has installed - // throw new HttpException((int)global::System.Net.HttpStatusCode.Unauthorized, "You must login to view this resource."); - //} - + } } \ No newline at end of file diff --git a/src/Umbraco.Web/Install/InstallAuthorizeAttribute.cs b/src/Umbraco.Web/Install/InstallAuthorizeAttribute.cs index 93bbd530f0..ecaf2d6be1 100644 --- a/src/Umbraco.Web/Install/InstallAuthorizeAttribute.cs +++ b/src/Umbraco.Web/Install/InstallAuthorizeAttribute.cs @@ -2,6 +2,8 @@ using System.Web; using System.Web.Mvc; using Umbraco.Core; +using Umbraco.Core.Configuration; +using Umbraco.Core.IO; using Umbraco.Web.Security; using umbraco.BasePages; @@ -74,13 +76,12 @@ namespace Umbraco.Web.Install } /// - /// Override to throw exception instead of returning 401 result + /// Override to redirect instead of throwing an exception /// /// protected override void HandleUnauthorizedRequest(AuthorizationContext filterContext) { - //they aren't authorized but the app has installed - throw new HttpException((int)global::System.Net.HttpStatusCode.Unauthorized, "You must login to view this resource."); + filterContext.Result = new RedirectResult(SystemDirectories.Umbraco.EnsureEndsWith('/')); } } diff --git a/src/Umbraco.Web/Install/InstallHelper.cs b/src/Umbraco.Web/Install/InstallHelper.cs index 2e95ca5783..d1885818b3 100644 --- a/src/Umbraco.Web/Install/InstallHelper.cs +++ b/src/Umbraco.Web/Install/InstallHelper.cs @@ -19,72 +19,64 @@ namespace Umbraco.Web.Install { //TODO: Add UserToken step to save our user token with Mother - var steps = new List(); - if (status == InstallStatus.NewInstall) + var steps = new List(new InstallSetupStep[] { - //The step order returned here is how they will appear on the front-end - steps.AddRange(new InstallSetupStep[] + new FilePermissionsStep() { - new FilePermissionsStep() - { - ServerOrder = 0, - }, - new UserStep(umbracoContext.Application) - { - ServerOrder = 4, - }, - new DatabaseConfigureStep(umbracoContext.Application) - { - ServerOrder = 1, - }, - new DatabaseInstallStep(umbracoContext.Application) - { - ServerOrder = 2, - }, - new DatabaseUpgradeStep(umbracoContext.Application) - { - ServerOrder = 3, - }, - new StarterKitDownloadStep() - { - ServerOrder = 5, - }, - new StarterKitInstallStep(umbracoContext.Application, umbracoContext.HttpContext) - { - ServerOrder = 6, - }, - new StarterKitCleanupStep() - { - ServerOrder = 7, - }, - new SetUmbracoVersionStep(umbracoContext.Application, umbracoContext.HttpContext) { - ServerOrder = 8 - } - }); - return steps; - } - else - { - //TODO: Add steps for upgrades - } - return null; - } - - public static bool IsNewInstall - { - get - { - var databaseSettings = ConfigurationManager.ConnectionStrings[GlobalSettings.UmbracoConnectionName]; - if (databaseSettings != null && ( - databaseSettings.ConnectionString.Trim() == string.Empty - && databaseSettings.ProviderName.Trim() == string.Empty - && GlobalSettings.ConfigurationStatus == string.Empty)) + ServerOrder = 0, + }, + new UserStep(umbracoContext.Application, status) { - return true; + ServerOrder = 4, + }, + new DatabaseConfigureStep(umbracoContext.Application) + { + ServerOrder = 1, + }, + new DatabaseInstallStep(umbracoContext.Application) + { + ServerOrder = 2, + }, + new DatabaseUpgradeStep(umbracoContext.Application) + { + ServerOrder = 3, + }, + new StarterKitDownloadStep(status) + { + ServerOrder = 5, + }, + new StarterKitInstallStep(status, umbracoContext.Application, umbracoContext.HttpContext) + { + ServerOrder = 6, + }, + new StarterKitCleanupStep(status) + { + ServerOrder = 7, + }, + new SetUmbracoVersionStep(umbracoContext.Application, umbracoContext.HttpContext) + { + ServerOrder = 8 } + }); - return false; - } + return steps; } + + //public static bool IsNewInstall + //{ + // get + // { + // var databaseSettings = ConfigurationManager.ConnectionStrings[GlobalSettings.UmbracoConnectionName]; + // if (databaseSettings != null && ( + // databaseSettings.ConnectionString.Trim() == string.Empty + // && databaseSettings.ProviderName.Trim() == string.Empty + // && GlobalSettings.ConfigurationStatus == string.Empty)) + // { + // return true; + // } + + // return false; + // } + //} } } \ No newline at end of file diff --git a/src/Umbraco.Web/Install/InstallSteps/StarterKitCleanupStep.cs b/src/Umbraco.Web/Install/InstallSteps/StarterKitCleanupStep.cs index c220dbc702..9766fda371 100644 --- a/src/Umbraco.Web/Install/InstallSteps/StarterKitCleanupStep.cs +++ b/src/Umbraco.Web/Install/InstallSteps/StarterKitCleanupStep.cs @@ -10,8 +10,17 @@ namespace Umbraco.Web.Install.InstallSteps [InstallSetupStep("StarterKitCleanup", "")] internal class StarterKitCleanupStep : InstallSetupStep { + private readonly InstallStatus _status; + + public StarterKitCleanupStep(InstallStatus status) + { + _status = status; + } + public override IDictionary Execute(object model) { + if (_status != InstallStatus.NewInstall) return null; + var installSteps = InstallStatusTracker.GetStatus(); //this step relies on the preious one completed - because it has stored some information we need if (installSteps.Any(x => x.Key == "StarterKitDownload") == false) diff --git a/src/Umbraco.Web/Install/InstallSteps/StarterKitDownloadStep.cs b/src/Umbraco.Web/Install/InstallSteps/StarterKitDownloadStep.cs index 0db3a66905..58891e0992 100644 --- a/src/Umbraco.Web/Install/InstallSteps/StarterKitDownloadStep.cs +++ b/src/Umbraco.Web/Install/InstallSteps/StarterKitDownloadStep.cs @@ -9,10 +9,19 @@ namespace Umbraco.Web.Install.InstallSteps [InstallSetupStep("StarterKitDownload", "starterKit")] internal class StarterKitDownloadStep : InstallSetupStep { + private readonly InstallStatus _status; + + public StarterKitDownloadStep(InstallStatus status) + { + _status = status; + } + private const string RepoGuid = "65194810-1f85-11dd-bd0b-0800200c9a66"; public override IDictionary Execute(Guid starterKitId) { + if (_status != InstallStatus.NewInstall) return null; + var result = DownloadPackageFiles(starterKitId); return new Dictionary diff --git a/src/Umbraco.Web/Install/InstallSteps/StarterKitInstallStep.cs b/src/Umbraco.Web/Install/InstallSteps/StarterKitInstallStep.cs index 56aaae63cb..8deda42115 100644 --- a/src/Umbraco.Web/Install/InstallSteps/StarterKitInstallStep.cs +++ b/src/Umbraco.Web/Install/InstallSteps/StarterKitInstallStep.cs @@ -10,11 +10,13 @@ namespace Umbraco.Web.Install.InstallSteps [InstallSetupStep("StarterKitInstall", "")] internal class StarterKitInstallStep : InstallSetupStep { + private readonly InstallStatus _status; private readonly ApplicationContext _applicationContext; private readonly HttpContextBase _httContext; - public StarterKitInstallStep(ApplicationContext applicationContext, HttpContextBase httContext) + public StarterKitInstallStep(InstallStatus status, ApplicationContext applicationContext, HttpContextBase httContext) { + _status = status; _applicationContext = applicationContext; _httContext = httContext; } @@ -22,6 +24,8 @@ namespace Umbraco.Web.Install.InstallSteps public override IDictionary Execute(object model) { + if (_status != InstallStatus.NewInstall) return null; + var installSteps = InstallStatusTracker.GetStatus(); //this step relies on the preious one completed - because it has stored some information we need if (installSteps.Any(x => x.Key == "StarterKitDownload") == false) diff --git a/src/Umbraco.Web/Install/InstallSteps/UserStep.cs b/src/Umbraco.Web/Install/InstallSteps/UserStep.cs index 7cea722342..f63dd63a08 100644 --- a/src/Umbraco.Web/Install/InstallSteps/UserStep.cs +++ b/src/Umbraco.Web/Install/InstallSteps/UserStep.cs @@ -12,10 +12,12 @@ namespace Umbraco.Web.Install.InstallSteps internal class UserStep : InstallSetupStep { private readonly ApplicationContext _applicationContext; + private readonly InstallStatus _status; - public UserStep(ApplicationContext applicationContext) + public UserStep(ApplicationContext applicationContext, InstallStatus status) { _applicationContext = applicationContext; + _status = status; } private MembershipProvider CurrentProvider @@ -67,5 +69,9 @@ namespace Umbraco.Web.Install.InstallSteps return null; } + public override string View + { + get { return _status == InstallStatus.NewInstall ? base.View : string.Empty; } + } } } \ No newline at end of file diff --git a/src/Umbraco.Web/Install/Models/InstallStatus.cs b/src/Umbraco.Web/Install/Models/InstallStatus.cs index afc0b7be6e..4512c06da2 100644 --- a/src/Umbraco.Web/Install/Models/InstallStatus.cs +++ b/src/Umbraco.Web/Install/Models/InstallStatus.cs @@ -18,9 +18,9 @@ namespace Umbraco.Web.Install.Models /// UpgradeWithoutToken, - /// - /// Used if the user presses f5 and is in the middle of an install - /// - InProgress + ///// + ///// Used if the user presses f5 and is in the middle of an install + ///// + //InProgress } }