diff --git a/src/Umbraco.Core/Services/SectionService.cs b/src/Umbraco.Core/Services/SectionService.cs index 0196f2d742..33af4f06e4 100644 --- a/src/Umbraco.Core/Services/SectionService.cs +++ b/src/Umbraco.Core/Services/SectionService.cs @@ -16,24 +16,19 @@ namespace Umbraco.Core.Services { internal class SectionService { - private readonly IDatabaseUnitOfWorkProvider _uowProvider; - private readonly RepositoryFactory _repositoryFactory; - private readonly EntityService _entityService; + private readonly IUserService _userService; private readonly ApplicationTreeService _applicationTreeService; private readonly CacheHelper _cache; public SectionService( - IDatabaseUnitOfWorkProvider uowProvider, - RepositoryFactory repositoryFactory, - EntityService entityService, + IUserService userService, ApplicationTreeService applicationTreeService, CacheHelper cache) { if (applicationTreeService == null) throw new ArgumentNullException("applicationTreeService"); if (cache == null) throw new ArgumentNullException("cache"); - _uowProvider = uowProvider; - _repositoryFactory = repositoryFactory; - _entityService = entityService; + + _userService = userService; _applicationTreeService = applicationTreeService; _cache = cache; } @@ -129,27 +124,14 @@ namespace Umbraco.Core.Services /// public IEnumerable
GetAllowedSections(int userId) { - var allApps = GetSections(); - var apps = new List
(); + + var user = _userService.GetUserById(userId); + if (user == null) + { + throw new InvalidOperationException("No user found with id " + userId); + } - //TODO: Sort this out - - //using (var repository = _repositoryFactory.CreateUserSectionRepository(_uowProvider.GetUnitOfWork())) - //{ - // return repository.Get(id); - //} - - //using (IRecordsReader appIcons = SqlHelper.ExecuteReader("select app from umbracoUser2app where [user] = @userID", SqlHelper.CreateParameter("@userID", this.Id))) - //{ - // while (appIcons.Read()) - // { - // var app = allApps.SingleOrDefault(x => x.alias == appIcons.GetString("app")); - // if (app != null) - // apps.Add(app); - // } - //} - - return apps; + return GetSections().Where(x => user.AllowedSections.Contains(x.Alias)); } /// diff --git a/src/Umbraco.Core/Services/ServiceContext.cs b/src/Umbraco.Core/Services/ServiceContext.cs index 38e4e075d3..9034e2d36d 100644 --- a/src/Umbraco.Core/Services/ServiceContext.cs +++ b/src/Umbraco.Core/Services/ServiceContext.cs @@ -94,7 +94,7 @@ namespace Umbraco.Core.Services _treeService = new Lazy(() => new ApplicationTreeService(cache)); if (_sectionService == null) - _sectionService = new Lazy(() => new SectionService(provider, repositoryFactory.Value, _entityService.Value, _treeService.Value, cache)); + _sectionService = new Lazy(() => new SectionService(_userService.Value, _treeService.Value, cache)); } /// diff --git a/src/Umbraco.Web/Editors/SectionController.cs b/src/Umbraco.Web/Editors/SectionController.cs index e7102d8532..b25e0b2f41 100644 --- a/src/Umbraco.Web/Editors/SectionController.cs +++ b/src/Umbraco.Web/Editors/SectionController.cs @@ -16,7 +16,8 @@ namespace Umbraco.Web.Editors { public IEnumerable
GetSections() { - return Services.SectionService.GetSections().Select(Mapper.Map); + return Services.SectionService.GetAllowedSections(UmbracoUser.Id) + .Select(Mapper.Map); } } } \ No newline at end of file