From f5c4aad270236f9d38def959476cb2cd9085acf2 Mon Sep 17 00:00:00 2001 From: Shannon Date: Fri, 9 Aug 2013 13:23:27 +1000 Subject: [PATCH] Added overload to User object to be created from an IUser object. Added GetUserSections to IUserService. --- src/Umbraco.Core/Services/IUserService.cs | 7 +++++++ src/Umbraco.Core/Services/UserService.cs | 16 ++++++++++++++++ src/umbraco.businesslogic/User.cs | 18 ++++++++++++++++++ 3 files changed, 41 insertions(+) diff --git a/src/Umbraco.Core/Services/IUserService.cs b/src/Umbraco.Core/Services/IUserService.cs index 8549699c53..3c37ad0e22 100644 --- a/src/Umbraco.Core/Services/IUserService.cs +++ b/src/Umbraco.Core/Services/IUserService.cs @@ -1,3 +1,4 @@ +using System.Collections.Generic; using System.Web; using Umbraco.Core.Models.Membership; @@ -44,5 +45,11 @@ namespace Umbraco.Core.Services /// /// void DeleteSectionFromAllUsers(string sectionAlias); + + /// + /// Returns a list of the sections that the user is allowed access to + /// + /// + IEnumerable GetUserSections(IUser user); } } \ No newline at end of file diff --git a/src/Umbraco.Core/Services/UserService.cs b/src/Umbraco.Core/Services/UserService.cs index e451d3aa05..fe3c0a367e 100644 --- a/src/Umbraco.Core/Services/UserService.cs +++ b/src/Umbraco.Core/Services/UserService.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Globalization; using System.Linq; using Umbraco.Core.Events; @@ -139,6 +140,21 @@ namespace Umbraco.Core.Services } } + /// + /// Returns the user's applications that they are allowed to access + /// + /// + /// + public IEnumerable GetUserSections(IUser user) + { + //TODO: We need to cache this result, should all caching be done in the repo level ? + + var uow = _uowProvider.GetUnitOfWork(); + var sql = new Sql(); + sql.Select("app").From().Where("[user] = @userID", new {userID = user.Id}); + return uow.Database.Fetch(sql); + } + /// /// Creates a new user for logging into the umbraco backoffice /// diff --git a/src/umbraco.businesslogic/User.cs b/src/umbraco.businesslogic/User.cs index 8a2af06082..f49af6ff1d 100644 --- a/src/umbraco.businesslogic/User.cs +++ b/src/umbraco.businesslogic/User.cs @@ -4,6 +4,7 @@ using System.Web.Caching; using Umbraco.Core; using Umbraco.Core.Cache; using Umbraco.Core.Logging; +using Umbraco.Core.Models.Membership; using umbraco.DataLayer; using System.Collections.Generic; using System.Linq; @@ -37,6 +38,23 @@ namespace umbraco.BusinessLogic get { return Application.SqlHelper; } } + internal User(IUser user) + { + _userNoConsole = user.NoConsole; + _userDisabled = user.IsLockedOut; + _name = user.Name; + _loginname = user.Username; + _email = user.Email; + _language = user.Language; + _startnodeid = user.StartContentId; + _startmediaid = user.StartMediaId; + //this is cached, so should be 'ok' + _usertype = UserType.GetUserType(user.UserType.Id); + _defaultToLiveEditing = user.DefaultToLiveEditing; + + _isInitialized = true; + } + /// /// Initializes a new instance of the class. ///