From 8f69efe331295b9c4e8b3d9304dae434c076324b Mon Sep 17 00:00:00 2001 From: Shannon Date: Thu, 4 May 2017 19:16:52 +1000 Subject: [PATCH] It builds! --- .../Initial/DatabaseSchemaCreation.cs | 2 +- .../AddUserGroupTables.cs | 6 +- .../Repositories/PermissionRepository.cs | 158 ++++++++---------- .../Repositories/UserGroupRepository.cs | 2 +- .../Repositories/UserRepository.cs | 6 +- src/Umbraco.Core/Services/UserService.cs | 23 +-- src/Umbraco.Core/Umbraco.Core.csproj | 2 +- .../Cache/CacheRefresherEventHandlerTests.cs | 4 +- .../Repositories/ContentRepositoryTest.cs | 2 +- .../Repositories/UserGroupRepositoryTest.cs | 2 +- .../Repositories/UserRepositoryTest.cs | 7 +- .../Scoping/ScopedRepositoryTests.cs | 3 +- .../Services/UserServiceTests.cs | 11 +- .../Cache/CacheRefresherEventHandler.cs | 28 +--- src/Umbraco.Web/Umbraco.Web.csproj | 2 + .../umbraco/users/EditUser.aspx.cs | 14 +- 16 files changed, 121 insertions(+), 151 deletions(-) rename src/Umbraco.Core/Persistence/Migrations/Upgrades/{TargetVersionSevenSixZero => TargetVersionSevenSevenZero}/AddUserGroupTables.cs (99%) diff --git a/src/Umbraco.Core/Persistence/Migrations/Initial/DatabaseSchemaCreation.cs b/src/Umbraco.Core/Persistence/Migrations/Initial/DatabaseSchemaCreation.cs index 609087c4bc..c4db9eacf9 100644 --- a/src/Umbraco.Core/Persistence/Migrations/Initial/DatabaseSchemaCreation.cs +++ b/src/Umbraco.Core/Persistence/Migrations/Initial/DatabaseSchemaCreation.cs @@ -85,7 +85,7 @@ namespace Umbraco.Core.Persistence.Migrations.Initial //46, removed: UmbracoDeployChecksumDto //47, removed: UmbracoDeployDependencyDto {48, typeof (RedirectUrlDto) }, - {49, typeof (LockDto) } + {49, typeof (LockDto) }, {49, typeof (UserGroupDto) }, {50, typeof (User2UserGroupDto) }, {51, typeof (UserGroup2NodePermissionDto) }, diff --git a/src/Umbraco.Core/Persistence/Migrations/Upgrades/TargetVersionSevenSixZero/AddUserGroupTables.cs b/src/Umbraco.Core/Persistence/Migrations/Upgrades/TargetVersionSevenSevenZero/AddUserGroupTables.cs similarity index 99% rename from src/Umbraco.Core/Persistence/Migrations/Upgrades/TargetVersionSevenSixZero/AddUserGroupTables.cs rename to src/Umbraco.Core/Persistence/Migrations/Upgrades/TargetVersionSevenSevenZero/AddUserGroupTables.cs index ea566c0238..62b75bbf7a 100644 --- a/src/Umbraco.Core/Persistence/Migrations/Upgrades/TargetVersionSevenSixZero/AddUserGroupTables.cs +++ b/src/Umbraco.Core/Persistence/Migrations/Upgrades/TargetVersionSevenSevenZero/AddUserGroupTables.cs @@ -1,13 +1,13 @@ using System; +using System.Data; using System.Linq; using Umbraco.Core.Configuration; using Umbraco.Core.Logging; using Umbraco.Core.Persistence.SqlSyntax; -using System.Data; -namespace Umbraco.Core.Persistence.Migrations.Upgrades.TargetVersionSevenSixZero +namespace Umbraco.Core.Persistence.Migrations.Upgrades.TargetVersionSevenSevenZero { - [Migration("7.6.0", 100, GlobalSettings.UmbracoMigrationName)] + [Migration("7.6.0", 100, Constants.System.UmbracoMigrationName)] public class AddUserGroupTables : MigrationBase { public AddUserGroupTables(ISqlSyntaxProvider sqlSyntax, ILogger logger) diff --git a/src/Umbraco.Core/Persistence/Repositories/PermissionRepository.cs b/src/Umbraco.Core/Persistence/Repositories/PermissionRepository.cs index 5cbffdeee5..3c7273eb0b 100644 --- a/src/Umbraco.Core/Persistence/Repositories/PermissionRepository.cs +++ b/src/Umbraco.Core/Persistence/Repositories/PermissionRepository.cs @@ -1,7 +1,5 @@ using System; -using System.Collections; using System.Collections.Generic; -using System.Dynamic; using System.Globalization; using System.Linq; using System.Text; @@ -12,18 +10,8 @@ using Umbraco.Core.Models.Membership; using Umbraco.Core.Models.Rdbms; using Umbraco.Core.Persistence.SqlSyntax; using Umbraco.Core.Persistence.UnitOfWork; -using Umbraco.Core.Services; using CacheKeys = Umbraco.Core.Cache.CacheKeys; using Umbraco.Core.Cache; -using System.Collections.Generic; -using System.Globalization; -using System.Linq; -using System.Text; -using Umbraco.Core.Models.EntityBase; -using Umbraco.Core.Models.Membership; -using Umbraco.Core.Models.Rdbms; -using Umbraco.Core.Persistence.SqlSyntax; -using Umbraco.Core.Persistence.UnitOfWork; namespace Umbraco.Core.Persistence.Repositories { @@ -67,8 +55,8 @@ namespace Umbraco.Core.Persistence.Repositories sql.Select("*") .From() .Where(whereCriteria); - var result = _unitOfWork.Database.Fetch(sql).ToArray(); - // ToArray() to ensure it's all fetched from the db once + var result = _unitOfWork.Database.Fetch(sql).ToArray(); + // ToArray() to ensure it's all fetched from the db once return ConvertToPermissionList(result); }, GetCacheTimeout(), @@ -154,8 +142,8 @@ namespace Umbraco.Core.Persistence.Repositories .Where(dto => dto.NodeId == entityId) .OrderBy(dto => dto.NodeId); - var result = _unitOfWork.Database.Fetch(sql).ToArray(); - // ToArray() to ensure it's all fetched from the db once + var result = _unitOfWork.Database.Fetch(sql).ToArray(); + // ToArray() to ensure it's all fetched from the db once return ConvertToPermissionList(result); } @@ -170,37 +158,34 @@ namespace Umbraco.Core.Persistence.Repositories /// public void ReplacePermissions(int groupId, IEnumerable permissions, params int[] entityIds) { - var db = _unitOfWork.Database; - - //we need to batch these in groups of 2000 so we don't exceed the max 2100 limit - var sql = "DELETE FROM umbracoUserGroup2NodePermission WHERE userGroupId = @groupId AND nodeId in (@nodeIds)"; + var db = _unitOfWork.Database; + + //we need to batch these in groups of 2000 so we don't exceed the max 2100 limit + var sql = "DELETE FROM umbracoUserGroup2NodePermission WHERE userGroupId = @groupId AND nodeId in (@nodeIds)"; foreach (var idGroup in entityIds.InGroupsOf(2000)) - { - db.Execute(sql, new {groupId = groupId, nodeIds = idGroup}); - } - - var toInsert = new List(); + { + db.Execute(sql, new { groupId = groupId, nodeIds = idGroup }); + } + + var toInsert = new List(); foreach (var p in permissions) { foreach (var e in entityIds) - { - toInsert.Add(new UserGroup2NodePermissionDto + { + toInsert.Add(new UserGroup2NodePermissionDto { NodeId = e, - Permission = p.ToString(CultureInfo.InvariantCulture), - UserGroupId = groupId + Permission = p.ToString(CultureInfo.InvariantCulture), + UserGroupId = groupId }); } } - _unitOfWork.Database.BulkInsertRecords(toInsert, _sqlSyntax); - - //Raise the event - //TODO: FIX THIS - _unitOfWork.Events.Dispatch(AssignedPermissions, this, new SaveEventArgs(ConvertToPermissionList(toInsert), false)); - AssignedPermissions.RaiseEvent( - new SaveEventArgs(ConvertToPermissionList(toInsert), false), this) - + _unitOfWork.Database.BulkInsertRecords(toInsert, _sqlSyntax); + + //Raise the event + _unitOfWork.Events.Dispatch(AssignedPermissions, this, new SaveEventArgs(ConvertToPermissionList(toInsert), false)); + } /// @@ -211,30 +196,27 @@ namespace Umbraco.Core.Persistence.Repositories /// public void AssignPermission(int groupId, char permission, params int[] entityIds) { - var db = _unitOfWork.Database; - var sql = "DELETE FROM umbracoUserGroup2NodePermission WHERE userGroupId = @groupId AND permission=@permission AND nodeId in (@entityIds)"; - db.Execute(sql, - new - { - groupId = groupId, - permission = permission.ToString(CultureInfo.InvariantCulture), - entityIds = entityIds - }); - - var actions = entityIds.Select(id => new UserGroup2NodePermissionDto + var db = _unitOfWork.Database; + var sql = "DELETE FROM umbracoUserGroup2NodePermission WHERE userGroupId = @groupId AND permission=@permission AND nodeId in (@entityIds)"; + db.Execute(sql, + new + { + groupId = groupId, + permission = permission.ToString(CultureInfo.InvariantCulture), + entityIds = entityIds + }); + + var actions = entityIds.Select(id => new UserGroup2NodePermissionDto { NodeId = id, - Permission = permission.ToString(CultureInfo.InvariantCulture), - UserGroupId = groupId + Permission = permission.ToString(CultureInfo.InvariantCulture), + UserGroupId = groupId }).ToArray(); - _unitOfWork.Database.BulkInsertRecords(actions, _sqlSyntax); - - //Raise the event - //TODO: Fix this - _unitOfWork.Events.Dispatch(AssignedPermissions, this, new SaveEventArgs(ConvertToPermissionList(actions), false)); - AssignedPermissions.RaiseEvent( - new SaveEventArgs(ConvertToPermissionList(actions), false), this) + _unitOfWork.Database.BulkInsertRecords(actions, _sqlSyntax); + + //Raise the event + _unitOfWork.Events.Dispatch(AssignedPermissions, this, new SaveEventArgs(ConvertToPermissionList(actions), false)); } @@ -246,31 +228,28 @@ namespace Umbraco.Core.Persistence.Repositories /// public void AssignEntityPermission(TEntity entity, char permission, IEnumerable groupIds) { - var db = _unitOfWork.Database; - var sql = "DELETE FROM umbracoUserGroup2NodePermission WHERE nodeId = @nodeId AND permission = @permission AND userGroupId in (@groupIds)"; - db.Execute(sql, - new - { - nodeId = entity.Id, - permission = permission.ToString(CultureInfo.InvariantCulture), - groupIds = groupIds - }); - - var actions = groupIds.Select(id => new UserGroup2NodePermissionDto + var db = _unitOfWork.Database; + var sql = "DELETE FROM umbracoUserGroup2NodePermission WHERE nodeId = @nodeId AND permission = @permission AND userGroupId in (@groupIds)"; + db.Execute(sql, + new + { + nodeId = entity.Id, + permission = permission.ToString(CultureInfo.InvariantCulture), + groupIds = groupIds + }); + + var actions = groupIds.Select(id => new UserGroup2NodePermissionDto { NodeId = entity.Id, - Permission = permission.ToString(CultureInfo.InvariantCulture), - UserGroupId = id + Permission = permission.ToString(CultureInfo.InvariantCulture), + UserGroupId = id }).ToArray(); _unitOfWork.Database.BulkInsertRecords(actions, _sqlSyntax); //Raise the event - //TODO: Fix this - _unitOfWork.Events.Dispatch(AssignedPermissions, this, new SaveEventArgs(ConvertToPermissionList(actions), false)); - AssignedPermissions.RaiseEvent( - new SaveEventArgs(ConvertToPermissionList(actions), false), this) - + _unitOfWork.Events.Dispatch(AssignedPermissions, this, new SaveEventArgs(ConvertToPermissionList(actions), false)); + } /// @@ -283,26 +262,23 @@ namespace Umbraco.Core.Persistence.Repositories /// public void ReplaceEntityPermissions(EntityPermissionSet permissionSet) { - var db = _unitOfWork.Database; - var sql = "DELETE FROM umbracoUserGroup2NodePermission WHERE nodeId = @nodeId"; - db.Execute(sql, new {nodeId = permissionSet.EntityId}); - - var actions = permissionSet.PermissionsSet.Select(p => new UserGroup2NodePermissionDto + var db = _unitOfWork.Database; + var sql = "DELETE FROM umbracoUserGroup2NodePermission WHERE nodeId = @nodeId"; + db.Execute(sql, new { nodeId = permissionSet.EntityId }); + + var actions = permissionSet.PermissionsSet.Select(p => new UserGroup2NodePermissionDto { NodeId = permissionSet.EntityId, - Permission = p.Permission, - UserGroupId = p.UserGroupId + Permission = p.Permission, + UserGroupId = p.UserGroupId }).ToArray(); - _unitOfWork.Database.BulkInsertRecords(actions, _sqlSyntax); - - //Raise the event - //TODO: Fix this - _unitOfWork.Events.Dispatch(AssignedPermissions, this, new SaveEventArgs(ConvertToPermissionList(actions), false)); - AssignedPermissions.RaiseEvent( - new SaveEventArgs(ConvertToPermissionList(actions), false), this) - - } + _unitOfWork.Database.BulkInsertRecords(actions, _sqlSyntax); + + //Raise the event + _unitOfWork.Events.Dispatch(AssignedPermissions, this, new SaveEventArgs(ConvertToPermissionList(actions), false)); + + } public static event TypedEventHandler, SaveEventArgs> AssignedPermissions; diff --git a/src/Umbraco.Core/Persistence/Repositories/UserGroupRepository.cs b/src/Umbraco.Core/Persistence/Repositories/UserGroupRepository.cs index d214c0d555..f87561e32f 100644 --- a/src/Umbraco.Core/Persistence/Repositories/UserGroupRepository.cs +++ b/src/Umbraco.Core/Persistence/Repositories/UserGroupRepository.cs @@ -20,7 +20,7 @@ namespace Umbraco.Core.Persistence.Repositories { private readonly CacheHelper _cacheHelper; - public UserGroupRepository(IDatabaseUnitOfWork work, CacheHelper cacheHelper, ILogger logger, ISqlSyntaxProvider sqlSyntax) + public UserGroupRepository(IScopeUnitOfWork work, CacheHelper cacheHelper, ILogger logger, ISqlSyntaxProvider sqlSyntax) : base(work, cacheHelper, logger, sqlSyntax) { _cacheHelper = cacheHelper; diff --git a/src/Umbraco.Core/Persistence/Repositories/UserRepository.cs b/src/Umbraco.Core/Persistence/Repositories/UserRepository.cs index 994c07d13e..7456bfc88c 100644 --- a/src/Umbraco.Core/Persistence/Repositories/UserRepository.cs +++ b/src/Umbraco.Core/Persistence/Repositories/UserRepository.cs @@ -20,12 +20,12 @@ namespace Umbraco.Core.Persistence.Repositories /// internal class UserRepository : PetaPocoRepositoryBase, IUserRepository { - private readonly CacheHelper _cacheHelper; + //private readonly CacheHelper _cacheHelper; - public UserRepository(IDatabaseUnitOfWork work, CacheHelper cacheHelper, ILogger logger, ISqlSyntaxProvider sqlSyntax) + public UserRepository(IScopeUnitOfWork work, CacheHelper cacheHelper, ILogger logger, ISqlSyntaxProvider sqlSyntax) : base(work, cacheHelper, logger, sqlSyntax) { - _cacheHelper = cacheHelper; + //_cacheHelper = cacheHelper; } #region Overrides of RepositoryBase diff --git a/src/Umbraco.Core/Services/UserService.cs b/src/Umbraco.Core/Services/UserService.cs index 066823ca76..0c1e1fa63f 100644 --- a/src/Umbraco.Core/Services/UserService.cs +++ b/src/Umbraco.Core/Services/UserService.cs @@ -612,7 +612,7 @@ namespace Umbraco.Core.Services { using (var uow = UowProvider.GetUnitOfWork()) { - var repository = RepositoryFactory.CreateUserGroupRepository(uow) + var repository = RepositoryFactory.CreateUserGroupRepository(uow); repository.AssignGroupPermission(groupId, permission, entityIds); uow.Commit(); } @@ -641,7 +641,7 @@ namespace Umbraco.Core.Services { using (var uow = UowProvider.GetUnitOfWork(readOnly: true)) { - var repository = RepositoryFactory.CreateUserGroupRepository(uow); + var repository = RepositoryFactory.CreateUserRepository(uow); return repository.GetGroupsForUser(userId); } } @@ -653,9 +653,12 @@ namespace Umbraco.Core.Services /// public IUserGroup GetUserGroupByAlias(string alias) { - using (var repository = RepositoryFactory.CreateUserGroupRepository(UowProvider.GetUnitOfWork())) + using (var uow = UowProvider.GetUnitOfWork(readOnly: true)) { + var repository = RepositoryFactory.CreateUserGroupRepository(uow); var query = Query.Builder.Where(x => x.Alias == alias); + var contents = repository.GetByQuery(query); + return contents.SingleOrDefault(); } } @@ -682,7 +685,7 @@ namespace Umbraco.Core.Services { using (var uow = UowProvider.GetUnitOfWork(readOnly: true)) { - var repository = RepositoryFactory.CreateUserGroupRepository(uow) + var repository = RepositoryFactory.CreateUserGroupRepository(uow); var query = Query.Builder.Where(x => x.Name == name); return repository.GetByQuery(query).SingleOrDefault(); } @@ -835,7 +838,7 @@ namespace Umbraco.Core.Services public IEnumerable GetPermissions(IUserGroup group, bool directlyAssignedOnly, params int[] nodeIds) { - using (var uow = UowProvider.GetUnitOfWork();) + using (var uow = UowProvider.GetUnitOfWork(readOnly: true)) { var repository = RepositoryFactory.CreateUserGroupRepository(uow); var explicitPermissions = repository.GetPermissionsForEntities(group.Id, nodeIds); @@ -951,11 +954,11 @@ namespace Umbraco.Core.Services : int.Parse(path); } - private static bool IsNotNullActionPermission(EntityPermission x) - { - const string NullActionChar = "-"; - return string.Join(string.Empty, x.AssignedPermissions) != NullActionChar; - } + //private static bool IsNotNullActionPermission(EntityPermission x) + //{ + // const string NullActionChar = "-"; + // return string.Join(string.Empty, x.AssignedPermissions) != NullActionChar; + //} /// /// Checks in a set of permissions associated with a user for those related to a given nodeId diff --git a/src/Umbraco.Core/Umbraco.Core.csproj b/src/Umbraco.Core/Umbraco.Core.csproj index c6ccd8495e..1f3f352292 100644 --- a/src/Umbraco.Core/Umbraco.Core.csproj +++ b/src/Umbraco.Core/Umbraco.Core.csproj @@ -521,13 +521,13 @@ - + diff --git a/src/Umbraco.Tests/Cache/CacheRefresherEventHandlerTests.cs b/src/Umbraco.Tests/Cache/CacheRefresherEventHandlerTests.cs index a5036188fd..61f526a046 100644 --- a/src/Umbraco.Tests/Cache/CacheRefresherEventHandlerTests.cs +++ b/src/Umbraco.Tests/Cache/CacheRefresherEventHandlerTests.cs @@ -32,8 +32,8 @@ namespace Umbraco.Tests.Cache new EventDefinition(null, ServiceContext.SectionService, new EventArgs(), "Deleted"), new EventDefinition(null, ServiceContext.SectionService, new EventArgs(), "New"), - new EventDefinition>(null, ServiceContext.UserService, new SaveEventArgs(Enumerable.Empty())), - new EventDefinition>(null, ServiceContext.UserService, new DeleteEventArgs(Enumerable.Empty())), + new EventDefinition>(null, ServiceContext.UserService, new SaveEventArgs(Enumerable.Empty())), + new EventDefinition>(null, ServiceContext.UserService, new DeleteEventArgs(Enumerable.Empty())), new EventDefinition>(null, ServiceContext.UserService, new SaveEventArgs(Enumerable.Empty())), new EventDefinition>(null, ServiceContext.UserService, new DeleteEventArgs(Enumerable.Empty())), diff --git a/src/Umbraco.Tests/Persistence/Repositories/ContentRepositoryTest.cs b/src/Umbraco.Tests/Persistence/Repositories/ContentRepositoryTest.cs index f8ff391c32..a3e5510941 100644 --- a/src/Umbraco.Tests/Persistence/Repositories/ContentRepositoryTest.cs +++ b/src/Umbraco.Tests/Persistence/Repositories/ContentRepositoryTest.cs @@ -64,7 +64,7 @@ namespace Umbraco.Tests.Persistence.Repositories return repository; } - private UserGroupRepository CreateUserGroupRepository(IDatabaseUnitOfWork unitOfWork) + private UserGroupRepository CreateUserGroupRepository(IScopeUnitOfWork unitOfWork) { return new UserGroupRepository(unitOfWork, CacheHelper, Logger, SqlSyntax); } diff --git a/src/Umbraco.Tests/Persistence/Repositories/UserGroupRepositoryTest.cs b/src/Umbraco.Tests/Persistence/Repositories/UserGroupRepositoryTest.cs index 6a2412bc63..1b669fdf60 100644 --- a/src/Umbraco.Tests/Persistence/Repositories/UserGroupRepositoryTest.cs +++ b/src/Umbraco.Tests/Persistence/Repositories/UserGroupRepositoryTest.cs @@ -30,7 +30,7 @@ namespace Umbraco.Tests.Persistence.Repositories base.TearDown(); } - private UserGroupRepository CreateRepository(IDatabaseUnitOfWork unitOfWork) + private UserGroupRepository CreateRepository(IScopeUnitOfWork unitOfWork) { return new UserGroupRepository(unitOfWork, CacheHelper.CreateDisabledCacheHelper(), Mock.Of(), SqlSyntax); } diff --git a/src/Umbraco.Tests/Persistence/Repositories/UserRepositoryTest.cs b/src/Umbraco.Tests/Persistence/Repositories/UserRepositoryTest.cs index f13175f563..62b22f681a 100644 --- a/src/Umbraco.Tests/Persistence/Repositories/UserRepositoryTest.cs +++ b/src/Umbraco.Tests/Persistence/Repositories/UserRepositoryTest.cs @@ -28,14 +28,13 @@ namespace Umbraco.Tests.Persistence.Repositories base.TearDown(); } - private UserRepository CreateRepository(IScopeUnitOfWork unitOfWork, out UserTypeRepository userTypeRepository) + private UserRepository CreateRepository(IScopeUnitOfWork unitOfWork) { - userTypeRepository = new UserTypeRepository(unitOfWork, CacheHelper.CreateDisabledCacheHelper(), Mock.Of(), SqlSyntax); - var repository = new UserRepository(unitOfWork, CacheHelper.CreateDisabledCacheHelper(), Mock.Of(), SqlSyntax, userTypeRepository); + var repository = new UserRepository(unitOfWork, CacheHelper.CreateDisabledCacheHelper(), Mock.Of(), SqlSyntax); return repository; } - private UserGroupRepository CreateUserGroupRepository(IDatabaseUnitOfWork unitOfWork) + private UserGroupRepository CreateUserGroupRepository(IScopeUnitOfWork unitOfWork) { return new UserGroupRepository(unitOfWork, CacheHelper.CreateDisabledCacheHelper(), Mock.Of(), SqlSyntax); } diff --git a/src/Umbraco.Tests/Scoping/ScopedRepositoryTests.cs b/src/Umbraco.Tests/Scoping/ScopedRepositoryTests.cs index 62bd17e122..ddbdf82f7f 100644 --- a/src/Umbraco.Tests/Scoping/ScopedRepositoryTests.cs +++ b/src/Umbraco.Tests/Scoping/ScopedRepositoryTests.cs @@ -80,8 +80,7 @@ namespace Umbraco.Tests.Scoping var service = ApplicationContext.Services.UserService; var globalCache = ApplicationContext.ApplicationCache.IsolatedRuntimeCache.GetOrCreateCache(typeof(IUser)); - var userType = service.GetUserTypeByAlias("admin"); - var user = (IUser) new User("name", "email", "username", "rawPassword", userType); + var user = (IUser) new User("name", "email", "username", "rawPassword"); service.Save(user); // global cache contains the entity diff --git a/src/Umbraco.Tests/Services/UserServiceTests.cs b/src/Umbraco.Tests/Services/UserServiceTests.cs index e05b9e6225..6c513e0956 100644 --- a/src/Umbraco.Tests/Services/UserServiceTests.cs +++ b/src/Umbraco.Tests/Services/UserServiceTests.cs @@ -535,11 +535,10 @@ namespace Umbraco.Tests.Services public void Cannot_Create_User_With_Empty_Username() { // Arrange - var userService = ServiceContext.UserService; - var userType = userService.GetUserTypeByAlias("admin"); + var userService = ServiceContext.UserService; // Act & Assert - Assert.Throws(() => userService.CreateUserWithIdentity(string.Empty, "john@umbraco.io", userType)); + Assert.Throws(() => userService.CreateUserWithIdentity(string.Empty, "john@umbraco.io")); } [Test] @@ -547,8 +546,7 @@ namespace Umbraco.Tests.Services { // Arrange var userService = ServiceContext.UserService; - var userType = userService.GetUserTypeByAlias("admin"); - var user = userService.CreateUserWithIdentity("John Doe", "john@umbraco.io", userType); + var user = userService.CreateUserWithIdentity("John Doe", "john@umbraco.io"); user.Username = string.Empty; // Act & Assert @@ -560,8 +558,7 @@ namespace Umbraco.Tests.Services { // Arrange var userService = ServiceContext.UserService; - var userType = userService.GetUserTypeByAlias("admin"); - var user = userService.CreateUserWithIdentity("John Doe", "john@umbraco.io", userType); + var user = userService.CreateUserWithIdentity("John Doe", "john@umbraco.io"); user.Name = string.Empty; // Act & Assert diff --git a/src/Umbraco.Web/Cache/CacheRefresherEventHandler.cs b/src/Umbraco.Web/Cache/CacheRefresherEventHandler.cs index 03898f8af4..2a30a90635 100644 --- a/src/Umbraco.Web/Cache/CacheRefresherEventHandler.cs +++ b/src/Umbraco.Web/Cache/CacheRefresherEventHandler.cs @@ -58,30 +58,12 @@ namespace Umbraco.Web.Cache () => SectionService.Deleted -= SectionService_Deleted); Bind(() => SectionService.New += SectionService_New, () => SectionService.New -= SectionService_New); - //bind to user / user group events - //TODO: FIX THIS - UserService.SavedUserGroup += UserServiceSavedUserGroup; - UserService.DeletedUserGroup += UserServiceDeletedUserGroup; - UserService.SavedUser += UserServiceSavedUser; - UserService.DeletedUser += UserServiceDeletedUser; - - //Bind to dictionary events - - LocalizationService.DeletedDictionaryItem += LocalizationServiceDeletedDictionaryItem; - LocalizationService.SavedDictionaryItem += LocalizationServiceSavedDictionaryItem; - - //Bind to data type events - //NOTE: we need to bind to legacy and new API events currently: http://issues.umbraco.org/issue/U4-1979 - - DataTypeService.Deleted += DataTypeServiceDeleted; - DataTypeService.Saved += DataTypeServiceSaved - //END FIX THIS - + // bind to user and user type events - Bind(() => UserService.SavedUserType += UserService_SavedUserType, - () => UserService.SavedUserType -= UserService_SavedUserType); - Bind(() => UserService.DeletedUserType += UserService_DeletedUserType, - () => UserService.DeletedUserType -= UserService_DeletedUserType); + Bind(() => UserService.SavedUserGroup += UserServiceSavedUserGroup, + () => UserService.SavedUserGroup -= UserServiceSavedUserGroup); + Bind(() => UserService.DeletedUserGroup += UserServiceDeletedUserGroup, + () => UserService.DeletedUserGroup -= UserServiceDeletedUserGroup); Bind(() => UserService.SavedUser += UserService_SavedUser, () => UserService.SavedUser -= UserService_SavedUser); Bind(() => UserService.DeletedUser += UserService_DeletedUser, diff --git a/src/Umbraco.Web/Umbraco.Web.csproj b/src/Umbraco.Web/Umbraco.Web.csproj index 8c22fec893..e8c92893fa 100644 --- a/src/Umbraco.Web/Umbraco.Web.csproj +++ b/src/Umbraco.Web/Umbraco.Web.csproj @@ -443,6 +443,8 @@ + ASPXCodeBehind + EditUserGroup.aspx diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/users/EditUser.aspx.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/users/EditUser.aspx.cs index 7331cdb6f5..de60960e5a 100644 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/users/EditUser.aspx.cs +++ b/src/Umbraco.Web/umbraco.presentation/umbraco/users/EditUser.aspx.cs @@ -25,6 +25,7 @@ using Umbraco.Core.Models; using PropertyType = umbraco.cms.businesslogic.propertytype.PropertyType; using System.Text.RegularExpressions; using System.Text; +using Umbraco.Core.Security; namespace umbraco.cms.presentation.user { @@ -62,7 +63,7 @@ namespace umbraco.cms.presentation.user protected DropDownList cExcerpt = new DropDownList(); protected ContentPicker cMediaPicker = new ContentPicker(); protected ContentPicker cContentPicker = new ContentPicker(); - protected CustomValidator sectionValidator = new CustomValidator(); + //protected CustomValidator sectionValidator = new CustomValidator(); protected UpdatePanel pnlGroups = new UpdatePanel(); protected PlaceHolder pnlGroupControls = new PlaceHolder(); @@ -294,6 +295,17 @@ namespace umbraco.cms.presentation.user ClientTools .SetActiveTreeType(TreeDefinitionCollection.Instance.FindTree().Tree.Alias) .SyncTree(UID.ToString(), IsPostBack); + } + + private void LnameCustomValidator_OnServerValidate(object source, ServerValidateEventArgs args) + { + var usersWithLoginName = ApplicationContext.Services.UserService.GetByUsername(lname.Text); + args.IsValid = usersWithLoginName == null || usersWithLoginName.Id == u.Id; + } + + private void EmailCustomValidator_OnServerValidate(object source, ServerValidateEventArgs args) + { + args.IsValid = MembershipProviderBase.IsEmailValid(email.Text.Trim()); } private void BindGroups()