From 813750b0a91f6650071efcf41bf2596f4bc8620c Mon Sep 17 00:00:00 2001 From: Shannon Date: Wed, 31 Jul 2013 19:14:02 +1000 Subject: [PATCH] Fixes merge issues --- .../TestHelpers/BaseDatabaseFactoryTest.cs | 40 ++++++++++------- src/Umbraco.Web/Editors/MediaController.cs | 45 +++++++++++++++++++ .../Mvc/UmbracoAuthorizeAttribute.cs | 2 +- src/Umbraco.Web/Umbraco.Web.csproj | 2 + .../WebApi/UmbracoApiController.cs | 7 --- .../WebApi/UmbracoAuthorizedApiController.cs | 2 - 6 files changed, 72 insertions(+), 26 deletions(-) diff --git a/src/Umbraco.Tests/TestHelpers/BaseDatabaseFactoryTest.cs b/src/Umbraco.Tests/TestHelpers/BaseDatabaseFactoryTest.cs index 163e0eba1c..7e453ca3c2 100644 --- a/src/Umbraco.Tests/TestHelpers/BaseDatabaseFactoryTest.cs +++ b/src/Umbraco.Tests/TestHelpers/BaseDatabaseFactoryTest.cs @@ -10,6 +10,7 @@ using System.Xml; using NUnit.Framework; using SQLCE4Umbraco; using Umbraco.Core; +using Umbraco.Core.Cache; using Umbraco.Core.Configuration; using Umbraco.Core.Logging; using Umbraco.Core.ObjectResolution; @@ -41,6 +42,7 @@ namespace Umbraco.Tests.TestHelpers private static volatile bool _firstRunInTestSession = true; private static readonly object Locker = new object(); private bool _firstTestInFixture = true; + private DefaultDatabaseFactory _dbFactory; //Used to flag if its the first test in the current session private bool _isFirstRunInTestSession = false; @@ -52,26 +54,16 @@ namespace Umbraco.Tests.TestHelpers { InitializeFirstRunFlags(); + _dbFactory = new DefaultDatabaseFactory( + GetDbConnectionString(), + GetDbProviderName()); + base.Initialize(); var path = TestHelper.CurrentAssemblyDirectory; AppDomain.CurrentDomain.SetData("DataDirectory", path); - var dbFactory = new DefaultDatabaseFactory( - GetDbConnectionString(), - GetDbProviderName()); - ApplicationContext.Current = new ApplicationContext( - //assign the db context - new DatabaseContext(dbFactory), - //assign the service context - new ServiceContext(new PetaPocoUnitOfWorkProvider(dbFactory), new FileUnitOfWorkProvider(), new PublishingStrategy()), - //disable cache - false) - { - IsReady = true - }; - - DatabaseContext.Initialize(dbFactory.ProviderName, dbFactory.ConnectionString); + DatabaseContext.Initialize(_dbFactory.ProviderName, _dbFactory.ConnectionString); CreateSqlCeDatabase(); @@ -80,7 +72,23 @@ namespace Umbraco.Tests.TestHelpers //ensure the configuration matches the current version for tests SettingsForTests.ConfigurationStatus = UmbracoVersion.Current.ToString(3); } - + + protected override void SetupApplicationContext() + { + //disable cache + var cacheHelper = new CacheHelper(new NullCacheProvider(), false); + + ApplicationContext.Current = new ApplicationContext( + //assign the db context + new DatabaseContext(_dbFactory), + //assign the service context + new ServiceContext(new PetaPocoUnitOfWorkProvider(), new FileUnitOfWorkProvider(), new PublishingStrategy(), cacheHelper), + cacheHelper) + { + IsReady = true + }; + } + /// /// The database behavior to use for the test/fixture /// diff --git a/src/Umbraco.Web/Editors/MediaController.cs b/src/Umbraco.Web/Editors/MediaController.cs index 430867451a..093c2ee909 100644 --- a/src/Umbraco.Web/Editors/MediaController.cs +++ b/src/Umbraco.Web/Editors/MediaController.cs @@ -161,5 +161,50 @@ namespace Umbraco.Web.Editors return display; } + + /// + /// Change the sort order for media + /// + /// + /// + public HttpResponseMessage PostSort(ContentSortOrder sorted) + { + if (sorted == null) + { + return Request.CreateResponse(HttpStatusCode.NotFound); + } + + //if there's nothing to sort just return ok + if (sorted.IdSortOrder.Length == 0) + { + return Request.CreateResponse(HttpStatusCode.OK); + } + + if (!Security.UserHasAppAccess(global::Umbraco.Core.Constants.Applications.Media, UmbracoUser)) + { + return Request.CreateErrorResponse(HttpStatusCode.Unauthorized, "User has no access to this application"); + } + + var mediaService = base.ApplicationContext.Services.MediaService; + var sortedMedia = new List(); + try + { + sortedMedia.AddRange(sorted.IdSortOrder.Select(mediaService.GetById)); + + // Save Media with new sort order and update content xml in db accordingly + if (!mediaService.Sort(sortedMedia)) + { + LogHelper.Warn("Media sorting failed, this was probably caused by an event being cancelled"); + return Request.CreateErrorResponse(HttpStatusCode.Forbidden, "Media sorting failed, this was probably caused by an event being cancelled"); + } + return Request.CreateResponse(HttpStatusCode.OK); + } + catch (Exception ex) + { + LogHelper.Error("Could not update media sort order", ex); + throw; + } + } + } } diff --git a/src/Umbraco.Web/Mvc/UmbracoAuthorizeAttribute.cs b/src/Umbraco.Web/Mvc/UmbracoAuthorizeAttribute.cs index e9344d34da..adf4353cfb 100644 --- a/src/Umbraco.Web/Mvc/UmbracoAuthorizeAttribute.cs +++ b/src/Umbraco.Web/Mvc/UmbracoAuthorizeAttribute.cs @@ -57,8 +57,8 @@ namespace Umbraco.Web.Mvc //we need to that the app is configured and that a user is logged in if (!appContext.IsConfigured) return false; + var isLoggedIn = umbContext.Security.ValidateCurrentUser(); - var isLoggedIn = umbCtx.Security.ValidateUserContextId(umbCtx.Security.UmbracoUserContextId); return isLoggedIn; } catch (Exception) diff --git a/src/Umbraco.Web/Umbraco.Web.csproj b/src/Umbraco.Web/Umbraco.Web.csproj index 71466f443b..7f129e5922 100644 --- a/src/Umbraco.Web/Umbraco.Web.csproj +++ b/src/Umbraco.Web/Umbraco.Web.csproj @@ -296,6 +296,8 @@ + + diff --git a/src/Umbraco.Web/WebApi/UmbracoApiController.cs b/src/Umbraco.Web/WebApi/UmbracoApiController.cs index 0c35c5c406..457b106d45 100644 --- a/src/Umbraco.Web/WebApi/UmbracoApiController.cs +++ b/src/Umbraco.Web/WebApi/UmbracoApiController.cs @@ -99,12 +99,5 @@ namespace Umbraco.Web.WebApi /// internal Guid InstanceId { get; private set; } - /// - /// Returns the WebSecurity instance - /// - public WebSecurity Security - { - get { return UmbracoContext.Security; } - } } } \ No newline at end of file diff --git a/src/Umbraco.Web/WebApi/UmbracoAuthorizedApiController.cs b/src/Umbraco.Web/WebApi/UmbracoAuthorizedApiController.cs index 3bcda7e17c..d03c52e158 100644 --- a/src/Umbraco.Web/WebApi/UmbracoAuthorizedApiController.cs +++ b/src/Umbraco.Web/WebApi/UmbracoAuthorizedApiController.cs @@ -33,8 +33,6 @@ namespace Umbraco.Web.WebApi if (!_userisValidated) { Security.ValidateCurrentUser(true); - throw new InvalidOperationException("To get a current user, this method must occur in a web request"); - Security.ValidateCurrentUser(ctx.Result, true); _userisValidated = true; }