From 617d7dcea11b09d3dc8ce81457d17841b7e3d140 Mon Sep 17 00:00:00 2001 From: Shannon Date: Wed, 23 Oct 2013 13:02:39 +1100 Subject: [PATCH] Completes: U4-2656 Put in upgrade checker functionality like we have in v6 --- .../Editors/UpdateCheckController.cs | 49 +++++++++++++------ 1 file changed, 35 insertions(+), 14 deletions(-) diff --git a/src/Umbraco.Web/Editors/UpdateCheckController.cs b/src/Umbraco.Web/Editors/UpdateCheckController.cs index 3cae1f55a0..b569458d97 100644 --- a/src/Umbraco.Web/Editors/UpdateCheckController.cs +++ b/src/Umbraco.Web/Editors/UpdateCheckController.cs @@ -1,10 +1,11 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Net.Http; +using System.Net.Http.Headers; using System.Text; using System.Threading.Tasks; -using System.Web.Mvc; - +using System.Web.Http.Filters; using Umbraco.Core.Configuration; using Umbraco.Web.Models; @@ -12,26 +13,46 @@ namespace Umbraco.Web.Editors { public class UpdateCheckController : UmbracoAuthorizedJsonController { - [HttpGet] + [UpdateCheckResponseFilter] public UpgradeCheckResponse GetCheck() { - //PP: The statehelper is obsolete, but there are NO directions on what to use instead, so keeping it here... - var updChkCookie = new global::umbraco.BusinessLogic.StateHelper.Cookies.Cookie("UMB_UPDCHK", GlobalSettings.VersionCheckPeriod); - string updateCheckCookie = updChkCookie.HasValue ? updChkCookie.GetValue() : ""; - - if (GlobalSettings.VersionCheckPeriod > 0 && String.IsNullOrEmpty(updateCheckCookie) && Security.CurrentUser.UserType.Alias == "admin") + var updChkCookie = Request.Headers.GetCookies("UMB_UPDCHK").FirstOrDefault(); + var updateCheckCookie = updChkCookie != null ? updChkCookie["UMB_UPDCHK"].Value : ""; + if (GlobalSettings.VersionCheckPeriod > 0 && string.IsNullOrEmpty(updateCheckCookie) && Security.CurrentUser.UserType.Alias == "admin") { - updChkCookie.SetValue("1"); - var check = new global::umbraco.presentation.org.umbraco.update.CheckForUpgrade(); var result = check.CheckUpgrade(UmbracoVersion.Current.Major, - UmbracoVersion.Current.Minor, - UmbracoVersion.Current.Build, - UmbracoVersion.CurrentComment); + UmbracoVersion.Current.Minor, + UmbracoVersion.Current.Build, + UmbracoVersion.CurrentComment); + return new UpgradeCheckResponse(result.UpgradeType.ToString(), result.Comment, result.UpgradeUrl); } - return null; } + + /// + /// Adds the cookie response if it was successful + /// + /// + /// A filter is required because we are returning an object from the get method and not an HttpResponseMessage + /// + internal class UpdateCheckResponseFilter : ActionFilterAttribute + { + public override void OnActionExecuted(HttpActionExecutedContext context) + { + var objectContent = context.Response.Content as ObjectContent; + if (objectContent == null || objectContent.Value == null) return; + + //there is a result, set the outgoing cookie + var cookie = new CookieHeaderValue("UMB_UPDCHK", "1") + { + Expires = DateTimeOffset.Now.AddDays(GlobalSettings.VersionCheckPeriod), + HttpOnly = true, + Secure = GlobalSettings.UseSSL + }; + context.Response.Headers.AddCookies(new[] { cookie }); + } + } } }