diff --git a/src/Umbraco.Core/Models/Identity/BackOfficeIdentityUser.cs b/src/Umbraco.Core/Models/Identity/BackOfficeIdentityUser.cs index 1618150851..03631bda05 100644 --- a/src/Umbraco.Core/Models/Identity/BackOfficeIdentityUser.cs +++ b/src/Umbraco.Core/Models/Identity/BackOfficeIdentityUser.cs @@ -37,8 +37,6 @@ namespace Umbraco.Core.Models.Identity public string[] Groups { get; set; } public string Culture { get; set; } - public string UserTypeAlias { get; set; } - /// /// Lockout is always enabled /// diff --git a/src/Umbraco.Core/Models/Identity/IdentityModelMappings.cs b/src/Umbraco.Core/Models/Identity/IdentityModelMappings.cs index 74fd602a7e..0bc0351d8d 100644 --- a/src/Umbraco.Core/Models/Identity/IdentityModelMappings.cs +++ b/src/Umbraco.Core/Models/Identity/IdentityModelMappings.cs @@ -22,7 +22,6 @@ namespace Umbraco.Core.Models.Identity .ForMember(user => user.Name, expression => expression.MapFrom(user => user.Name)) .ForMember(user => user.StartMediaId, expression => expression.MapFrom(user => user.StartMediaId)) .ForMember(user => user.StartContentId, expression => expression.MapFrom(user => user.StartContentId)) - .ForMember(user => user.UserTypeAlias, expression => expression.MapFrom(user => user.UserType.Alias)) .ForMember(user => user.AccessFailedCount, expression => expression.MapFrom(user => user.FailedPasswordAttempts)) .ForMember(user => user.Groups, expression => expression.MapFrom(user => user.Groups.Select(x => x.Name).ToArray())) .ForMember(user => user.AllowedSections, expression => expression.MapFrom(user => user.AllowedSections.ToArray())); @@ -31,9 +30,8 @@ namespace Umbraco.Core.Models.Identity .ConstructUsing((BackOfficeIdentityUser user) => new UserData(Guid.NewGuid().ToString("N"))) //this is the 'session id' .ForMember(detail => detail.Id, opt => opt.MapFrom(user => user.Id)) .ForMember(detail => detail.AllowedApplications, opt => opt.MapFrom(user => user.AllowedSections)) - .ForMember(detail => detail.Groups, opt => opt.MapFrom(user => user.Groups)) + .ForMember(detail => detail.Roles, opt => opt.MapFrom(user => user.Groups)) .ForMember(detail => detail.RealName, opt => opt.MapFrom(user => user.Name)) - .ForMember(detail => detail.Roles, opt => opt.MapFrom(user => new[] { user.UserTypeAlias })) .ForMember(detail => detail.StartContentNode, opt => opt.MapFrom(user => user.StartContentId)) .ForMember(detail => detail.StartMediaNode, opt => opt.MapFrom(user => user.StartMediaId)) .ForMember(detail => detail.Username, opt => opt.MapFrom(user => user.UserName)) diff --git a/src/Umbraco.Core/Models/Membership/IUser.cs b/src/Umbraco.Core/Models/Membership/IUser.cs index a3cea0b232..1fb82116f9 100644 --- a/src/Umbraco.Core/Models/Membership/IUser.cs +++ b/src/Umbraco.Core/Models/Membership/IUser.cs @@ -15,11 +15,6 @@ namespace Umbraco.Core.Models.Membership int StartMediaId { get; set; } string Language { get; set; } - /// - /// Gets/sets the user type for the user - /// - IUserType UserType { get; set; } - /// /// Gets the groups that user is part of /// diff --git a/src/Umbraco.Core/Models/Membership/IUserGroup.cs b/src/Umbraco.Core/Models/Membership/IUserGroup.cs index fc1af97912..8e9f862910 100644 --- a/src/Umbraco.Core/Models/Membership/IUserGroup.cs +++ b/src/Umbraco.Core/Models/Membership/IUserGroup.cs @@ -1,9 +1,28 @@ using System.Collections.Generic; +using Umbraco.Core.Models.EntityBase; namespace Umbraco.Core.Models.Membership { - public interface IUserGroup : IUserTypeGroupBase + public interface IUserGroup : IAggregateRoot { + /// + /// The alias + /// + string Alias { get; set; } + + /// + /// The name + /// + string Name { get; set; } + + /// + /// The set of default permissions + /// + /// + /// By default each permission is simply a single char but we've made this an enumerable{string} to support a more flexible permissions structure in the future. + /// + IEnumerable Permissions { get; set; } + IEnumerable AllowedSections { get; } void RemoveAllowedSection(string sectionAlias); diff --git a/src/Umbraco.Core/Models/Membership/IUserType.cs b/src/Umbraco.Core/Models/Membership/IUserType.cs deleted file mode 100644 index ccfdc729f5..0000000000 --- a/src/Umbraco.Core/Models/Membership/IUserType.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace Umbraco.Core.Models.Membership -{ - public interface IUserType : IUserTypeGroupBase - { - } -} \ No newline at end of file diff --git a/src/Umbraco.Core/Models/Membership/IUserTypeGroupBase.cs b/src/Umbraco.Core/Models/Membership/IUserTypeGroupBase.cs deleted file mode 100644 index 06769b1866..0000000000 --- a/src/Umbraco.Core/Models/Membership/IUserTypeGroupBase.cs +++ /dev/null @@ -1,26 +0,0 @@ -using System.Collections.Generic; -using Umbraco.Core.Models.EntityBase; - -namespace Umbraco.Core.Models.Membership -{ - public interface IUserTypeGroupBase : IAggregateRoot - { - /// - /// The alias - /// - string Alias { get; set; } - - /// - /// The name - /// - string Name { get; set; } - - /// - /// The set of default permissions - /// - /// - /// By default each permission is simply a single char but we've made this an enumerable{string} to support a more flexible permissions structure in the future. - /// - IEnumerable Permissions { get; set; } - } -} \ No newline at end of file diff --git a/src/Umbraco.Core/Models/Membership/UmbracoMembershipUser.cs b/src/Umbraco.Core/Models/Membership/UmbracoMembershipUser.cs index ada2a7102d..0ada5c3d0e 100644 --- a/src/Umbraco.Core/Models/Membership/UmbracoMembershipUser.cs +++ b/src/Umbraco.Core/Models/Membership/UmbracoMembershipUser.cs @@ -34,12 +34,11 @@ namespace Umbraco.Core.Models.Membership /// The last lockout date. /// The full name. /// The language. - /// Type of the user. /// public UmbracoMembershipUser(string providerName, string name, object providerUserKey, string email, string passwordQuestion, string comment, bool isApproved, bool isLockedOut, DateTime creationDate, DateTime lastLoginDate, DateTime lastActivityDate, DateTime lastPasswordChangedDate, - DateTime lastLockoutDate, string fullName, string language, IUserType userType, T user) + DateTime lastLockoutDate, string fullName, string language, T user) : base( providerName, name, providerUserKey, email, passwordQuestion, comment, isApproved, isLockedOut, creationDate, lastLoginDate, lastActivityDate, lastPasswordChangedDate, lastLockoutDate) { diff --git a/src/Umbraco.Core/Models/Membership/User.cs b/src/Umbraco.Core/Models/Membership/User.cs index 41bcb5ee80..d6d02df8f3 100644 --- a/src/Umbraco.Core/Models/Membership/User.cs +++ b/src/Umbraco.Core/Models/Membership/User.cs @@ -17,13 +17,8 @@ namespace Umbraco.Core.Models.Membership [DataContract(IsReference = true)] public class User : Entity, IUser { - public User(IUserType userType) + public User() { - if (userType == null) throw new ArgumentNullException("userType"); - - _userType = userType; - _defaultPermissions = _userType.Permissions == null ? Enumerable.Empty() : new List(_userType.Permissions); - //Groups = new List { userType }; SessionTimeout = 60; _groupCollection = new List(); _language = GlobalSettings.DefaultUILanguage; @@ -35,8 +30,8 @@ namespace Umbraco.Core.Models.Membership _rawPasswordValue = ""; } - public User(string name, string email, string username, string rawPasswordValue, IUserType userType) - : this(userType) + public User(string name, string email, string username, string rawPasswordValue) + : this() { _name = name; _email = email; @@ -48,7 +43,6 @@ namespace Umbraco.Core.Models.Membership _startMediaId = -1; } - private IUserType _userType; private string _name; private string _securityStamp; private List _groupCollection; @@ -95,7 +89,6 @@ namespace Umbraco.Core.Models.Membership public readonly PropertyInfo LanguageSelector = ExpressionHelper.GetPropertyInfo(x => x.Language); public readonly PropertyInfo DefaultToLiveEditingSelector = ExpressionHelper.GetPropertyInfo(x => x.DefaultToLiveEditing); - public readonly PropertyInfo UserTypeSelector = ExpressionHelper.GetPropertyInfo(x => x.UserType); } #region Implementation of IMembershipUser @@ -281,21 +274,6 @@ namespace Umbraco.Core.Models.Membership set { SetPropertyValueAndDetectChanges(value, ref _defaultToLiveEditing, Ps.Value.DefaultToLiveEditingSelector); } } - [IgnoreDataMember] - public IUserType UserType - { - get { return _userType; } - set - { - if (value.HasIdentity == false) - { - throw new InvalidOperationException("Cannot assign a User Type that has not been persisted"); - } - - SetPropertyValueAndDetectChanges(value, ref _userType, Ps.Value.UserTypeSelector); - } - } - /// /// Gets or sets the groups that user is part of /// diff --git a/src/Umbraco.Core/Models/Membership/UserGroup.cs b/src/Umbraco.Core/Models/Membership/UserGroup.cs index 403e40c8df..ea5f891037 100644 --- a/src/Umbraco.Core/Models/Membership/UserGroup.cs +++ b/src/Umbraco.Core/Models/Membership/UserGroup.cs @@ -1,6 +1,9 @@ using System; using System.Collections.Generic; +using System.Reflection; using System.Runtime.Serialization; +using Umbraco.Core.Models.EntityBase; +using Umbraco.Core.Strings; namespace Umbraco.Core.Models.Membership { @@ -9,15 +12,67 @@ namespace Umbraco.Core.Models.Membership /// [Serializable] [DataContract(IsReference = true)] - internal class UserGroup : UserTypeGroupBase, IUserGroup + internal class UserGroup : Entity, IUserGroup { - private List _sectionCollection; + private string _alias; + private string _name; + private IEnumerable _permissions; + private readonly List _sectionCollection; + + private static readonly Lazy Ps = new Lazy(); + + private class PropertySelectors + { + public readonly PropertyInfo NameSelector = ExpressionHelper.GetPropertyInfo(x => x.Name); + public readonly PropertyInfo AliasSelector = ExpressionHelper.GetPropertyInfo(x => x.Alias); + public readonly PropertyInfo PermissionsSelector = ExpressionHelper.GetPropertyInfo>(x => x.Permissions); + } public UserGroup() { _sectionCollection = new List(); } + [DataMember] + public string Alias + { + get { return _alias; } + set + { + SetPropertyValueAndDetectChanges( + value.ToCleanString(CleanStringType.Alias | CleanStringType.UmbracoCase), + ref _alias, + Ps.Value.AliasSelector); + } + } + + [DataMember] + public string Name + { + get { return _name; } + set { SetPropertyValueAndDetectChanges(value, ref _name, Ps.Value.NameSelector); } + } + + /// + /// The set of default permissions for the user type + /// + /// + /// By default each permission is simply a single char but we've made this an enumerable{string} to support a more flexible permissions structure in the future. + /// + [DataMember] + public IEnumerable Permissions + { + get { return _permissions; } + set + { + SetPropertyValueAndDetectChanges(value, ref _permissions, Ps.Value.PermissionsSelector, + //Custom comparer for enumerable + new DelegateEqualityComparer>( + (enum1, enum2) => enum1.UnsortedSequenceEqual(enum2), + enum1 => enum1.GetHashCode())); + } + } + public IEnumerable AllowedSections { get { return _sectionCollection; } diff --git a/src/Umbraco.Core/Models/Membership/UserType.cs b/src/Umbraco.Core/Models/Membership/UserType.cs deleted file mode 100644 index 92e0032bd6..0000000000 --- a/src/Umbraco.Core/Models/Membership/UserType.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System; -using System.Runtime.Serialization; - -namespace Umbraco.Core.Models.Membership -{ - /// - /// Represents the Type for a back-office User - /// - [Serializable] - [DataContract(IsReference = true)] - internal class UserType : UserTypeGroupBase, IUserType - { - } -} \ No newline at end of file diff --git a/src/Umbraco.Core/Models/Membership/UserTypeGroupBase.cs b/src/Umbraco.Core/Models/Membership/UserTypeGroupBase.cs deleted file mode 100644 index b858747eb1..0000000000 --- a/src/Umbraco.Core/Models/Membership/UserTypeGroupBase.cs +++ /dev/null @@ -1,68 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Reflection; -using System.Runtime.Serialization; -using Umbraco.Core.Models.EntityBase; -using Umbraco.Core.Strings; - -namespace Umbraco.Core.Models.Membership -{ - /// - /// Base class representing common fields for back-office user types and groups - /// - internal abstract class UserTypeGroupBase : Entity - { - private string _alias; - private string _name; - private IEnumerable _permissions; - - private static readonly Lazy Ps = new Lazy(); - - private class PropertySelectors - { - public readonly PropertyInfo NameSelector = ExpressionHelper.GetPropertyInfo(x => x.Name); - public readonly PropertyInfo AliasSelector = ExpressionHelper.GetPropertyInfo(x => x.Alias); - public readonly PropertyInfo PermissionsSelector = ExpressionHelper.GetPropertyInfo>(x => x.Permissions); - } - - [DataMember] - public string Alias - { - get { return _alias; } - set - { - SetPropertyValueAndDetectChanges( - value.ToCleanString(CleanStringType.Alias | CleanStringType.UmbracoCase), - ref _alias, - Ps.Value.AliasSelector); - } - } - - [DataMember] - public string Name - { - get { return _name; } - set { SetPropertyValueAndDetectChanges(value, ref _name, Ps.Value.NameSelector); } - } - - /// - /// The set of default permissions for the user type - /// - /// - /// By default each permission is simply a single char but we've made this an enumerable{string} to support a more flexible permissions structure in the future. - /// - [DataMember] - public IEnumerable Permissions - { - get { return _permissions; } - set - { - SetPropertyValueAndDetectChanges(value, ref _permissions, Ps.Value.PermissionsSelector, - //Custom comparer for enumerable - new DelegateEqualityComparer>( - (enum1, enum2) => enum1.UnsortedSequenceEqual(enum2), - enum1 => enum1.GetHashCode())); - } - } - } -} \ No newline at end of file diff --git a/src/Umbraco.Core/Models/Rdbms/UserDto.cs b/src/Umbraco.Core/Models/Rdbms/UserDto.cs index d05cf1086b..73434ef9f3 100644 --- a/src/Umbraco.Core/Models/Rdbms/UserDto.cs +++ b/src/Umbraco.Core/Models/Rdbms/UserDto.cs @@ -22,10 +22,6 @@ namespace Umbraco.Core.Models.Rdbms [Constraint(Default = "0")] public bool NoConsole { get; set; } - [Column("userType")] - [ForeignKey(typeof(UserTypeDto))] - public short Type { get; set; } - [Column("startStructureID")] public int ContentStartId { get; set; } diff --git a/src/Umbraco.Core/Models/Rdbms/UserTypeDto.cs b/src/Umbraco.Core/Models/Rdbms/UserTypeDto.cs index d3268a14fb..cff36f6c32 100644 --- a/src/Umbraco.Core/Models/Rdbms/UserTypeDto.cs +++ b/src/Umbraco.Core/Models/Rdbms/UserTypeDto.cs @@ -1,8 +1,10 @@ -using Umbraco.Core.Persistence; +using System; +using Umbraco.Core.Persistence; using Umbraco.Core.Persistence.DatabaseAnnotations; namespace Umbraco.Core.Models.Rdbms { + [Obsolete("Table no longer exists as of 7.6 - retained only to support migrations from previous versions")] [TableName("umbracoUserType")] [PrimaryKey("id")] [ExplicitColumns] diff --git a/src/Umbraco.Core/Models/UserExtensions.cs b/src/Umbraco.Core/Models/UserExtensions.cs index ece63b4889..7cadc1c892 100644 --- a/src/Umbraco.Core/Models/UserExtensions.cs +++ b/src/Umbraco.Core/Models/UserExtensions.cs @@ -1,5 +1,6 @@ using System; using System.Globalization; +using System.Linq; using Umbraco.Core.Models.Membership; using Umbraco.Core.Services; @@ -80,8 +81,7 @@ namespace Umbraco.Core.Models if (media == null) throw new ArgumentNullException("media"); return HasPathAccess(media.Path, user.StartMediaId, Constants.System.RecycleBinMedia); } - - + /// /// Determines whether this user is an admin. /// @@ -92,7 +92,7 @@ namespace Umbraco.Core.Models public static bool IsAdmin(this IUser user) { if (user == null) throw new ArgumentNullException("user"); - return user.UserType.Alias == "admin"; + return user.Groups != null && user.Groups.Any(x => x.Alias == "admin"); } } } \ No newline at end of file diff --git a/src/Umbraco.Core/Persistence/Factories/UserFactory.cs b/src/Umbraco.Core/Persistence/Factories/UserFactory.cs index a404c43450..3d4b02f804 100644 --- a/src/Umbraco.Core/Persistence/Factories/UserFactory.cs +++ b/src/Umbraco.Core/Persistence/Factories/UserFactory.cs @@ -1,5 +1,4 @@ using System; -using System.Collections.Generic; using System.Globalization; using Umbraco.Core.Models.Membership; using Umbraco.Core.Models.Rdbms; @@ -8,19 +7,12 @@ namespace Umbraco.Core.Persistence.Factories { internal class UserFactory { - private readonly IUserType _userType; - - public UserFactory(IUserType userType) - { - _userType = userType; - } - #region Implementation of IEntityFactory public IUser BuildEntity(UserDto dto) { var guidId = dto.Id.ToGuid(); - var user = new User(_userType); + var user = new User(); try { @@ -68,7 +60,6 @@ namespace Umbraco.Core.Persistence.Factories Password = entity.RawPasswordValue, UserLanguage = entity.Language, UserName = entity.Name, - Type = short.Parse(entity.UserType.Id.ToString(CultureInfo.InvariantCulture)), SecurityStampToken = entity.SecurityStamp, FailedLoginAttempts = entity.FailedPasswordAttempts, LastLockoutDate = entity.LastLockoutDate == DateTime.MinValue ? (DateTime?)null : entity.LastLockoutDate, diff --git a/src/Umbraco.Core/Persistence/Factories/UserGroupFactory.cs b/src/Umbraco.Core/Persistence/Factories/UserGroupFactory.cs index 39a4d13f7f..323ef3319a 100644 --- a/src/Umbraco.Core/Persistence/Factories/UserGroupFactory.cs +++ b/src/Umbraco.Core/Persistence/Factories/UserGroupFactory.cs @@ -8,7 +8,7 @@ namespace Umbraco.Core.Persistence.Factories { internal class UserGroupFactory { - #region Implementation of IEntityFactory + #region Implementation of IEntityFactory public IUserGroup BuildEntity(UserGroupDto dto) { diff --git a/src/Umbraco.Core/Persistence/Factories/UserTypeFactory.cs b/src/Umbraco.Core/Persistence/Factories/UserTypeFactory.cs deleted file mode 100644 index 5f9cfac994..0000000000 --- a/src/Umbraco.Core/Persistence/Factories/UserTypeFactory.cs +++ /dev/null @@ -1,54 +0,0 @@ -using System.Globalization; -using System.Linq; -using Umbraco.Core.Models.Membership; -using Umbraco.Core.Models.Rdbms; - -namespace Umbraco.Core.Persistence.Factories -{ - internal class UserTypeFactory - { - #region Implementation of IEntityFactory - - public IUserType BuildEntity(UserTypeDto dto) - { - var userType = new UserType(); - - try - { - userType.DisableChangeTracking(); - - userType.Alias = dto.Alias; - userType.Id = dto.Id; - userType.Name = dto.Name; - userType.Permissions = dto.DefaultPermissions.IsNullOrWhiteSpace() - ? Enumerable.Empty() - : dto.DefaultPermissions.ToCharArray().Select(x => x.ToString(CultureInfo.InvariantCulture)); - //on initial construction we don't want to have dirty properties tracked - // http://issues.umbraco.org/issue/U4-1946 - userType.ResetDirtyProperties(false); - return userType; - } - finally - { - userType.EnableChangeTracking(); - } - } - - public UserTypeDto BuildDto(IUserType entity) - { - var userType = new UserTypeDto - { - Alias = entity.Alias, - DefaultPermissions = entity.Permissions == null ? "" : string.Join("", entity.Permissions), - Name = entity.Name - }; - - if(entity.HasIdentity) - userType.Id = short.Parse(entity.Id.ToString()); - - return userType; - } - - #endregion - } -} \ No newline at end of file diff --git a/src/Umbraco.Core/Persistence/Mappers/UserMapper.cs b/src/Umbraco.Core/Persistence/Mappers/UserMapper.cs index 0ffd6cbfe1..baefd56db5 100644 --- a/src/Umbraco.Core/Persistence/Mappers/UserMapper.cs +++ b/src/Umbraco.Core/Persistence/Mappers/UserMapper.cs @@ -69,7 +69,6 @@ namespace Umbraco.Core.Persistence.Mappers CacheMap(src => src.StartContentId, dto => dto.ContentStartId); CacheMap(src => src.IsApproved, dto => dto.Disabled); CacheMap(src => src.IsLockedOut, dto => dto.NoConsole); - CacheMap(src => src.UserType, dto => dto.Type); CacheMap(src => src.Language, dto => dto.UserLanguage); } diff --git a/src/Umbraco.Core/Persistence/Mappers/UserTypeMapper.cs b/src/Umbraco.Core/Persistence/Mappers/UserTypeMapper.cs deleted file mode 100644 index 82f362b6f4..0000000000 --- a/src/Umbraco.Core/Persistence/Mappers/UserTypeMapper.cs +++ /dev/null @@ -1,44 +0,0 @@ -using System; -using System.Collections.Concurrent; -using System.Linq.Expressions; -using Umbraco.Core.Models.Membership; -using Umbraco.Core.Models.Rdbms; - -namespace Umbraco.Core.Persistence.Mappers -{ - /// - /// Represents a to DTO mapper used to translate the properties of the public api - /// implementation to that of the database's DTO as sql: [tableName].[columnName]. - /// - [MapperFor(typeof(IUserType))] - [MapperFor(typeof(UserType))] - public sealed class UserTypeMapper : BaseMapper - { - private static readonly ConcurrentDictionary PropertyInfoCacheInstance = new ConcurrentDictionary(); - - //NOTE: its an internal class but the ctor must be public since we're using Activator.CreateInstance to create it - // otherwise that would fail because there is no public constructor. - public UserTypeMapper() - { - BuildMap(); - } - - #region Overrides of BaseMapper - - internal override ConcurrentDictionary PropertyInfoCache - { - get { return PropertyInfoCacheInstance; } - } - - internal override void BuildMap() - { - CacheMap(src => src.Id, dto => dto.Id); - CacheMap(src => src.Alias, dto => dto.Alias); - CacheMap(src => src.Name, dto => dto.Name); - CacheMap(src => src.Permissions, dto => dto.DefaultPermissions); - } - - - #endregion - } -} \ No newline at end of file diff --git a/src/Umbraco.Core/Persistence/Migrations/Initial/BaseDataCreation.cs b/src/Umbraco.Core/Persistence/Migrations/Initial/BaseDataCreation.cs index 68d43a1acd..ac23492263 100644 --- a/src/Umbraco.Core/Persistence/Migrations/Initial/BaseDataCreation.cs +++ b/src/Umbraco.Core/Persistence/Migrations/Initial/BaseDataCreation.cs @@ -43,9 +43,19 @@ namespace Umbraco.Core.Persistence.Migrations.Initial CreateUmbracoUserData(); } - if (tableName.Equals("umbracoUserType")) + if (tableName.Equals("umbracoUserGroup")) { - CreateUmbracoUserTypeData(); + CreateUmbracoUserGroupData(); + } + + if (tableName.Equals("umbracoUser2UserGroup")) + { + CreateUmbracoUser2UserGroupData(); + } + + if (tableName.Equals("umbracoUserGroup2App")) + { + CreateUmbracooUserGroup2AppData(); } if (tableName.Equals("cmsPropertyTypeGroup")) @@ -151,16 +161,35 @@ namespace Umbraco.Core.Persistence.Migrations.Initial private void CreateUmbracoUserData() { - _database.Insert("umbracoUser", "id", false, new UserDto { Id = 0, Disabled = false, NoConsole = false, Type = 1, ContentStartId = -1, MediaStartId = -1, UserName = "Administrator", Login = "admin", Password = "default", Email = "", UserLanguage = "en" }); + _database.Insert("umbracoUser", "id", false, new UserDto { Id = 0, Disabled = false, NoConsole = false, ContentStartId = -1, MediaStartId = -1, UserName = "Administrator", Login = "admin", Password = "default", Email = "", UserLanguage = "en" }); //_database.Update("SET id = @IdAfter WHERE id = @IdBefore AND userLogin = @Login", new { IdAfter = 0, IdBefore = 1, Login = "admin" }); } - private void CreateUmbracoUserTypeData() + private void CreateUmbracoUserGroupData() { - _database.Insert("umbracoUserType", "id", false, new UserTypeDto { Id = 1, Alias = "admin", Name = "Administrators", DefaultPermissions = "CADMOSKTPIURZ:5F7" }); - _database.Insert("umbracoUserType", "id", false, new UserTypeDto { Id = 2, Alias = "writer", Name = "Writer", DefaultPermissions = "CAH:F" }); - _database.Insert("umbracoUserType", "id", false, new UserTypeDto { Id = 3, Alias = "editor", Name = "Editors", DefaultPermissions = "CADMOSKTPUZ:5F" }); - _database.Insert("umbracoUserType", "id", false, new UserTypeDto { Id = 4, Alias = "translator", Name = "Translator", DefaultPermissions = "AF" }); + _database.Insert("umbracoUserGroup", "id", false, new UserGroupDto { Id = 1, Alias = "admin", Name = "Administrators", DefaultPermissions = "CADMOSKTPIURZ:5F7" }); + _database.Insert("umbracoUserGroup", "id", false, new UserGroupDto { Id = 2, Alias = "writer", Name = "Writers", DefaultPermissions = "CAH:F" }); + _database.Insert("umbracoUserGroup", "id", false, new UserGroupDto { Id = 3, Alias = "editor", Name = "Editors", DefaultPermissions = "CADMOSKTPUZ:5F" }); + _database.Insert("umbracoUserGroup", "id", false, new UserGroupDto { Id = 4, Alias = "translator", Name = "Translators", DefaultPermissions = "AF" }); + } + + private void CreateUmbracoUser2UserGroupData() + { + _database.Insert(new User2UserGroupDto { UserGroupId = 1, UserId = 0 }); + } + + private void CreateUmbracooUserGroup2AppData() + { + _database.Insert(new UserGroup2AppDto { UserGroupId = 1, AppAlias = Constants.Applications.Content }); + _database.Insert(new UserGroup2AppDto { UserGroupId = 1, AppAlias = Constants.Applications.Media }); + _database.Insert(new UserGroup2AppDto { UserGroupId = 1, AppAlias = Constants.Applications.Settings }); + _database.Insert(new UserGroup2AppDto { UserGroupId = 1, AppAlias = Constants.Applications.Developer }); + _database.Insert(new UserGroup2AppDto { UserGroupId = 1, AppAlias = Constants.Applications.Users }); + _database.Insert(new UserGroup2AppDto { UserGroupId = 1, AppAlias = Constants.Applications.Members }); + _database.Insert(new UserGroup2AppDto { UserGroupId = 2, AppAlias = Constants.Applications.Content }); + _database.Insert(new UserGroup2AppDto { UserGroupId = 3, AppAlias = Constants.Applications.Content }); + _database.Insert(new UserGroup2AppDto { UserGroupId = 3, AppAlias = Constants.Applications.Media }); + _database.Insert(new UserGroup2AppDto { UserGroupId = 4, AppAlias = Constants.Applications.Translation }); } private void CreateCmsPropertyTypeGroupData() diff --git a/src/Umbraco.Core/Persistence/Migrations/Initial/DatabaseSchemaCreation.cs b/src/Umbraco.Core/Persistence/Migrations/Initial/DatabaseSchemaCreation.cs index 6c06d1f06c..fd7569f409 100644 --- a/src/Umbraco.Core/Persistence/Migrations/Initial/DatabaseSchemaCreation.cs +++ b/src/Umbraco.Core/Persistence/Migrations/Initial/DatabaseSchemaCreation.cs @@ -67,7 +67,7 @@ namespace Umbraco.Core.Persistence.Migrations.Initial {28, typeof (TagDto)}, {29, typeof (TagRelationshipDto)}, - {31, typeof (UserTypeDto)}, + // Removed in 7.6 {31, typeof (UserTypeDto)}, {32, typeof (UserDto)}, {33, typeof (TaskTypeDto)}, {34, typeof (TaskDto)}, diff --git a/src/Umbraco.Core/Persistence/Migrations/Upgrades/TargetVersionSevenSixZero/AddUserGroupTables.cs b/src/Umbraco.Core/Persistence/Migrations/Upgrades/TargetVersionSevenSixZero/AddUserGroupTables.cs index 593a3c9b68..dae7505462 100644 --- a/src/Umbraco.Core/Persistence/Migrations/Upgrades/TargetVersionSevenSixZero/AddUserGroupTables.cs +++ b/src/Umbraco.Core/Persistence/Migrations/Upgrades/TargetVersionSevenSixZero/AddUserGroupTables.cs @@ -99,6 +99,9 @@ namespace Umbraco.Core.Persistence.Migrations.Upgrades.TargetVersionSevenSixZero WHERE u.userType = ut.id ) FROM umbracoUser u"); + + Execute.Sql("UPDATE umbracoUserGroup SET userGroupName = 'Writers' WHERE userGroupName = 'Writer'"); + Execute.Sql("UPDATE umbracoUserGroup SET userGroupName = 'Translators' WHERE userGroupName = 'Translator'"); } private void MigrateUserPermissions() diff --git a/src/Umbraco.Core/Persistence/Repositories/Interfaces/IUserTypeRepository.cs b/src/Umbraco.Core/Persistence/Repositories/Interfaces/IUserTypeRepository.cs deleted file mode 100644 index 43b6709aa7..0000000000 --- a/src/Umbraco.Core/Persistence/Repositories/Interfaces/IUserTypeRepository.cs +++ /dev/null @@ -1,9 +0,0 @@ -using Umbraco.Core.Models.Membership; - -namespace Umbraco.Core.Persistence.Repositories -{ - public interface IUserTypeRepository : IRepositoryQueryable - { - - } -} \ No newline at end of file diff --git a/src/Umbraco.Core/Persistence/Repositories/UserRepository.cs b/src/Umbraco.Core/Persistence/Repositories/UserRepository.cs index f5e3fda7c5..12bdc12976 100644 --- a/src/Umbraco.Core/Persistence/Repositories/UserRepository.cs +++ b/src/Umbraco.Core/Persistence/Repositories/UserRepository.cs @@ -23,13 +23,11 @@ namespace Umbraco.Core.Persistence.Repositories /// internal class UserRepository : PetaPocoRepositoryBase, IUserRepository { - private readonly IUserTypeRepository _userTypeRepository; private readonly CacheHelper _cacheHelper; - public UserRepository(IDatabaseUnitOfWork work, CacheHelper cacheHelper, ILogger logger, ISqlSyntaxProvider sqlSyntax, IUserTypeRepository userTypeRepository) + public UserRepository(IDatabaseUnitOfWork work, CacheHelper cacheHelper, ILogger logger, ISqlSyntaxProvider sqlSyntax) : base(work, cacheHelper, logger, sqlSyntax) { - _userTypeRepository = userTypeRepository; _cacheHelper = cacheHelper; } @@ -45,8 +43,7 @@ namespace Umbraco.Core.Persistence.Repositories if (dto == null) return null; - var userType = _userTypeRepository.Get(dto.Type); - var userFactory = new UserFactory(userType); + var userFactory = new UserFactory(); var user = userFactory.BuildEntity(dto); AssociateGroupsWithUser(user); return user; @@ -152,7 +149,7 @@ namespace Umbraco.Core.Persistence.Repositories protected override void PersistNewItem(IUser entity) { - var userFactory = new UserFactory(entity.UserType); + var userFactory = new UserFactory(); //ensure security stamp if non if (entity.SecurityStamp.IsNullOrWhiteSpace()) @@ -170,7 +167,7 @@ namespace Umbraco.Core.Persistence.Repositories protected override void PersistUpdatedItem(IUser entity) { - var userFactory = new UserFactory(entity.UserType); + var userFactory = new UserFactory(); //ensure security stamp if non if (entity.SecurityStamp.IsNullOrWhiteSpace()) @@ -404,15 +401,9 @@ namespace Umbraco.Core.Persistence.Repositories private IEnumerable ConvertFromDtos(IEnumerable dtos) { - var userTypeIds = dtos.Select(x => Convert.ToInt32(x.Type)).ToArray(); - - var allUserTypes = userTypeIds.Length == 0 ? Enumerable.Empty() : _userTypeRepository.GetAll(userTypeIds); - return dtos.Select(dto => { - var userType = allUserTypes.Single(x => x.Id == dto.Type); - - var userFactory = new UserFactory(userType); + var userFactory = new UserFactory(); return userFactory.BuildEntity(dto); }); } @@ -425,16 +416,5 @@ namespace Umbraco.Core.Persistence.Repositories return userGroupFactory.BuildEntity(dto); }); } - - /// - /// Dispose disposable properties - /// - /// - /// Ensure the unit of work is disposed - /// - protected override void DisposeResources() - { - _userTypeRepository.Dispose(); - } } } \ No newline at end of file diff --git a/src/Umbraco.Core/Persistence/Repositories/UserTypeRepository.cs b/src/Umbraco.Core/Persistence/Repositories/UserTypeRepository.cs deleted file mode 100644 index 1fd94ca357..0000000000 --- a/src/Umbraco.Core/Persistence/Repositories/UserTypeRepository.cs +++ /dev/null @@ -1,114 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using Umbraco.Core.Logging; -using Umbraco.Core.Models.Membership; -using Umbraco.Core.Models.Rdbms; - -using Umbraco.Core.Persistence.Factories; -using Umbraco.Core.Persistence.Querying; -using Umbraco.Core.Persistence.SqlSyntax; -using Umbraco.Core.Persistence.UnitOfWork; - -namespace Umbraco.Core.Persistence.Repositories -{ - /// - /// Represents the UserTypeRepository for doing CRUD operations for - /// - internal class UserTypeRepository : PetaPocoRepositoryBase, IUserTypeRepository - { - public UserTypeRepository(IDatabaseUnitOfWork work, CacheHelper cache, ILogger logger, ISqlSyntaxProvider sqlSyntax) - : base(work, cache, logger, sqlSyntax) - { - } - - #region Overrides of RepositoryBase - - protected override IUserType PerformGet(int id) - { - return GetAll(new[] {id}).FirstOrDefault(); - } - - protected override IEnumerable PerformGetAll(params int[] ids) - { - var userTypeFactory = new UserTypeFactory(); - - var sql = GetBaseQuery(false); - - if (ids.Any()) - { - sql.Where("umbracoUserType.id in (@ids)", new { ids = ids }); - } - else - { - sql.Where(x => x.Id >= 0); - } - - var dtos = Database.Fetch(sql); - return dtos.Select(userTypeFactory.BuildEntity).ToArray(); - } - - protected override IEnumerable PerformGetByQuery(IQuery query) - { - var userTypeFactory = new UserTypeFactory(); - var sqlClause = GetBaseQuery(false); - var translator = new SqlTranslator(sqlClause, query); - var sql = translator.Translate(); - - var dtos = Database.Fetch(sql); - - return dtos.Select(userTypeFactory.BuildEntity).ToArray(); - } - - #endregion - - #region Overrides of PetaPocoRepositoryBase - - protected override Sql GetBaseQuery(bool isCount) - { - var sql = new Sql(); - sql.Select(isCount ? "COUNT(*)" : "*") - .From(); - return sql; - } - - protected override string GetBaseWhereClause() - { - return "umbracoUserType.id = @Id"; - } - - protected override IEnumerable GetDeleteClauses() - { - var list = new List - { - "DELETE FROM umbracoUser WHERE userType = @Id", - "DELETE FROM umbracoUserType WHERE id = @Id" - }; - return list; - } - - protected override Guid NodeObjectTypeId - { - get { throw new NotImplementedException(); } - } - - protected override void PersistNewItem(IUserType entity) - { - var userTypeFactory = new UserTypeFactory(); - var userTypeDto = userTypeFactory.BuildDto(entity); - - var id = Convert.ToInt32(Database.Insert(userTypeDto)); - entity.Id = id; - } - - protected override void PersistUpdatedItem(IUserType entity) - { - var userTypeFactory = new UserTypeFactory(); - var userTypeDto = userTypeFactory.BuildDto(entity); - - Database.Update(userTypeDto); - } - - #endregion - } -} \ No newline at end of file diff --git a/src/Umbraco.Core/Persistence/RepositoryFactory.cs b/src/Umbraco.Core/Persistence/RepositoryFactory.cs index b422dda40d..8d8844deb2 100644 --- a/src/Umbraco.Core/Persistence/RepositoryFactory.cs +++ b/src/Umbraco.Core/Persistence/RepositoryFactory.cs @@ -256,15 +256,6 @@ namespace Umbraco.Core.Persistence _logger, _sqlSyntax); } - public virtual IUserTypeRepository CreateUserTypeRepository(IDatabaseUnitOfWork uow) - { - return new UserTypeRepository( - uow, - //There's not many user types but we query on users all the time so the result needs to be cached - _cacheHelper, - _logger, _sqlSyntax); - } - public virtual IUserGroupRepository CreateUserGroupRepository(IDatabaseUnitOfWork uow) { return new UserGroupRepository( @@ -279,8 +270,7 @@ namespace Umbraco.Core.Persistence uow, //Need to cache users - we look up user information more than anything in the back office! _cacheHelper, - _logger, _sqlSyntax, - CreateUserTypeRepository(uow)); + _logger, _sqlSyntax); } internal virtual IMacroRepository CreateMacroRepository(IDatabaseUnitOfWork uow) diff --git a/src/Umbraco.Core/Security/BackOfficeUserStore.cs b/src/Umbraco.Core/Security/BackOfficeUserStore.cs index fcdf623dba..6c7a1212dc 100644 --- a/src/Umbraco.Core/Security/BackOfficeUserStore.cs +++ b/src/Umbraco.Core/Security/BackOfficeUserStore.cs @@ -68,10 +68,7 @@ namespace Umbraco.Core.Security ThrowIfDisposed(); if (user == null) throw new ArgumentNullException("user"); - var userType = _userService.GetUserTypeByAlias( - user.UserTypeAlias.IsNullOrWhiteSpace() ? _userService.GetDefaultMemberType() : user.UserTypeAlias); - - var member = new User(userType) + var member = new User { DefaultToLiveEditing = false, Email = user.Email, diff --git a/src/Umbraco.Core/Security/UserData.cs b/src/Umbraco.Core/Security/UserData.cs index b1a8b08507..407d2782dd 100644 --- a/src/Umbraco.Core/Security/UserData.cs +++ b/src/Umbraco.Core/Security/UserData.cs @@ -56,9 +56,6 @@ namespace Umbraco.Core.Security [DataMember(Name = "allowedApps")] public string[] AllowedApplications { get; set; } - [DataMember(Name = "groups")] - public string[] Groups { get; set; } - [DataMember(Name = "culture")] public string Culture { get; set; } } diff --git a/src/Umbraco.Core/Services/IMembershipMemberService.cs b/src/Umbraco.Core/Services/IMembershipMemberService.cs index 801f88d9ac..640b90b431 100644 --- a/src/Umbraco.Core/Services/IMembershipMemberService.cs +++ b/src/Umbraco.Core/Services/IMembershipMemberService.cs @@ -46,14 +46,6 @@ namespace Umbraco.Core.Services /// with number of Members or Users for passed in type int GetCount(MemberCountType countType); - /// - /// Gets the default MemberType alias - /// - /// By default we'll return the 'writer', but we need to check it exists. If it doesn't we'll - /// return the first type that is not an admin, otherwise if there's only one we will return that one. - /// Alias of the default MemberType - string GetDefaultMemberType(); - /// /// Checks if a Member with the username exists /// @@ -121,6 +113,14 @@ namespace Umbraco.Core.Services /// Default is True otherwise set to False to not raise events void Save(IEnumerable entities, bool raiseEvents = true); + /// + /// Gets the default MemberType alias + /// + /// By default we'll return the 'writer', but we need to check it exists. If it doesn't we'll + /// return the first type that is not an admin, otherwise if there's only one we will return that one. + /// Alias of the default MemberType + string GetDefaultMemberType(); + /// /// Finds a list of objects by a partial email string /// diff --git a/src/Umbraco.Core/Services/IMembershipUserService.cs b/src/Umbraco.Core/Services/IMembershipUserService.cs index 182d08f9bd..63dc4db37c 100644 --- a/src/Umbraco.Core/Services/IMembershipUserService.cs +++ b/src/Umbraco.Core/Services/IMembershipUserService.cs @@ -18,8 +18,7 @@ namespace Umbraco.Core.Services /// Id of the user once its been created. /// Username of the User to create /// Email of the User to create - /// which the User should be based on /// - IUser CreateUserWithIdentity(string username, string email, IUserType userType); + IUser CreateUserWithIdentity(string username, string email); } } \ No newline at end of file diff --git a/src/Umbraco.Core/Services/IUserService.cs b/src/Umbraco.Core/Services/IUserService.cs index fa69cb30a3..d6df61a7c5 100644 --- a/src/Umbraco.Core/Services/IUserService.cs +++ b/src/Umbraco.Core/Services/IUserService.cs @@ -129,52 +129,6 @@ namespace Umbraco.Core.Services /// IEnumerable GetAllNotInGroup(int groupId); - #region User types - - /// - /// Gets all UserTypes or those specified as parameters - /// - /// Optional Ids of UserTypes to retrieve - /// An enumerable list of - IEnumerable GetAllUserTypes(params int[] ids); - - /// - /// Gets a UserType by its Alias - /// - /// Alias of the UserType to retrieve - /// - IUserType GetUserTypeByAlias(string alias); - - /// - /// Gets a UserType by its Id - /// - /// Id of the UserType to retrieve - /// - IUserType GetUserTypeById(int id); - - /// - /// Gets a UserType by its Name - /// - /// Name of the UserType to retrieve - /// - IUserType GetUserTypeByName(string name); - - /// - /// Saves a UserType - /// - /// UserType to save - /// Optional parameter to raise events. - /// Default is True otherwise set to False to not raise events - void SaveUserType(IUserType userType, bool raiseEvents = true); - - /// - /// Deletes a UserType - /// - /// UserType to delete - void DeleteUserType(IUserType userType); - - #endregion - #region User groups /// diff --git a/src/Umbraco.Core/Services/UserService.cs b/src/Umbraco.Core/Services/UserService.cs index 1a5abb8ee7..11a476a10b 100644 --- a/src/Umbraco.Core/Services/UserService.cs +++ b/src/Umbraco.Core/Services/UserService.cs @@ -34,38 +34,6 @@ namespace Umbraco.Core.Services #region Implementation of IMembershipUserService - /// - /// Gets the default MemberType alias - /// - /// By default we'll return the 'writer', but we need to check it exists. If it doesn't we'll - /// return the first type that is not an admin, otherwise if there's only one we will return that one. - /// Alias of the default MemberType - public string GetDefaultMemberType() - { - using (var repository = RepositoryFactory.CreateUserTypeRepository(UowProvider.GetUnitOfWork())) - { - var types = repository.GetAll().Select(x => x.Alias).ToArray(); - - if (types.Any() == false) - { - throw new EntityNotFoundException("No member types could be resolved"); - } - - if (types.InvariantContains("writer")) - { - return types.First(x => x.InvariantEquals("writer")); - } - - if (types.Length == 1) - { - return types.First(); - } - - //first that is not admin - return types.First(x => x.InvariantEquals("admin") == false); - } - } - /// /// Checks if a User with the username exists /// @@ -85,11 +53,10 @@ namespace Umbraco.Core.Services /// The user will be saved in the database and returned with an Id /// Username of the user to create /// Email of the user to create - /// which the User should be based on /// - public IUser CreateUserWithIdentity(string username, string email, IUserType userType) + public IUser CreateUserWithIdentity(string username, string email) { - return CreateUserWithIdentity(username, email, "", userType); + return CreateUserWithIdentity(username, email, string.Empty); } /// @@ -98,17 +65,11 @@ namespace Umbraco.Core.Services /// Username of the to create /// Email of the to create /// This value should be the encoded/encrypted/hashed value for the password that will be stored in the database - /// Alias of the Type + /// Not used for users /// IUser IMembershipMemberService.CreateWithIdentity(string username, string email, string passwordValue, string memberTypeAlias) { - var userType = GetUserTypeByAlias(memberTypeAlias); - if (userType == null) - { - throw new EntityNotFoundException("The user type " + memberTypeAlias + " could not be resolved"); - } - - return CreateUserWithIdentity(username, email, passwordValue, userType); + return CreateUserWithIdentity(username, email, passwordValue); } /// @@ -119,12 +80,9 @@ namespace Umbraco.Core.Services /// Username of the Member to create /// Email of the Member to create /// This value should be the encoded/encrypted/hashed value for the password that will be stored in the database - /// MemberType the Member should be based on /// - private IUser CreateUserWithIdentity(string username, string email, string passwordValue, IUserType userType) + private IUser CreateUserWithIdentity(string username, string email, string passwordValue) { - if (userType == null) throw new ArgumentNullException("userType"); - //TODO: PUT lock here!! var uow = UowProvider.GetUnitOfWork(); @@ -134,7 +92,7 @@ namespace Umbraco.Core.Services if (loginExists) throw new ArgumentException("Login already exists"); - var user = new User(userType) + var user = new User { DefaultToLiveEditing = false, Email = email, @@ -360,6 +318,12 @@ namespace Umbraco.Core.Services SavedUser.RaiseEvent(new SaveEventArgs(entities, false), this); } + public string GetDefaultMemberType() + { + // User types now being removed, there is no default user type to return + throw new NotImplementedException(); + } + /// /// Finds a list of objects by a partial email string /// @@ -610,108 +574,7 @@ namespace Umbraco.Core.Services repository.AssignGroupPermission(groupId, permission, entityIds); } } - - /// - /// Gets all UserTypes or those specified as parameters - /// - /// Optional Ids of UserTypes to retrieve - /// An enumerable list of - public IEnumerable GetAllUserTypes(params int[] ids) - { - var uow = UowProvider.GetUnitOfWork(); - using (var repository = RepositoryFactory.CreateUserTypeRepository(uow)) - { - return repository.GetAll(ids); - } - } - - /// - /// Gets a UserType by its Alias - /// - /// Alias of the UserType to retrieve - /// - public IUserType GetUserTypeByAlias(string alias) - { - using (var repository = RepositoryFactory.CreateUserTypeRepository(UowProvider.GetUnitOfWork())) - { - var query = Query.Builder.Where(x => x.Alias == alias); - var contents = repository.GetByQuery(query); - return contents.SingleOrDefault(); - } - } - - /// - /// Gets a UserType by its Id - /// - /// Id of the UserType to retrieve - /// - public IUserType GetUserTypeById(int id) - { - using (var repository = RepositoryFactory.CreateUserTypeRepository(UowProvider.GetUnitOfWork())) - { - return repository.Get(id); - } - } - - /// - /// Gets a UserType by its Name - /// - /// Name of the UserType to retrieve - /// - public IUserType GetUserTypeByName(string name) - { - using (var repository = RepositoryFactory.CreateUserTypeRepository(UowProvider.GetUnitOfWork())) - { - var query = Query.Builder.Where(x => x.Name == name); - var contents = repository.GetByQuery(query); - return contents.SingleOrDefault(); - } - } - - /// - /// Saves a UserType - /// - /// UserType to save - /// Optional parameter to raise events. - /// Default is True otherwise set to False to not raise events - public void SaveUserType(IUserType userType, bool raiseEvents = true) - { - if (raiseEvents) - { - if (SavingUserType.IsRaisedEventCancelled(new SaveEventArgs(userType), this)) - return; - } - - var uow = UowProvider.GetUnitOfWork(); - using (var repository = RepositoryFactory.CreateUserTypeRepository(uow)) - { - repository.AddOrUpdate(userType); - uow.Commit(); - } - - if (raiseEvents) - SavedUserType.RaiseEvent(new SaveEventArgs(userType, false), this); - } - - /// - /// Deletes a UserType - /// - /// UserType to delete - public void DeleteUserType(IUserType userType) - { - if (DeletingUserType.IsRaisedEventCancelled(new DeleteEventArgs(userType), this)) - return; - - var uow = UowProvider.GetUnitOfWork(); - using (var repository = RepositoryFactory.CreateUserTypeRepository(uow)) - { - repository.Delete(userType); - uow.Commit(); - } - - DeletedUserType.RaiseEvent(new DeleteEventArgs(userType, false), this); - } - + /// /// Gets all UserGroups or those specified as parameters /// @@ -1124,26 +987,6 @@ namespace Umbraco.Core.Services /// public static event TypedEventHandler> DeletedUser; - /// - /// Occurs before Save - /// - public static event TypedEventHandler> SavingUserType; - - /// - /// Occurs after Save - /// - public static event TypedEventHandler> SavedUserType; - - /// - /// Occurs before Delete - /// - public static event TypedEventHandler> DeletingUserType; - - /// - /// Occurs after Delete - /// - public static event TypedEventHandler> DeletedUserType; - /// /// Occurs before Save /// diff --git a/src/Umbraco.Core/Services/UserServiceExtensions.cs b/src/Umbraco.Core/Services/UserServiceExtensions.cs index a1f480a1f5..6130077771 100644 --- a/src/Umbraco.Core/Services/UserServiceExtensions.cs +++ b/src/Umbraco.Core/Services/UserServiceExtensions.cs @@ -51,17 +51,11 @@ namespace Umbraco.Core.Services if (found == null) { - var writer = userService.GetUserTypeByAlias("writer"); - if (writer == null) - { - throw new InvalidOperationException("Could not map the custom user to an Umbraco user, no 'writer' user type could be found"); - } var user = new User( member.UserName, member.Email ?? Guid.NewGuid().ToString("N") + "@example.com", //email cannot be empty member.ProviderUserKey == null ? member.UserName : member.ProviderUserKey.ToString(), - Guid.NewGuid().ToString("N"), //pass cannot be empty - writer); + Guid.NewGuid().ToString("N")); //pass cannot be empty userService.Save(user); return user; } diff --git a/src/Umbraco.Core/Umbraco.Core.csproj b/src/Umbraco.Core/Umbraco.Core.csproj index 07256fda05..4eb57ab292 100644 --- a/src/Umbraco.Core/Umbraco.Core.csproj +++ b/src/Umbraco.Core/Umbraco.Core.csproj @@ -386,9 +386,7 @@ - - @@ -420,6 +418,7 @@ + @@ -753,10 +752,8 @@ - - @@ -864,7 +861,6 @@ - @@ -886,7 +882,6 @@ - @@ -1061,7 +1056,6 @@ - @@ -1080,7 +1074,6 @@ - @@ -1206,7 +1199,6 @@ - diff --git a/src/Umbraco.Tests/Models/UserTests.cs b/src/Umbraco.Tests/Models/UserTests.cs index 9f974ee9fa..8699a97698 100644 --- a/src/Umbraco.Tests/Models/UserTests.cs +++ b/src/Umbraco.Tests/Models/UserTests.cs @@ -13,7 +13,7 @@ namespace Umbraco.Tests.Models [Test] public void Can_Deep_Clone() { - var item = new User(new UserType(){Id = 3}) + var item = new User() { Id = 3, Key = Guid.NewGuid(), @@ -46,8 +46,6 @@ namespace Umbraco.Tests.Models Assert.AreNotSame(clone, item); Assert.AreEqual(clone, item); - Assert.AreNotSame(clone.UserType, item.UserType); - Assert.AreEqual(clone.UserType, item.UserType); Assert.AreEqual(clone.AllowedSections.Count(), item.AllowedSections.Count()); Assert.AreNotSame(clone.DefaultPermissions, item.DefaultPermissions); @@ -66,7 +64,7 @@ namespace Umbraco.Tests.Models { var ss = new SerializationService(new JsonNetSerializer()); - var item = new User(new UserType() { Id = 3 }) + var item = new User { Id = 3, Key = Guid.NewGuid(), diff --git a/src/Umbraco.Tests/Models/UserTypeTests.cs b/src/Umbraco.Tests/Models/UserTypeTests.cs deleted file mode 100644 index 72aa0b2efc..0000000000 --- a/src/Umbraco.Tests/Models/UserTypeTests.cs +++ /dev/null @@ -1,61 +0,0 @@ -using System; -using System.Diagnostics; -using System.Linq; -using NUnit.Framework; -using Umbraco.Core.Models.Membership; -using Umbraco.Core.Serialization; - -namespace Umbraco.Tests.Models -{ - [TestFixture] - public class UserTypeTests - { - [Test] - public void Can_Deep_Clone() - { - var item = new UserType() - { - Id = 3, - Key = Guid.NewGuid(), - UpdateDate = DateTime.Now, - CreateDate = DateTime.Now, - Name = "Test", - Alias = "test", - Permissions = new[] {"a", "b", "c"} - }; - - var clone = (UserType)item.DeepClone(); - - Assert.AreNotSame(clone, item); - Assert.AreEqual(clone, item); - - //Verify normal properties with reflection - var allProps = clone.GetType().GetProperties(); - foreach (var propertyInfo in allProps) - { - Assert.AreEqual(propertyInfo.GetValue(clone, null), propertyInfo.GetValue(item, null)); - } - } - - [Test] - public void Can_Serialize_Without_Error() - { - var ss = new SerializationService(new JsonNetSerializer()); - - var item = new UserType() - { - Id = 3, - Key = Guid.NewGuid(), - UpdateDate = DateTime.Now, - CreateDate = DateTime.Now, - Name = "Test", - Alias = "test", - Permissions = new[] { "a", "b", "c" } - }; - - var result = ss.ToStream(item); - var json = result.ResultStream.ToJsonString(); - Debug.Print(json); - } - } -} \ No newline at end of file diff --git a/src/Umbraco.Tests/Persistence/BaseTableByTableTest.cs b/src/Umbraco.Tests/Persistence/BaseTableByTableTest.cs index 201fedfcad..97df758000 100644 --- a/src/Umbraco.Tests/Persistence/BaseTableByTableTest.cs +++ b/src/Umbraco.Tests/Persistence/BaseTableByTableTest.cs @@ -559,7 +559,6 @@ namespace Umbraco.Tests.Persistence using (Transaction transaction = Database.GetTransaction()) { DatabaseSchemaHelper.CreateTable(); - DatabaseSchemaHelper.CreateTable(); DatabaseSchemaHelper.CreateTable(); DatabaseSchemaHelper.CreateTable(); DatabaseSchemaHelper.CreateTable(); @@ -611,25 +610,12 @@ namespace Umbraco.Tests.Persistence using (Transaction transaction = Database.GetTransaction()) { - DatabaseSchemaHelper.CreateTable(); DatabaseSchemaHelper.CreateTable(); //transaction.Complete(); } } - [Test] - public void Can_Create_umbracoUserType_Table() - { - - using (Transaction transaction = Database.GetTransaction()) - { - DatabaseSchemaHelper.CreateTable(); - - //transaction.Complete(); - } - } - [Test] public void Can_Create_umbracoUserGroup_Table() { @@ -648,7 +634,6 @@ namespace Umbraco.Tests.Persistence using (Transaction transaction = Database.GetTransaction()) { DatabaseSchemaHelper.CreateTable(); - DatabaseSchemaHelper.CreateTable(); DatabaseSchemaHelper.CreateTable(); DatabaseSchemaHelper.CreateTable(); @@ -656,20 +641,6 @@ namespace Umbraco.Tests.Persistence } } - [Test] - public void Can_Create_umbracoUser2UserGroup_Table() - { - using (Transaction transaction = Database.GetTransaction()) - { - DatabaseSchemaHelper.CreateTable(); - DatabaseSchemaHelper.CreateTable(); - DatabaseSchemaHelper.CreateTable(); - DatabaseSchemaHelper.CreateTable(); - - //transaction.Complete(); - } - } - public void Can_Create_umbracoGroupUser2app_Table() { using (Transaction transaction = Database.GetTransaction()) diff --git a/src/Umbraco.Tests/Persistence/Repositories/NotificationsRepositoryTest.cs b/src/Umbraco.Tests/Persistence/Repositories/NotificationsRepositoryTest.cs index 54387a03f9..e6055adaac 100644 --- a/src/Umbraco.Tests/Persistence/Repositories/NotificationsRepositoryTest.cs +++ b/src/Umbraco.Tests/Persistence/Repositories/NotificationsRepositoryTest.cs @@ -44,7 +44,7 @@ namespace Umbraco.Tests.Persistence.Repositories var unitOfWork = provider.GetUnitOfWork(); var repo = new NotificationsRepository(unitOfWork); - var userDto = new UserDto { ContentStartId = -1, Email = "test" , Login = "test" , MediaStartId = -1, Password = "test" , Type = 1, UserName = "test" , UserLanguage = "en" }; + var userDto = new UserDto { ContentStartId = -1, Email = "test" , Login = "test" , MediaStartId = -1, Password = "test" , UserName = "test" , UserLanguage = "en" }; unitOfWork.Database.Insert(userDto); var userNew = Mock.Of(e => e.Id == userDto.Id); @@ -79,7 +79,7 @@ namespace Umbraco.Tests.Persistence.Repositories for (var i = 0; i < 10; i++) { - var userDto = new UserDto { ContentStartId = -1, Email = "test" + i, Login = "test" + i, MediaStartId = -1, Password = "test", Type = 1, UserName = "test" + i, UserLanguage = "en" }; + var userDto = new UserDto { ContentStartId = -1, Email = "test" + i, Login = "test" + i, MediaStartId = -1, Password = "test", UserName = "test" + i, UserLanguage = "en" }; unitOfWork.Database.Insert(userDto); var userNew = Mock.Of(e => e.Id == userDto.Id); var notification = repo.CreateNotification(userNew, (i % 2 == 0) ? entity1 : entity2, i.ToString(CultureInfo.InvariantCulture)); @@ -106,7 +106,7 @@ namespace Umbraco.Tests.Persistence.Repositories for (var i = 0; i < 10; i++) { - var userDto = new UserDto { ContentStartId = -1, Email = "test" + i, Login = "test" + i, MediaStartId = -1, Password = "test", Type = 1, UserName = "test" + i, UserLanguage = "en" }; + var userDto = new UserDto { ContentStartId = -1, Email = "test" + i, Login = "test" + i, MediaStartId = -1, Password = "test", UserName = "test" + i, UserLanguage = "en" }; unitOfWork.Database.Insert(userDto); var userNew = Mock.Of(e => e.Id == userDto.Id); var notification = repo.CreateNotification(userNew, (i % 2 == 0) ? entity1 : entity2, i.ToString(CultureInfo.InvariantCulture)); @@ -124,7 +124,7 @@ namespace Umbraco.Tests.Persistence.Repositories var unitOfWork = provider.GetUnitOfWork(); var repo = new NotificationsRepository(unitOfWork); - var userDto = new UserDto { ContentStartId = -1, Email = "test", Login = "test", MediaStartId = -1, Password = "test", Type = 1, UserName = "test", UserLanguage = "en" }; + var userDto = new UserDto { ContentStartId = -1, Email = "test", Login = "test", MediaStartId = -1, Password = "test", UserName = "test", UserLanguage = "en" }; unitOfWork.Database.Insert(userDto); var userNew = Mock.Of(e => e.Id == userDto.Id); diff --git a/src/Umbraco.Tests/Persistence/Repositories/UserRepositoryTest.cs b/src/Umbraco.Tests/Persistence/Repositories/UserRepositoryTest.cs index 2a92cb39c8..5c7a87c240 100644 --- a/src/Umbraco.Tests/Persistence/Repositories/UserRepositoryTest.cs +++ b/src/Umbraco.Tests/Persistence/Repositories/UserRepositoryTest.cs @@ -1,13 +1,9 @@ -using System; -using System.Collections.Generic; -using System.Linq; +using System.Linq; using Moq; using NUnit.Framework; using Umbraco.Core; using Umbraco.Core.Logging; using Umbraco.Core.Models.Membership; -using Umbraco.Core.Persistence; - using Umbraco.Core.Persistence.Querying; using Umbraco.Core.Persistence.Repositories; using Umbraco.Core.Persistence.UnitOfWork; @@ -32,10 +28,9 @@ namespace Umbraco.Tests.Persistence.Repositories base.TearDown(); } - private UserRepository CreateRepository(IDatabaseUnitOfWork unitOfWork, out UserTypeRepository userTypeRepository) + private UserRepository CreateRepository(IDatabaseUnitOfWork 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; } @@ -46,11 +41,10 @@ namespace Umbraco.Tests.Persistence.Repositories // Arrange var provider = new PetaPocoUnitOfWorkProvider(Logger); var unitOfWork = provider.GetUnitOfWork(); - UserTypeRepository userTypeRepository; - using (var repository = CreateRepository(unitOfWork, out userTypeRepository)) + using (var repository = CreateRepository(unitOfWork)) { - var user = MockedUser.CreateUser(CreateAndCommitUserType()); + var user = MockedUser.CreateUser(); // Act repository.AddOrUpdate(user); @@ -67,12 +61,11 @@ namespace Umbraco.Tests.Persistence.Repositories // Arrange var provider = new PetaPocoUnitOfWorkProvider(Logger); var unitOfWork = provider.GetUnitOfWork(); - UserTypeRepository userTypeRepository; - using (var repository = CreateRepository(unitOfWork, out userTypeRepository)) + using (var repository = CreateRepository(unitOfWork)) { - var user1 = MockedUser.CreateUser(CreateAndCommitUserType(), "1"); - var use2 = MockedUser.CreateUser(CreateAndCommitUserType(), "2"); + var user1 = MockedUser.CreateUser("1"); + var use2 = MockedUser.CreateUser("2"); // Act repository.AddOrUpdate(user1); @@ -92,10 +85,9 @@ namespace Umbraco.Tests.Persistence.Repositories // Arrange var provider = new PetaPocoUnitOfWorkProvider(Logger); var unitOfWork = provider.GetUnitOfWork(); - UserTypeRepository userTypeRepository; - using (var repository = CreateRepository(unitOfWork, out userTypeRepository)) + using (var repository = CreateRepository(unitOfWork)) { - var user = MockedUser.CreateUser(CreateAndCommitUserType()); + var user = MockedUser.CreateUser(); repository.AddOrUpdate(user); unitOfWork.Commit(); @@ -114,10 +106,9 @@ namespace Umbraco.Tests.Persistence.Repositories // Arrange var provider = new PetaPocoUnitOfWorkProvider(Logger); var unitOfWork = provider.GetUnitOfWork(); - UserTypeRepository userTypeRepository; - using (var repository = CreateRepository(unitOfWork, out userTypeRepository)) + using (var repository = CreateRepository(unitOfWork)) { - var user = MockedUser.CreateUser(CreateAndCommitUserType()); + var user = MockedUser.CreateUser(); repository.AddOrUpdate(user); unitOfWork.Commit(); @@ -163,19 +154,17 @@ namespace Umbraco.Tests.Persistence.Repositories // Arrange var provider = new PetaPocoUnitOfWorkProvider(Logger); var unitOfWork = provider.GetUnitOfWork(); - UserTypeRepository userTypeRepository; - using (var repository = CreateRepository(unitOfWork, out userTypeRepository)) + using (var repository = CreateRepository(unitOfWork)) { - var user = MockedUser.CreateUser(CreateAndCommitUserType()); + var user = MockedUser.CreateUser(); // Act repository.AddOrUpdate(user); unitOfWork.Commit(); var id = user.Id; - using (var utRepo = new UserTypeRepository(unitOfWork, CacheHelper.CreateDisabledCacheHelper(), Logger, SqlSyntax)) - using (var repository2 = new UserRepository(unitOfWork, CacheHelper.CreateDisabledCacheHelper(), Logger, SqlSyntax, utRepo)) + using (var repository2 = new UserRepository(unitOfWork, CacheHelper.CreateDisabledCacheHelper(), Logger, SqlSyntax)) { repository2.Delete(user); unitOfWork.Commit(); @@ -194,8 +183,7 @@ namespace Umbraco.Tests.Persistence.Repositories // // Arrange // var provider = new PetaPocoUnitOfWorkProvider(Logger); // var unitOfWork = provider.GetUnitOfWork(); - // UserTypeRepository userTypeRepository; - //using (var repository = CreateRepository(unitOfWork, out userTypeRepository)) + //using (var repository = CreateRepository(unitOfWork)) //{ // var user = MockedUser.CreateUser(CreateAndCommitUserType()); @@ -224,10 +212,9 @@ namespace Umbraco.Tests.Persistence.Repositories // Arrange var provider = new PetaPocoUnitOfWorkProvider(Logger); var unitOfWork = provider.GetUnitOfWork(); - UserTypeRepository userTypeRepository; - using (var repository = CreateRepository(unitOfWork, out userTypeRepository)) + using (var repository = CreateRepository(unitOfWork)) { - var user = MockedUser.CreateUser(CreateAndCommitUserType()); + var user = MockedUser.CreateUser(); repository.AddOrUpdate(user); unitOfWork.Commit(); @@ -245,8 +232,7 @@ namespace Umbraco.Tests.Persistence.Repositories // Arrange var provider = new PetaPocoUnitOfWorkProvider(Logger); var unitOfWork = provider.GetUnitOfWork(); - UserTypeRepository userTypeRepository; - using (var repository = CreateRepository(unitOfWork, out userTypeRepository)) + using (var repository = CreateRepository(unitOfWork)) { CreateAndCommitMultipleUsers(repository, unitOfWork); @@ -265,8 +251,7 @@ namespace Umbraco.Tests.Persistence.Repositories // Arrange var provider = new PetaPocoUnitOfWorkProvider(Logger); var unitOfWork = provider.GetUnitOfWork(); - UserTypeRepository userTypeRepository; - using (var repository = CreateRepository(unitOfWork, out userTypeRepository)) + using (var repository = CreateRepository(unitOfWork)) { var users = CreateAndCommitMultipleUsers(repository, unitOfWork); @@ -286,8 +271,7 @@ namespace Umbraco.Tests.Persistence.Repositories // Arrange var provider = new PetaPocoUnitOfWorkProvider(Logger); var unitOfWork = provider.GetUnitOfWork(); - UserTypeRepository userTypeRepository; - using (var repository = CreateRepository(unitOfWork, out userTypeRepository)) + using (var repository = CreateRepository(unitOfWork)) { CreateAndCommitMultipleUsers(repository, unitOfWork); @@ -307,8 +291,7 @@ namespace Umbraco.Tests.Persistence.Repositories // Arrange var provider = new PetaPocoUnitOfWorkProvider(Logger); var unitOfWork = provider.GetUnitOfWork(); - UserTypeRepository userTypeRepository; - using (var repository = CreateRepository(unitOfWork, out userTypeRepository)) + using (var repository = CreateRepository(unitOfWork)) { var users = CreateAndCommitMultipleUsers(repository, unitOfWork); @@ -326,8 +309,7 @@ namespace Umbraco.Tests.Persistence.Repositories // Arrange var provider = new PetaPocoUnitOfWorkProvider(Logger); var unitOfWork = provider.GetUnitOfWork(); - UserTypeRepository userTypeRepository; - using (var repository = CreateRepository(unitOfWork, out userTypeRepository)) + using (var repository = CreateRepository(unitOfWork)) { var users = CreateAndCommitMultipleUsers(repository, unitOfWork); @@ -346,12 +328,11 @@ namespace Umbraco.Tests.Persistence.Repositories // Arrange var provider = new PetaPocoUnitOfWorkProvider(Logger); var unitOfWork = provider.GetUnitOfWork(); - using (var utRepo = new UserTypeRepository(unitOfWork, CacheHelper.CreateDisabledCacheHelper(), Logger, SqlSyntax)) - using (var repository = new UserRepository(unitOfWork, CacheHelper.CreateDisabledCacheHelper(), Logger, SqlSyntax, utRepo)) + using (var repository = new UserRepository(unitOfWork, CacheHelper.CreateDisabledCacheHelper(), Logger, SqlSyntax)) { // Act - var user1 = MockedUser.CreateUser(CreateAndCommitUserType(), "1"); + var user1 = MockedUser.CreateUser("1"); repository.AddOrUpdate(user1); unitOfWork.Commit(); @@ -383,27 +364,14 @@ namespace Umbraco.Tests.Persistence.Repositories private IUser[] CreateAndCommitMultipleUsers(IUserRepository repository, IUnitOfWork unitOfWork) { - var user1 = MockedUser.CreateUser(CreateAndCommitUserType(), "1"); - var user2 = MockedUser.CreateUser(CreateAndCommitUserType(), "2"); - var user3 = MockedUser.CreateUser(CreateAndCommitUserType(), "3"); + var user1 = MockedUser.CreateUser("1"); + var user2 = MockedUser.CreateUser("2"); + var user3 = MockedUser.CreateUser("3"); repository.AddOrUpdate(user1); repository.AddOrUpdate(user2); repository.AddOrUpdate(user3); unitOfWork.Commit(); return new IUser[] { user1, user2, user3 }; } - - private IUserType CreateAndCommitUserType() - { - var provider = new PetaPocoUnitOfWorkProvider(Logger); - var unitOfWork = provider.GetUnitOfWork(); - using (var repository = new UserTypeRepository(unitOfWork, CacheHelper.CreateDisabledCacheHelper(), Logger, SqlSyntax)) - { - var userType = MockedUserType.CreateUserType(); - repository.AddOrUpdate(userType); - unitOfWork.Commit(); - return userType; - } - } } } \ No newline at end of file diff --git a/src/Umbraco.Tests/Persistence/Repositories/UserTypeRepositoryTest.cs b/src/Umbraco.Tests/Persistence/Repositories/UserTypeRepositoryTest.cs deleted file mode 100644 index 5efc139931..0000000000 --- a/src/Umbraco.Tests/Persistence/Repositories/UserTypeRepositoryTest.cs +++ /dev/null @@ -1,293 +0,0 @@ -using System.Linq; -using Moq; -using NUnit.Framework; -using Umbraco.Core; -using Umbraco.Core.Logging; -using Umbraco.Core.Models.Membership; -using Umbraco.Core.Persistence; - -using Umbraco.Core.Persistence.Querying; -using Umbraco.Core.Persistence.Repositories; -using Umbraco.Core.Persistence.UnitOfWork; -using Umbraco.Tests.TestHelpers; -using Umbraco.Tests.TestHelpers.Entities; - -namespace Umbraco.Tests.Persistence.Repositories -{ - [DatabaseTestBehavior(DatabaseBehavior.NewDbFileAndSchemaPerTest)] - [TestFixture] - public class UserTypeRepositoryTest : BaseDatabaseFactoryTest - { - [SetUp] - public override void Initialize() - { - base.Initialize(); - } - - [TearDown] - public override void TearDown() - { - base.TearDown(); - } - - private UserTypeRepository CreateRepository(IDatabaseUnitOfWork unitOfWork) - { - return new UserTypeRepository(unitOfWork, CacheHelper.CreateDisabledCacheHelper(), Mock.Of(), SqlSyntax); - } - - [Test] - public void Can_Perform_Add_On_UserTypeRepository() - { - // Arrange - var provider = new PetaPocoUnitOfWorkProvider(Logger); - var unitOfWork = provider.GetUnitOfWork(); - using (var repository = CreateRepository(unitOfWork)) - { - - var userType = MockedUserType.CreateUserType(); - - // Act - repository.AddOrUpdate(userType); - unitOfWork.Commit(); - - // Assert - Assert.That(userType.HasIdentity, Is.True); - } - } - - [Test] - public void Can_Perform_Multiple_Adds_On_UserTypeRepository() - { - // Arrange - var provider = new PetaPocoUnitOfWorkProvider(Logger); - var unitOfWork = provider.GetUnitOfWork(); - using (var repository = CreateRepository(unitOfWork)) - { - - var userType1 = MockedUserType.CreateUserType("1"); - var userType2 = MockedUserType.CreateUserType("2"); - - // Act - repository.AddOrUpdate(userType1); - unitOfWork.Commit(); - repository.AddOrUpdate(userType2); - unitOfWork.Commit(); - - // Assert - Assert.That(userType1.HasIdentity, Is.True); - Assert.That(userType2.HasIdentity, Is.True); - } - } - - [Test] - public void Can_Verify_Fresh_Entity_Is_Not_Dirty() - { - // Arrange - var provider = new PetaPocoUnitOfWorkProvider(Logger); - var unitOfWork = provider.GetUnitOfWork(); - using (var repository = CreateRepository(unitOfWork)) - { - var userType = MockedUserType.CreateUserType(); - repository.AddOrUpdate(userType); - unitOfWork.Commit(); - - // Act - var resolved = repository.Get(userType.Id); - bool dirty = ((UserType) resolved).IsDirty(); - - // Assert - Assert.That(dirty, Is.False); - } - } - - [Test] - public void Can_Perform_Update_On_UserTypeRepository() - { - // Arrange - var provider = new PetaPocoUnitOfWorkProvider(Logger); - var unitOfWork = provider.GetUnitOfWork(); - using (var repository = CreateRepository(unitOfWork)) - { - var userType = MockedUserType.CreateUserType(); - repository.AddOrUpdate(userType); - unitOfWork.Commit(); - - // Act - var resolved = repository.Get(userType.Id); - resolved.Name = "New Name"; - resolved.Permissions = new[]{"Z", "Y", "X"}; - repository.AddOrUpdate(resolved); - unitOfWork.Commit(); - var updatedItem = repository.Get(userType.Id); - - // Assert - Assert.That(updatedItem.Id, Is.EqualTo(resolved.Id)); - Assert.That(updatedItem.Name, Is.EqualTo(resolved.Name)); - Assert.That(updatedItem.Permissions, Is.EqualTo(resolved.Permissions)); - } - } - - [Test] - public void Can_Perform_Delete_On_UserTypeRepository() - { - // Arrange - var provider = new PetaPocoUnitOfWorkProvider(Logger); - var unitOfWork = provider.GetUnitOfWork(); - using (var repository = CreateRepository(unitOfWork)) - { - - var userType = MockedUserType.CreateUserType(); - - // Act - repository.AddOrUpdate(userType); - unitOfWork.Commit(); - var id = userType.Id; - - using (var repository2 = new UserTypeRepository(unitOfWork, CacheHelper.CreateDisabledCacheHelper(), Logger, SqlSyntax)) - { - repository2.Delete(userType); - unitOfWork.Commit(); - - var resolved = repository2.Get(id); - - // Assert - Assert.That(resolved, Is.Null); - } - - } - } - - [Test] - public void Can_Perform_Get_On_UserTypeRepository() - { - // Arrange - var provider = new PetaPocoUnitOfWorkProvider(Logger); - var unitOfWork = provider.GetUnitOfWork(); - using (var repository = CreateRepository(unitOfWork)) - { - var userType = MockedUserType.CreateUserType(); - repository.AddOrUpdate(userType); - unitOfWork.Commit(); - - // Act - var resolved = repository.Get(userType.Id); - - // Assert - Assert.That(resolved.Id, Is.EqualTo(userType.Id)); - //Assert.That(resolved.CreateDate, Is.GreaterThan(DateTime.MinValue)); - //Assert.That(resolved.UpdateDate, Is.GreaterThan(DateTime.MinValue)); - Assert.That(resolved.Name, Is.EqualTo(userType.Name)); - Assert.That(resolved.Alias, Is.EqualTo(userType.Alias)); - Assert.That(resolved.Permissions, Is.EqualTo(userType.Permissions)); - } - } - - [Test] - public void Can_Perform_GetByQuery_On_UserTypeRepository() - { - // Arrange - var provider = new PetaPocoUnitOfWorkProvider(Logger); - var unitOfWork = provider.GetUnitOfWork(); - using (var repository = CreateRepository(unitOfWork)) - { - CreateAndCommitMultipleUserTypes(repository, unitOfWork); - - // Act - var query = Query.Builder.Where(x => x.Alias == "testUserType1"); - var result = repository.GetByQuery(query); - - // Assert - Assert.That(result.Count(), Is.GreaterThanOrEqualTo(1)); - } - } - - [Test] - public void Can_Perform_GetAll_By_Param_Ids_On_UserTypeRepository() - { - // Arrange - var provider = new PetaPocoUnitOfWorkProvider(Logger); - var unitOfWork = provider.GetUnitOfWork(); - using (var repository = CreateRepository(unitOfWork)) - { - var userTypes = CreateAndCommitMultipleUserTypes(repository, unitOfWork); - - // Act - var result = repository.GetAll(userTypes[0].Id, userTypes[1].Id); - - // Assert - Assert.That(result, Is.Not.Null); - Assert.That(result.Any(), Is.True); - Assert.That(result.Count(), Is.EqualTo(2)); - } - } - - [Test] - public void Can_Perform_GetAll_On_UserTypeRepository() - { - // Arrange - var provider = new PetaPocoUnitOfWorkProvider(Logger); - var unitOfWork = provider.GetUnitOfWork(); - using (var repository = CreateRepository(unitOfWork)) - { - CreateAndCommitMultipleUserTypes(repository, unitOfWork); - - // Act - var result = repository.GetAll(); - - // Assert - Assert.That(result, Is.Not.Null); - Assert.That(result.Any(), Is.True); - Assert.That(result.Count(), Is.GreaterThanOrEqualTo(3)); - } - } - - [Test] - public void Can_Perform_Exists_On_UserTypeRepository() - { - // Arrange - var provider = new PetaPocoUnitOfWorkProvider(Logger); - var unitOfWork = provider.GetUnitOfWork(); - using (var repository = CreateRepository(unitOfWork)) - { - var userTypes = CreateAndCommitMultipleUserTypes(repository, unitOfWork); - - // Act - var exists = repository.Exists(userTypes[0].Id); - - // Assert - Assert.That(exists, Is.True); - } - } - - [Test] - public void Can_Perform_Count_On_UserTypeRepository() - { - // Arrange - var provider = new PetaPocoUnitOfWorkProvider(Logger); - var unitOfWork = provider.GetUnitOfWork(); - using (var repository = CreateRepository(unitOfWork)) - { - var userTypes = CreateAndCommitMultipleUserTypes(repository, unitOfWork); - - // Act - var query = Query.Builder.Where(x => x.Alias == "testUserType1" || x.Alias == "testUserType2"); - var result = repository.Count(query); - - // Assert - Assert.That(result, Is.GreaterThanOrEqualTo(2)); - } - } - - private IUserType[] CreateAndCommitMultipleUserTypes(IUserTypeRepository repository, IUnitOfWork unitOfWork) - { - var userType1 = MockedUserType.CreateUserType("1"); - var userType2 = MockedUserType.CreateUserType("2"); - var userType3 = MockedUserType.CreateUserType("3"); - repository.AddOrUpdate(userType1); - repository.AddOrUpdate(userType2); - repository.AddOrUpdate(userType3); - unitOfWork.Commit(); - return new IUserType[] {userType1, userType2, userType3}; - } - } -} \ No newline at end of file diff --git a/src/Umbraco.Tests/Services/ContentServiceTests.cs b/src/Umbraco.Tests/Services/ContentServiceTests.cs index ed4a59bab4..ed6d50c7d9 100644 --- a/src/Umbraco.Tests/Services/ContentServiceTests.cs +++ b/src/Umbraco.Tests/Services/ContentServiceTests.cs @@ -594,7 +594,7 @@ namespace Umbraco.Tests.Services [Test] public void Can_Save_New_Content_With_Explicit_User() { - var user = new User(ServiceContext.UserService.GetUserTypeByAlias("admin")) + var user = new User() { Name = "Test", Email = "test@test.com", diff --git a/src/Umbraco.Tests/Services/SectionServiceTests.cs b/src/Umbraco.Tests/Services/SectionServiceTests.cs index 3bfba08e76..a300d76e60 100644 --- a/src/Umbraco.Tests/Services/SectionServiceTests.cs +++ b/src/Umbraco.Tests/Services/SectionServiceTests.cs @@ -58,14 +58,7 @@ namespace Umbraco.Tests.Services private IUser CreateUser(bool withGroups = false) { - var userType = new UserType - { - Alias = "TypeA", - Name = "Type A", - }; - ServiceContext.UserService.SaveUserType(userType, false); - - var user = new User(userType) + var user = new User { Name = "Test user", Username = "testUser", diff --git a/src/Umbraco.Tests/Services/UserServiceTests.cs b/src/Umbraco.Tests/Services/UserServiceTests.cs index 35013ca69b..4acdff7d2d 100644 --- a/src/Umbraco.Tests/Services/UserServiceTests.cs +++ b/src/Umbraco.Tests/Services/UserServiceTests.cs @@ -39,8 +39,7 @@ namespace Umbraco.Tests.Services { // Arrange var userService = ServiceContext.UserService; - var userType = userService.GetUserTypeByAlias("admin"); - var user = ServiceContext.UserService.CreateUserWithIdentity("test1", "test1@test.com", userType); + var user = ServiceContext.UserService.CreateUserWithIdentity("test1", "test1@test.com"); var contentType = MockedContentTypes.CreateSimpleContentType(); ServiceContext.ContentTypeService.Save(contentType); var content = new[] @@ -66,8 +65,7 @@ namespace Umbraco.Tests.Services { // Arrange var userService = ServiceContext.UserService; - var userType = userService.GetUserTypeByAlias("admin"); - var user = ServiceContext.UserService.CreateUserWithIdentity("test1", "test1@test.com", userType); + var user = ServiceContext.UserService.CreateUserWithIdentity("test1", "test1@test.com"); var contentType = MockedContentTypes.CreateSimpleContentType(); ServiceContext.ContentTypeService.Save(contentType); var content = new[] @@ -99,9 +97,7 @@ namespace Umbraco.Tests.Services [Test] public void Can_Delete_User() { - var userType = MockedUserType.CreateUserType(); - ServiceContext.UserService.SaveUserType(userType); - var user = ServiceContext.UserService.CreateUserWithIdentity("JohnDoe", "john@umbraco.io", userType); + var user = ServiceContext.UserService.CreateUserWithIdentity("JohnDoe", "john@umbraco.io"); ServiceContext.UserService.Delete(user, true); var deleted = ServiceContext.UserService.GetUserById(user.Id); @@ -113,9 +109,7 @@ namespace Umbraco.Tests.Services [Test] public void Disables_User_Instead_Of_Deleting_If_Flag_Not_Set() { - var userType = MockedUserType.CreateUserType(); - ServiceContext.UserService.SaveUserType(userType); - var user = ServiceContext.UserService.CreateUserWithIdentity("JohnDoe", "john@umbraco.io", userType); + var user = ServiceContext.UserService.CreateUserWithIdentity("JohnDoe", "john@umbraco.io"); ServiceContext.UserService.Delete(user); var deleted = ServiceContext.UserService.GetUserById(user.Id); @@ -127,10 +121,8 @@ namespace Umbraco.Tests.Services [Test] public void Exists_By_Username() { - var userType = MockedUserType.CreateUserType(); - ServiceContext.UserService.SaveUserType(userType); - var user = ServiceContext.UserService.CreateUserWithIdentity("JohnDoe", "john@umbraco.io", userType); - var user2 = ServiceContext.UserService.CreateUserWithIdentity("john2@umbraco.io", "john2@umbraco.io", userType); + var user = ServiceContext.UserService.CreateUserWithIdentity("JohnDoe", "john@umbraco.io"); + var user2 = ServiceContext.UserService.CreateUserWithIdentity("john2@umbraco.io", "john2@umbraco.io"); Assert.IsTrue(ServiceContext.UserService.Exists("JohnDoe")); Assert.IsFalse(ServiceContext.UserService.Exists("notFound")); Assert.IsTrue(ServiceContext.UserService.Exists("john2@umbraco.io")); @@ -139,9 +131,7 @@ namespace Umbraco.Tests.Services [Test] public void Get_By_Email() { - var userType = MockedUserType.CreateUserType(); - ServiceContext.UserService.SaveUserType(userType); - var user = ServiceContext.UserService.CreateUserWithIdentity("JohnDoe", "john@umbraco.io", userType); + var user = ServiceContext.UserService.CreateUserWithIdentity("JohnDoe", "john@umbraco.io"); Assert.IsNotNull(ServiceContext.UserService.GetByEmail(user.Email)); Assert.IsNull(ServiceContext.UserService.GetByEmail("do@not.find")); @@ -150,9 +140,7 @@ namespace Umbraco.Tests.Services [Test] public void Get_By_Username() { - var userType = MockedUserType.CreateUserType(); - ServiceContext.UserService.SaveUserType(userType); - var user = ServiceContext.UserService.CreateUserWithIdentity("JohnDoe", "john@umbraco.io", userType); + var user = ServiceContext.UserService.CreateUserWithIdentity("JohnDoe", "john@umbraco.io"); Assert.IsNotNull(ServiceContext.UserService.GetByUsername(user.Username)); Assert.IsNull(ServiceContext.UserService.GetByUsername("notFound")); @@ -161,9 +149,7 @@ namespace Umbraco.Tests.Services [Test] public void Get_By_Username_With_Backslash() { - var userType = MockedUserType.CreateUserType(); - ServiceContext.UserService.SaveUserType(userType); - var user = ServiceContext.UserService.CreateUserWithIdentity("mydomain\\JohnDoe", "john@umbraco.io", userType); + var user = ServiceContext.UserService.CreateUserWithIdentity("mydomain\\JohnDoe", "john@umbraco.io"); Assert.IsNotNull(ServiceContext.UserService.GetByUsername(user.Username)); Assert.IsNull(ServiceContext.UserService.GetByUsername("notFound")); @@ -172,9 +158,7 @@ namespace Umbraco.Tests.Services [Test] public void Get_By_Object_Id() { - var userType = MockedUserType.CreateUserType(); - ServiceContext.UserService.SaveUserType(userType); - var user = ServiceContext.UserService.CreateUserWithIdentity("JohnDoe", "john@umbraco.io", userType); + var user = ServiceContext.UserService.CreateUserWithIdentity("JohnDoe", "john@umbraco.io"); Assert.IsNotNull(ServiceContext.UserService.GetUserById(user.Id)); Assert.IsNull(ServiceContext.UserService.GetUserById(9876)); @@ -183,12 +167,10 @@ namespace Umbraco.Tests.Services [Test] public void Find_By_Email_Starts_With() { - var userType = MockedUserType.CreateUserType(); - ServiceContext.UserService.SaveUserType(userType); - var users = MockedUser.CreateMulipleUsers(userType, 10); + var users = MockedUser.CreateMulipleUsers(10); ServiceContext.UserService.Save(users); //don't find this - var customUser = MockedUser.CreateUser(userType); + var customUser = MockedUser.CreateUser(); customUser.Email = "hello@hello.com"; ServiceContext.UserService.Save(customUser); @@ -201,12 +183,10 @@ namespace Umbraco.Tests.Services [Test] public void Find_By_Email_Ends_With() { - var userType = MockedUserType.CreateUserType(); - ServiceContext.UserService.SaveUserType(userType); - var users = MockedUser.CreateMulipleUsers(userType, 10); + var users = MockedUser.CreateMulipleUsers(10); ServiceContext.UserService.Save(users); //include this - var customUser = MockedUser.CreateUser(userType); + var customUser = MockedUser.CreateUser(); customUser.Email = "hello@test.com"; ServiceContext.UserService.Save(customUser); @@ -219,12 +199,10 @@ namespace Umbraco.Tests.Services [Test] public void Find_By_Email_Contains() { - var userType = MockedUserType.CreateUserType(); - ServiceContext.UserService.SaveUserType(userType); - var users = MockedUser.CreateMulipleUsers(userType, 10); + var users = MockedUser.CreateMulipleUsers(10); ServiceContext.UserService.Save(users); //include this - var customUser = MockedUser.CreateUser(userType); + var customUser = MockedUser.CreateUser(); customUser.Email = "hello@test.com"; ServiceContext.UserService.Save(customUser); @@ -237,12 +215,10 @@ namespace Umbraco.Tests.Services [Test] public void Find_By_Email_Exact() { - var userType = MockedUserType.CreateUserType(); - ServiceContext.UserService.SaveUserType(userType); - var users = MockedUser.CreateMulipleUsers(userType, 10); + var users = MockedUser.CreateMulipleUsers(10); ServiceContext.UserService.Save(users); //include this - var customUser = MockedUser.CreateUser(userType); + var customUser = MockedUser.CreateUser(); customUser.Email = "hello@test.com"; ServiceContext.UserService.Save(customUser); @@ -255,9 +231,7 @@ namespace Umbraco.Tests.Services [Test] public void Get_All_Paged_Users() { - var userType = MockedUserType.CreateUserType(); - ServiceContext.UserService.SaveUserType(userType); - var users = MockedUser.CreateMulipleUsers(userType, 10); + var users = MockedUser.CreateMulipleUsers(10); ServiceContext.UserService.Save(users); int totalRecs; @@ -273,11 +247,9 @@ namespace Umbraco.Tests.Services [Test] public void Count_All_Users() { - var userType = MockedUserType.CreateUserType(); - ServiceContext.UserService.SaveUserType(userType); - var users = MockedUser.CreateMulipleUsers(userType, 10); + var users = MockedUser.CreateMulipleUsers(10); ServiceContext.UserService.Save(users); - var customUser = MockedUser.CreateUser(userType); + var customUser = MockedUser.CreateUser(); ServiceContext.UserService.Save(customUser); var found = ServiceContext.UserService.GetCount(MemberCountType.All); @@ -290,24 +262,20 @@ namespace Umbraco.Tests.Services [Test] public void Count_All_Online_Users() { - var userType = MockedUserType.CreateUserType(); - ServiceContext.UserService.SaveUserType(userType); - var users = MockedUser.CreateMulipleUsers(userType, 10, (i, member) => member.LastLoginDate = DateTime.Now.AddMinutes(i * -2)); + var users = MockedUser.CreateMulipleUsers(10, (i, member) => member.LastLoginDate = DateTime.Now.AddMinutes(i * -2)); ServiceContext.UserService.Save(users); - var customUser = MockedUser.CreateUser(userType); + var customUser = MockedUser.CreateUser(); throw new NotImplementedException(); } [Test] public void Count_All_Locked_Users() { - var userType = MockedUserType.CreateUserType(); - ServiceContext.UserService.SaveUserType(userType); - var users = MockedUser.CreateMulipleUsers(userType, 10, (i, member) => member.IsLockedOut = i % 2 == 0); + var users = MockedUser.CreateMulipleUsers(10, (i, member) => member.IsLockedOut = i % 2 == 0); ServiceContext.UserService.Save(users); - var customUser = MockedUser.CreateUser(userType); + var customUser = MockedUser.CreateUser(); customUser.IsLockedOut = true; ServiceContext.UserService.Save(customUser); @@ -319,12 +287,10 @@ namespace Umbraco.Tests.Services [Test] public void Count_All_Approved_Users() { - var userType = MockedUserType.CreateUserType(); - ServiceContext.UserService.SaveUserType(userType); - var users = MockedUser.CreateMulipleUsers(userType, 10, (i, member) => member.IsApproved = i % 2 == 0); + var users = MockedUser.CreateMulipleUsers(10, (i, member) => member.IsApproved = i % 2 == 0); ServiceContext.UserService.Save(users); - var customUser = MockedUser.CreateUser(userType); + var customUser = MockedUser.CreateUser(); customUser.IsApproved = false; ServiceContext.UserService.Save(customUser); @@ -334,36 +300,20 @@ namespace Umbraco.Tests.Services Assert.AreEqual(6, found); } - [Test] - public void Can_Persist_New_User_Type() - { - // Arrange - var userService = ServiceContext.UserService; - var userType = MockedUserType.CreateUserType(); - - // Act - userService.SaveUserType(userType); - - // Assert - Assert.That(userType.HasIdentity, Is.True); - } - [Test] public void Can_Persist_New_User() { // Arrange var userService = ServiceContext.UserService; - var userType = userService.GetUserTypeByAlias("admin"); // Act - var membershipUser = userService.CreateUserWithIdentity("JohnDoe", "john@umbraco.io", userType); + var membershipUser = userService.CreateUserWithIdentity("JohnDoe", "john@umbraco.io"); // Assert Assert.That(membershipUser.HasIdentity, Is.True); Assert.That(membershipUser.Id, Is.GreaterThan(0)); IUser user = membershipUser as User; Assert.That(user, Is.Not.Null); - Assert.That(user.DefaultPermissions, Is.EqualTo(userType.Permissions)); } [Test] @@ -371,7 +321,6 @@ namespace Umbraco.Tests.Services { // Arrange var userService = ServiceContext.UserService; - var userType = userService.GetUserTypeByAlias("admin"); // Act // NOTE: Normally the hash'ing would be handled in the membership provider, so the service just saves the password @@ -379,7 +328,7 @@ namespace Umbraco.Tests.Services var hash = new HMACSHA1(); hash.Key = Encoding.Unicode.GetBytes(password); var encodedPassword = Convert.ToBase64String(hash.ComputeHash(Encoding.Unicode.GetBytes(password))); - var membershipUser = new User("JohnDoe", "john@umbraco.io", encodedPassword, encodedPassword, userType); + var membershipUser = new User("JohnDoe", "john@umbraco.io", encodedPassword, encodedPassword); userService.Save(membershipUser); // Assert @@ -388,7 +337,6 @@ namespace Umbraco.Tests.Services Assert.That(membershipUser.RawPasswordValue, Is.EqualTo(encodedPassword)); IUser user = membershipUser as User; Assert.That(user, Is.Not.Null); - Assert.That(user.DefaultPermissions, Is.EqualTo(userType.Permissions)); } [Test] @@ -516,8 +464,7 @@ namespace Umbraco.Tests.Services public void Get_By_Profile_Username() { // Arrange - var userType = ServiceContext.UserService.GetUserTypeByAlias("admin"); - var user = ServiceContext.UserService.CreateUserWithIdentity("test1", "test1@test.com", userType); + var user = ServiceContext.UserService.CreateUserWithIdentity("test1", "test1@test.com"); // Act @@ -533,8 +480,7 @@ namespace Umbraco.Tests.Services public void Get_By_Profile_Id() { // Arrange - var userType = ServiceContext.UserService.GetUserTypeByAlias("admin"); - var user = (IUser)ServiceContext.UserService.CreateUserWithIdentity("test1", "test1@test.com", userType); + var user = (IUser)ServiceContext.UserService.CreateUserWithIdentity("test1", "test1@test.com"); // Act @@ -550,8 +496,7 @@ namespace Umbraco.Tests.Services public void Get_User_By_Username() { // Arrange - var userType = ServiceContext.UserService.GetUserTypeByAlias("admin"); - var originalUser = (User)ServiceContext.UserService.CreateUserWithIdentity("test1", "test1@test.com", userType); + var originalUser = (User)ServiceContext.UserService.CreateUserWithIdentity("test1", "test1@test.com"); // Act diff --git a/src/Umbraco.Tests/TestHelpers/Entities/MockedUser.cs b/src/Umbraco.Tests/TestHelpers/Entities/MockedUser.cs index 3ccdd70966..9237574c51 100644 --- a/src/Umbraco.Tests/TestHelpers/Entities/MockedUser.cs +++ b/src/Umbraco.Tests/TestHelpers/Entities/MockedUser.cs @@ -1,21 +1,14 @@ using System; using System.Collections.Generic; -using System.Linq; -using Umbraco.Core.Models; using Umbraco.Core.Models.Membership; namespace Umbraco.Tests.TestHelpers.Entities { public class MockedUser { - internal static User CreateUser(IUserType userType = null, string suffix = "") + internal static User CreateUser(string suffix = "") { - if (userType == null) - { - userType = MockedUserType.CreateUserType(); - } - - var user = new User(userType) + var user = new User { Language = "en", IsApproved = true, @@ -32,14 +25,14 @@ namespace Umbraco.Tests.TestHelpers.Entities return user; } - internal static IEnumerable CreateMulipleUsers(IUserType userType, int amount, Action onCreating = null) + internal static IEnumerable CreateMulipleUsers(int amount, Action onCreating = null) { var list = new List(); for (int i = 0; i < amount; i++) { var name = "Member No-" + i; - var user = new User(name, "test" + i + "@test.com", "test" + i, "test" + i, userType); + var user = new User(name, "test" + i + "@test.com", "test" + i, "test" + i); if (onCreating != null) { diff --git a/src/Umbraco.Tests/TestHelpers/Entities/MockedUserType.cs b/src/Umbraco.Tests/TestHelpers/Entities/MockedUserType.cs deleted file mode 100644 index 153ec40b20..0000000000 --- a/src/Umbraco.Tests/TestHelpers/Entities/MockedUserType.cs +++ /dev/null @@ -1,17 +0,0 @@ -using Umbraco.Core.Models.Membership; - -namespace Umbraco.Tests.TestHelpers.Entities -{ - public class MockedUserType - { - internal static UserType CreateUserType(string suffix = "") - { - return new UserType() - { - Alias = "testUserType" + suffix, - Name = "TestUserType" + suffix, - Permissions = new[]{"A", "B", "C"} - }; - } - } -} \ No newline at end of file diff --git a/src/Umbraco.Tests/UI/LegacyDialogTests.cs b/src/Umbraco.Tests/UI/LegacyDialogTests.cs index 0b1514d8a5..a4a0b98a1f 100644 --- a/src/Umbraco.Tests/UI/LegacyDialogTests.cs +++ b/src/Umbraco.Tests/UI/LegacyDialogTests.cs @@ -27,7 +27,6 @@ namespace Umbraco.Tests.UI } } - [TestCase(typeof(UserTypeTasks), DefaultApps.users)] [TestCase(typeof(XsltTasks), DefaultApps.developer)] [TestCase(typeof(userTasks), DefaultApps.users)] [TestCase(typeof(templateTasks), DefaultApps.settings)] diff --git a/src/Umbraco.Tests/Umbraco.Tests.csproj b/src/Umbraco.Tests/Umbraco.Tests.csproj index c0f43220d9..8f70dcff56 100644 --- a/src/Umbraco.Tests/Umbraco.Tests.csproj +++ b/src/Umbraco.Tests/Umbraco.Tests.csproj @@ -252,7 +252,6 @@ - @@ -353,7 +352,6 @@ - @@ -484,7 +482,6 @@ - diff --git a/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj b/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj index d679384a38..21770434f2 100644 --- a/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj +++ b/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj @@ -2255,7 +2255,6 @@ - diff --git a/src/Umbraco.Web.UI/config/trees.Release.config b/src/Umbraco.Web.UI/config/trees.Release.config index f53e3b7862..c0df67417c 100644 --- a/src/Umbraco.Web.UI/config/trees.Release.config +++ b/src/Umbraco.Web.UI/config/trees.Release.config @@ -29,9 +29,8 @@ - - - + + diff --git a/src/Umbraco.Web.UI/config/trees.config b/src/Umbraco.Web.UI/config/trees.config index cc63766afc..31c5c9f0aa 100644 --- a/src/Umbraco.Web.UI/config/trees.config +++ b/src/Umbraco.Web.UI/config/trees.config @@ -25,9 +25,8 @@ - - - + + diff --git a/src/Umbraco.Web.UI/umbraco/users/EditUserType.aspx b/src/Umbraco.Web.UI/umbraco/users/EditUserType.aspx deleted file mode 100644 index d8671f0596..0000000000 --- a/src/Umbraco.Web.UI/umbraco/users/EditUserType.aspx +++ /dev/null @@ -1,27 +0,0 @@ -<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="EditUserType.aspx.cs" MasterPageFile="../masterpages/umbracoPage.Master" - Inherits="umbraco.cms.presentation.user.EditUserType" %> - -<%@ Register TagPrefix="cc2" Namespace="umbraco.uicontrols" Assembly="controls" %> - - - - - - - - - - - - - - - - - - - diff --git a/src/Umbraco.Web/Cache/CacheRefresherEventHandler.cs b/src/Umbraco.Web/Cache/CacheRefresherEventHandler.cs index 638d124658..b5743df158 100644 --- a/src/Umbraco.Web/Cache/CacheRefresherEventHandler.cs +++ b/src/Umbraco.Web/Cache/CacheRefresherEventHandler.cs @@ -36,9 +36,9 @@ namespace Umbraco.Web.Cache SectionService.Deleted += ApplicationDeleted; SectionService.New += ApplicationNew; - //bind to user / user type events - UserService.SavedUserType += UserServiceSavedUserType; - UserService.DeletedUserType += UserServiceDeletedUserType; + //bind to user / user group events + UserService.SavedUserGroup += UserServiceSavedUserGroup; + UserService.DeletedUserGroup += UserServiceDeletedUserGroup; UserService.SavedUser += UserServiceSavedUser; UserService.DeletedUser += UserServiceDeletedUser; @@ -349,19 +349,6 @@ namespace Umbraco.Web.Cache } #endregion - #region UserType event handlers - static void UserServiceDeletedUserType(IUserService sender, DeleteEventArgs e) - { - e.DeletedEntities.ForEach(x => DistributedCache.Instance.RemoveUserTypeCache(x.Id)); - } - - static void UserServiceSavedUserType(IUserService sender, SaveEventArgs e) - { - e.SavedEntities.ForEach(x => DistributedCache.Instance.RefreshUserTypeCache(x.Id)); - } - - #endregion - #region Dictionary event handlers static void LocalizationServiceSavedDictionaryItem(ILocalizationService sender, SaveEventArgs e) @@ -537,7 +524,17 @@ namespace Umbraco.Web.Cache { e.DeletedEntities.ForEach(x => DistributedCache.Instance.RemoveUserCache(x.Id)); } - + + static void UserServiceSavedUserGroup(IUserService sender, SaveEventArgs e) + { + e.SavedEntities.ForEach(x => DistributedCache.Instance.RefreshUserGroupCache(x.Id)); + } + + static void UserServiceDeletedUserGroup(IUserService sender, DeleteEventArgs e) + { + e.DeletedEntities.ForEach(x => DistributedCache.Instance.RemoveUserGroupCache(x.Id)); + } + private static void InvalidateCacheForPermissionsChange(UserGroupPermission sender) { if (sender.UserGroup != null) diff --git a/src/Umbraco.Web/Cache/DistributedCache.cs b/src/Umbraco.Web/Cache/DistributedCache.cs index 75715565ac..6956df2374 100644 --- a/src/Umbraco.Web/Cache/DistributedCache.cs +++ b/src/Umbraco.Web/Cache/DistributedCache.cs @@ -35,7 +35,6 @@ namespace Umbraco.Web.Cache public const string UserCacheRefresherId = "E057AF6D-2EE6-41F4-8045-3694010F0AA6"; public const string UserGroupCacheRefresherId = "45178038-B232-4FE8-AA1A-F2B949C44762"; public const string UserGroupPermissionsCacheRefresherId = "840AB9C5-5C0B-48DB-A77E-29FE4B80CD3A"; - public const string UserTypeCacheRefresherId = "7E707E21-0195-4522-9A3C-658CC1761BD4"; public const string ContentTypeCacheRefresherId = "6902E22C-9C10-483C-91F3-66B7CAE9E2F5"; public const string LanguageCacheRefresherId = "3E0F95D8-0BE5-44B8-8394-2B8750B62654"; public const string DomainCacheRefresherId = "11290A79-4B57-4C99-AD72-7748A3CF38AF"; @@ -58,8 +57,8 @@ namespace Umbraco.Web.Cache public static readonly Guid MediaCacheRefresherGuid = new Guid(MediaCacheRefresherId); public static readonly Guid MacroCacheRefresherGuid = new Guid(MacroCacheRefresherId); public static readonly Guid UserCacheRefresherGuid = new Guid(UserCacheRefresherId); + public static readonly Guid UserGroupCacheRefresherGuid = new Guid(UserGroupCacheRefresherId); public static readonly Guid UserGroupPermissionsCacheRefresherGuid = new Guid(UserGroupPermissionsCacheRefresherId); - public static readonly Guid UserTypeCacheRefresherGuid = new Guid(UserTypeCacheRefresherId); public static readonly Guid ContentTypeCacheRefresherGuid = new Guid(ContentTypeCacheRefresherId); public static readonly Guid LanguageCacheRefresherGuid = new Guid(LanguageCacheRefresherId); public static readonly Guid DomainCacheRefresherGuid = new Guid(DomainCacheRefresherId); diff --git a/src/Umbraco.Web/Cache/DistributedCacheExtensions.cs b/src/Umbraco.Web/Cache/DistributedCacheExtensions.cs index f7abb7494d..1050517c5a 100644 --- a/src/Umbraco.Web/Cache/DistributedCacheExtensions.cs +++ b/src/Umbraco.Web/Cache/DistributedCacheExtensions.cs @@ -41,25 +41,6 @@ namespace Umbraco.Web.Cache #endregion - #region User type cache - - public static void RemoveUserTypeCache(this DistributedCache dc, int userTypeId) - { - dc.Remove(DistributedCache.UserTypeCacheRefresherGuid, userTypeId); - } - - public static void RefreshUserTypeCache(this DistributedCache dc, int userTypeId) - { - dc.Refresh(DistributedCache.UserTypeCacheRefresherGuid, userTypeId); - } - - public static void RefreshAllUserTypeCache(this DistributedCache dc) - { - dc.RefreshAll(DistributedCache.UserTypeCacheRefresherGuid); - } - - #endregion - #region User cache public static void RemoveUserCache(this DistributedCache dc, int userId) @@ -75,7 +56,26 @@ namespace Umbraco.Web.Cache public static void RefreshAllUserCache(this DistributedCache dc) { dc.RefreshAll(DistributedCache.UserCacheRefresherGuid); - } + } + + #endregion + + #region User group cache + + public static void RemoveUserGroupCache(this DistributedCache dc, int userId) + { + dc.Remove(DistributedCache.UserGroupCacheRefresherGuid, userId); + } + + public static void RefreshUserGroupCache(this DistributedCache dc, int userId) + { + dc.Refresh(DistributedCache.UserGroupCacheRefresherGuid, userId); + } + + public static void RefreshAllUserGroupCache(this DistributedCache dc) + { + dc.RefreshAll(DistributedCache.UserGroupCacheRefresherGuid); + } #endregion diff --git a/src/Umbraco.Web/Cache/UserTypeCacheRefresher.cs b/src/Umbraco.Web/Cache/UserTypeCacheRefresher.cs deleted file mode 100644 index ca3f93c068..0000000000 --- a/src/Umbraco.Web/Cache/UserTypeCacheRefresher.cs +++ /dev/null @@ -1,53 +0,0 @@ -using System; -using Umbraco.Core; -using Umbraco.Core.Cache; -using Umbraco.Core.Models.Membership; - -using Umbraco.Core.Persistence.Repositories; - -namespace Umbraco.Web.Cache -{ - /// - /// Handles User type cache invalidation/refreshing - /// - public sealed class UserTypeCacheRefresher : CacheRefresherBase - { - protected override UserTypeCacheRefresher Instance - { - get { return this; } - } - - public override Guid UniqueIdentifier - { - get { return Guid.Parse(DistributedCache.UserTypeCacheRefresherId); } - } - - public override string Name - { - get { return "User type cache refresher"; } - } - - public override void RefreshAll() - { - ClearAllIsolatedCacheByEntityType(); - base.RefreshAll(); - } - - public override void Refresh(int id) - { - var userTypeCache = ApplicationContext.Current.ApplicationCache.IsolatedRuntimeCache.GetCache(); - if (userTypeCache) - userTypeCache.Result.ClearCacheItem(RepositoryBase.GetCacheIdKey(id)); - base.Refresh(id); - } - - public override void Remove(int id) - { - var userTypeCache = ApplicationContext.Current.ApplicationCache.IsolatedRuntimeCache.GetCache(); - if (userTypeCache) - userTypeCache.Result.ClearCacheItem(RepositoryBase.GetCacheIdKey(id)); - base.Remove(id); - } - - } -} \ No newline at end of file diff --git a/src/Umbraco.Web/Editors/BackOfficeController.cs b/src/Umbraco.Web/Editors/BackOfficeController.cs index 199ffd9bed..bc596a8a0a 100644 --- a/src/Umbraco.Web/Editors/BackOfficeController.cs +++ b/src/Umbraco.Web/Editors/BackOfficeController.cs @@ -604,60 +604,49 @@ namespace Umbraco.Web.Editors } else { - var defaultUserType = autoLinkOptions.GetDefaultUserType(UmbracoContext, loginInfo); - var userType = Services.UserService.GetUserTypeByAlias(defaultUserType); - if (userType == null) + if (loginInfo.Email.IsNullOrWhiteSpace()) throw new InvalidOperationException("The Email value cannot be null"); + if (loginInfo.ExternalIdentity.Name.IsNullOrWhiteSpace()) throw new InvalidOperationException("The Name value cannot be null"); + + var autoLinkUser = new BackOfficeIdentityUser { - ViewData[TokenExternalSignInError] = new[] { "Could not auto-link this account, the specified User Type does not exist: " + defaultUserType }; + Email = loginInfo.Email, + Name = loginInfo.ExternalIdentity.Name, + AllowedSections = autoLinkOptions.GetDefaultAllowedSections(UmbracoContext, loginInfo), + Culture = autoLinkOptions.GetDefaultCulture(UmbracoContext, loginInfo), + UserName = loginInfo.Email + }; + + //call the callback if one is assigned + if (autoLinkOptions.OnAutoLinking != null) + { + autoLinkOptions.OnAutoLinking(autoLinkUser, loginInfo); + } + + var userCreationResult = await UserManager.CreateAsync(autoLinkUser); + + if (userCreationResult.Succeeded == false) + { + ViewData[TokenExternalSignInError] = userCreationResult.Errors; } else { - - if (loginInfo.Email.IsNullOrWhiteSpace()) throw new InvalidOperationException("The Email value cannot be null"); - if (loginInfo.ExternalIdentity.Name.IsNullOrWhiteSpace()) throw new InvalidOperationException("The Name value cannot be null"); - - var autoLinkUser = new BackOfficeIdentityUser() + var linkResult = await UserManager.AddLoginAsync(autoLinkUser.Id, loginInfo.Login); + if (linkResult.Succeeded == false) { - Email = loginInfo.Email, - Name = loginInfo.ExternalIdentity.Name, - UserTypeAlias = userType.Alias, - AllowedSections = autoLinkOptions.GetDefaultAllowedSections(UmbracoContext, loginInfo), - Culture = autoLinkOptions.GetDefaultCulture(UmbracoContext, loginInfo), - UserName = loginInfo.Email - }; + ViewData[TokenExternalSignInError] = linkResult.Errors; - //call the callback if one is assigned - if (autoLinkOptions.OnAutoLinking != null) - { - autoLinkOptions.OnAutoLinking(autoLinkUser, loginInfo); - } - - var userCreationResult = await UserManager.CreateAsync(autoLinkUser); - - if (userCreationResult.Succeeded == false) - { - ViewData[TokenExternalSignInError] = userCreationResult.Errors; + //If this fails, we should really delete the user since it will be in an inconsistent state! + var deleteResult = await UserManager.DeleteAsync(autoLinkUser); + if (deleteResult.Succeeded == false) + { + //DOH! ... this isn't good, combine all errors to be shown + ViewData[TokenExternalSignInError] = linkResult.Errors.Concat(deleteResult.Errors); + } } else { - var linkResult = await UserManager.AddLoginAsync(autoLinkUser.Id, loginInfo.Login); - if (linkResult.Succeeded == false) - { - ViewData[TokenExternalSignInError] = linkResult.Errors; - - //If this fails, we should really delete the user since it will be in an inconsistent state! - var deleteResult = await UserManager.DeleteAsync(autoLinkUser); - if (deleteResult.Succeeded == false) - { - //DOH! ... this isn't good, combine all errors to be shown - ViewData[TokenExternalSignInError] = linkResult.Errors.Concat(deleteResult.Errors); - } - } - else - { - //sign in - await SignInManager.SignInAsync(autoLinkUser, isPersistent: false, rememberBrowser: false); - } + //sign in + await SignInManager.SignInAsync(autoLinkUser, isPersistent: false, rememberBrowser: false); } } } diff --git a/src/Umbraco.Web/Editors/DashboardController.cs b/src/Umbraco.Web/Editors/DashboardController.cs index d668399e83..e4c94965b7 100644 --- a/src/Umbraco.Web/Editors/DashboardController.cs +++ b/src/Umbraco.Web/Editors/DashboardController.cs @@ -37,13 +37,12 @@ namespace Umbraco.Web.Editors throw new HttpResponseException(HttpStatusCode.InternalServerError); var user = Security.CurrentUser; - var userType = user.UserType.Alias; var allowedSections = string.Join(",", user.AllowedSections); var language = user.Language; var version = UmbracoVersion.GetSemanticVersion().ToSemanticString(); - var url = string.Format(baseUrl + "{0}?section={0}&type={1}&allowed={2}&lang={3}&version={4}", section, userType, allowedSections, language, version); - var key = "umbraco-dynamic-dashboard-" + userType + language + allowedSections.Replace(",", "-") + section; + var url = string.Format(baseUrl + "{0}?section={0}&allowed={1}&lang={2}&version={3}", section, allowedSections, language, version); + var key = "umbraco-dynamic-dashboard-" + language + allowedSections.Replace(",", "-") + section; var content = ApplicationContext.ApplicationCache.RuntimeCache.GetCacheItem(key); var result = new JObject(); diff --git a/src/Umbraco.Web/Editors/DashboardSecurity.cs b/src/Umbraco.Web/Editors/DashboardSecurity.cs index a8f5e44ef2..879fd468e0 100644 --- a/src/Umbraco.Web/Editors/DashboardSecurity.cs +++ b/src/Umbraco.Web/Editors/DashboardSecurity.cs @@ -76,33 +76,6 @@ namespace Umbraco.Web.Editors } } - //Check if this item as any grant arguments, if so check if the user is one of the user types approved, if so they will - // be allowed to see it (so far) - if (grantedTypes.Any()) - { - var allApprovedUserTypes = grantedTypes.SelectMany(g => g.Value.Split(new[] {','}, StringSplitOptions.RemoveEmptyEntries)).ToArray(); - if (allApprovedUserTypes.InvariantContains(user.UserType.Alias)) - { - allowedSoFar = true; - } - } - else - { - //if there are not explicit grant types then everyone is allowed so far and we'll only disallow on a deny basis - allowedSoFar = true; - } - - //Check if this item as any deny arguments, if so check if the user is one of the user types approved, if so they will - // be denied to see it no matter what - if (denyTypes.Any()) - { - var allDeniedUserTypes = denyTypes.SelectMany(g => g.Value.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries)).ToArray(); - if (allDeniedUserTypes.InvariantContains(user.UserType.Alias)) - { - allowedSoFar = false; - } - } - return allowedSoFar; } } diff --git a/src/Umbraco.Web/Editors/RedirectUrlManagementController.cs b/src/Umbraco.Web/Editors/RedirectUrlManagementController.cs index 8ccfd6dde7..9fb7a63c9f 100644 --- a/src/Umbraco.Web/Editors/RedirectUrlManagementController.cs +++ b/src/Umbraco.Web/Editors/RedirectUrlManagementController.cs @@ -72,8 +72,7 @@ namespace Umbraco.Web.Editors var userIsAdmin = Umbraco.UmbracoContext.Security.CurrentUser.IsAdmin(); if (userIsAdmin == false) { - var errorMessage = string.Format("User of type {0} is not allowed to toggle the URL tracker", - Umbraco.UmbracoContext.Security.CurrentUser.UserType.Alias); + var errorMessage = "User is not a member of the administrators group and so is not allowed to toggle the URL tracker"; LogHelper.Debug(errorMessage); throw new UserAuthorizationException(errorMessage); } diff --git a/src/Umbraco.Web/Models/ContentEditing/UserDetail.cs b/src/Umbraco.Web/Models/ContentEditing/UserDetail.cs index d27736576f..ada24ee38c 100644 --- a/src/Umbraco.Web/Models/ContentEditing/UserDetail.cs +++ b/src/Umbraco.Web/Models/ContentEditing/UserDetail.cs @@ -21,10 +21,6 @@ namespace Umbraco.Web.Models.ContentEditing [DataMember(Name = "emailHash")] public string EmailHash { get; set; } - [DataMember(Name = "userType", IsRequired = true)] - [Required] - public string UserType { get; set; } - /// /// Gets/sets the number of seconds for the user's auth ticket to expire /// diff --git a/src/Umbraco.Web/Models/Mapping/UserModelMapper.cs b/src/Umbraco.Web/Models/Mapping/UserModelMapper.cs index 72093b19a8..213abc5afc 100644 --- a/src/Umbraco.Web/Models/Mapping/UserModelMapper.cs +++ b/src/Umbraco.Web/Models/Mapping/UserModelMapper.cs @@ -1,4 +1,5 @@ using System; +using System.Linq; using AutoMapper; using Umbraco.Core; using Umbraco.Core.Models.Mapping; @@ -17,7 +18,6 @@ namespace Umbraco.Web.Models.Mapping { config.CreateMap() .ForMember(detail => detail.UserId, opt => opt.MapFrom(user => GetIntId(user.Id))) - .ForMember(detail => detail.UserType, opt => opt.MapFrom(user => user.UserType.Alias)) .ForMember(detail => detail.StartContentId, opt => opt.MapFrom(user => user.StartContentId)) .ForMember(detail => detail.StartMediaId, opt => opt.MapFrom(user => user.StartMediaId)) .ForMember(detail => detail.Culture, opt => opt.MapFrom(user => user.GetUserCulture(applicationContext.Services.TextService))) @@ -28,7 +28,6 @@ namespace Umbraco.Web.Models.Mapping config.CreateMap() .ForMember(detail => detail.UserId, opt => opt.MapFrom(user => user.Id)) - .ForMember(detail => detail.UserType, opt => opt.MapFrom(user => user.UserTypeAlias)) .ForMember(detail => detail.StartContentId, opt => opt.MapFrom(user => user.StartContentId)) .ForMember(detail => detail.StartMediaId, opt => opt.MapFrom(user => user.StartMediaId)) .ForMember(detail => detail.Culture, opt => opt.MapFrom(user => user.Culture)) @@ -46,7 +45,7 @@ namespace Umbraco.Web.Models.Mapping .ForMember(detail => detail.Id, opt => opt.MapFrom(user => user.Id)) .ForMember(detail => detail.AllowedApplications, opt => opt.MapFrom(user => user.AllowedSections)) .ForMember(detail => detail.RealName, opt => opt.MapFrom(user => user.Name)) - .ForMember(detail => detail.Roles, opt => opt.MapFrom(user => new[] {user.UserType.Alias})) + .ForMember(detail => detail.Roles, opt => opt.MapFrom(user => user.Groups.Select(x => x.Name))) .ForMember(detail => detail.StartContentNode, opt => opt.MapFrom(user => user.StartContentId)) .ForMember(detail => detail.StartMediaNode, opt => opt.MapFrom(user => user.StartMediaId)) .ForMember(detail => detail.Username, opt => opt.MapFrom(user => user.Username)) diff --git a/src/Umbraco.Web/Security/WebSecurity.cs b/src/Umbraco.Web/Security/WebSecurity.cs index f3b0eaeb5f..3cff7344ad 100644 --- a/src/Umbraco.Web/Security/WebSecurity.cs +++ b/src/Umbraco.Web/Security/WebSecurity.cs @@ -229,9 +229,6 @@ namespace Umbraco.Web.Security //if we already have a user object in Umbraco we don't need to do anything, otherwise we need to create a mapped Umbraco account. if (user != null) return user; - //we need to create an Umbraco IUser of a 'writer' type with access to only content - this was how v6 operates. - var writer = _applicationContext.Services.UserService.GetUserTypeByAlias("writer"); - var email = membershipUser.Email; if (email.IsNullOrWhiteSpace()) { @@ -239,7 +236,7 @@ namespace Umbraco.Web.Security email = Guid.NewGuid().ToString("N") + "@example.com"; } - user = new Core.Models.Membership.User(writer) + user = new Core.Models.Membership.User { Email = email, Language = GlobalSettings.DefaultUILanguage, diff --git a/src/Umbraco.Web/Umbraco.Web.csproj b/src/Umbraco.Web/Umbraco.Web.csproj index a324e39af4..c2b5665f4c 100644 --- a/src/Umbraco.Web/Umbraco.Web.csproj +++ b/src/Umbraco.Web/Umbraco.Web.csproj @@ -476,7 +476,6 @@ - @@ -1856,18 +1855,10 @@ - XmlTree.xsd - - EditUserType.aspx - ASPXCodeBehind - - - EditUserType.aspx - NodePermissions.ascx ASPXCodeBehind @@ -1886,7 +1877,6 @@ PermissionsHandler.asmx - CacheRefresher.asmx @@ -2151,9 +2141,6 @@ ASPXCodeBehind - - ASPXCodeBehind - Form diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/Trees/UserTypes.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/Trees/UserTypes.cs deleted file mode 100644 index 54dd21738b..0000000000 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/Trees/UserTypes.cs +++ /dev/null @@ -1,53 +0,0 @@ -using System; -using umbraco.BusinessLogic; -using System.Collections.Generic; -using umbraco.businesslogic; -using Umbraco.Core; - -namespace umbraco.cms.presentation.Trees -{ - [Tree(Constants.Applications.Users, "userTypes", "User Types", sortOrder: 1)] - public class UserTypes : BaseTree - { - - public UserTypes(string application) : base(application) { } - - public override void RenderJS(ref System.Text.StringBuilder Javascript) - { - Javascript.Append( - @" -function openUserTypes(id) { - UmbClientMgr.contentFrame('users/EditUserType.aspx?id=' + id); -} -"); - } - - public override void Render(ref XmlTree tree) - { - List userTypes = UserType.GetAllUserTypes(); - foreach (UserType userType in userTypes) - { - if (userType.Id > 1) //don't show the admin user type, they should always have full permissions - { - XmlTreeNode node = XmlTreeNode.Create(this); - node.NodeID = userType.Id.ToString(); - node.Action = string.Format("javascript:openUserTypes({0})", userType.Id.ToString()); - node.Icon = "icon-users"; - node.Text = userType.Name; - - OnBeforeNodeRender(ref tree, ref node, EventArgs.Empty); - if (node != null) - { - tree.Add(node); - OnAfterNodeRender(ref tree, ref node, EventArgs.Empty); - } - } - } - } - - protected override void CreateRootNode(ref XmlTreeNode rootNode) - { - rootNode.Text = ui.Text("user", "userTypes"); - } - } -} diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/developer/RelationTypes/RelationTypesWebService.asmx.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/developer/RelationTypes/RelationTypesWebService.asmx.cs index 2b775ed797..2b5965d2f3 100644 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/developer/RelationTypes/RelationTypesWebService.asmx.cs +++ b/src/Umbraco.Web/umbraco.presentation/umbraco/developer/RelationTypes/RelationTypesWebService.asmx.cs @@ -1,10 +1,11 @@ using System.Web.Services; using Umbraco.Core; +using Umbraco.Core.Models; using Umbraco.Web; namespace umbraco.cms.presentation.developer.RelationTypes { - /// + /// /// Webservice to delete relation types, this allows deletion via a javacscript call hooked into the tree UI /// [WebService(Namespace = "http://tempuri.org/")] @@ -22,7 +23,7 @@ namespace umbraco.cms.presentation.developer.RelationTypes { var user = UmbracoContext.Current.Security.CurrentUser; - if (user.UserType.Name == "Administrators") + if (user.IsAdmin()) { var relationService = ApplicationContext.Current.Services.RelationService; var relationType = relationService.GetRelationTypeById(relationTypeId); diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/dialogs/sendToTranslation.aspx.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/dialogs/sendToTranslation.aspx.cs index c02baaaa7b..a310764498 100644 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/dialogs/sendToTranslation.aspx.cs +++ b/src/Umbraco.Web/umbraco.presentation/umbraco/dialogs/sendToTranslation.aspx.cs @@ -1,4 +1,5 @@ using System; +using System.Linq; using System.Data; using System.Configuration; using System.Collections; @@ -70,7 +71,7 @@ namespace umbraco.presentation.dialogs // Translators foreach (var u in BusinessLogic.User.getAll()) - if (u.UserType.Alias.ToLower() == "translator" || UserHasTranslatePermission(u, _currentPage)) + if (u.GetGroups().Select(x => x.ToLower()).Contains("translators") || UserHasTranslatePermission(u, _currentPage)) translator.Items.Add(new ListItem(u.Name, u.Id.ToString())); if (translator.Items.Count == 0) { 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 510a526a0e..83c30ddc25 100644 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/users/EditUser.aspx.cs +++ b/src/Umbraco.Web/umbraco.presentation/umbraco/users/EditUser.aspx.cs @@ -93,19 +93,6 @@ namespace umbraco.cms.presentation.user throw new Exception("Admin users can only be edited by admins"); } - // Populate usertype list - foreach (UserType ut in UserType.getAll) - { - if (CurrentUser.IsAdmin() || ut.Alias != "admin") - { - ListItem li = new ListItem(ui.Text("user", ut.Name.ToLower(), UmbracoUser), ut.Id.ToString()); - if (ut.Id == u.UserType.Id) - li.Selected = true; - - userType.Items.Add(li); - } - } - var userCulture = UserExtensions.GetUserCulture(u.Language, Services.TextService); // Populate ui language lsit @@ -467,7 +454,6 @@ namespace umbraco.cms.presentation.user // ok since the membership provider might be storing these details someplace totally different! But we want to keep our UI in sync. u.Name = uname.Text.Trim(); u.Language = userLanguage.SelectedValue; - u.UserType = UserType.GetUserType(int.Parse(userType.SelectedValue)); u.Email = email.Text.Trim(); u.LoginName = lname.Text; u.Disabled = Disabled.Checked; diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/users/EditUserType.aspx b/src/Umbraco.Web/umbraco.presentation/umbraco/users/EditUserType.aspx deleted file mode 100644 index d8671f0596..0000000000 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/users/EditUserType.aspx +++ /dev/null @@ -1,27 +0,0 @@ -<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="EditUserType.aspx.cs" MasterPageFile="../masterpages/umbracoPage.Master" - Inherits="umbraco.cms.presentation.user.EditUserType" %> - -<%@ Register TagPrefix="cc2" Namespace="umbraco.uicontrols" Assembly="controls" %> - - - - - - - - - - - - - - - - - - - diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/users/EditUserType.aspx.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/users/EditUserType.aspx.cs deleted file mode 100644 index b6796e45fa..0000000000 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/users/EditUserType.aspx.cs +++ /dev/null @@ -1,121 +0,0 @@ -using System; -using System.Data; -using System.Configuration; -using System.Collections; -using System.Web; -using System.Web.Security; -using System.Web.UI; -using System.Web.UI.WebControls; -using System.Web.UI.WebControls.WebParts; -using System.Web.UI.HtmlControls; -using umbraco.BasePages; -using System.Collections.Generic; -using umbraco.interfaces; -using umbraco.BusinessLogic.Actions; -using umbraco.BusinessLogic; -using umbraco.uicontrols; -using umbraco.cms.presentation.Trees; -using Umbraco.Core.IO; - -namespace umbraco.cms.presentation.user -{ - public partial class EditUserType : UmbracoEnsuredPage - { - public EditUserType() - { - CurrentApp = BusinessLogic.DefaultApps.users.ToString(); - } - protected void Page_Load(object sender, EventArgs e) - { - pnlUmbraco.Text = umbraco.ui.Text("usertype", base.getUser()); - - var save = pnlUmbraco.Menu.NewButton(); - save.Click += save_Click; - save.ID = "save"; - save.ToolTip = ui.Text("save"); - save.Text = ui.Text("save"); - - pp_alias.Text = umbraco.ui.Text("usertype", base.getUser()) + " " + umbraco.ui.Text("alias", base.getUser()); - pp_name.Text = umbraco.ui.Text("usertype", base.getUser()) + " " + umbraco.ui.Text("name", base.getUser()); - - pp_rights.Text = umbraco.ui.Text("default", base.getUser()) + " " + umbraco.ui.Text("rights", base.getUser()); - - //ensure we have a query string - if (string.IsNullOrEmpty(Request.QueryString["id"])) - return; - //ensuer it is an integer - if (!int.TryParse(Request.QueryString["id"], out m_userTypeID)) - return; - - if (!IsPostBack) - { - BindActions(); - - ClientTools - .SetActiveTreeType(TreeDefinitionCollection.Instance.FindTree().Tree.Alias) - .SyncTree(m_userTypeID.ToString(), false); - } - - } - - void save_Click(object sender, EventArgs e) - { - UserType userType = CurrentUserType; - userType.Name = txtUserTypeName.Text; - string actions = ""; - - foreach (ListItem li in cbl_rights.Items) { - if (li.Selected) - actions += li.Value; - } - - userType.DefaultPermissions = actions; - userType.Save(); - - ClientTools.ShowSpeechBubble(speechBubbleIcon.save, ui.Text("speechBubbles", "editUserTypeSaved", base.getUser()), ""); - } - - protected List CurrentUserTypeActions - { - get - { - if (m_userTypeActions == null) - m_userTypeActions = umbraco.BusinessLogic.Actions.Action.FromString(CurrentUserType.DefaultPermissions); - return m_userTypeActions; - } - } - - protected UserType CurrentUserType - { - get - { - if (m_userType == null) - m_userType = UserType.GetUserType(m_userTypeID); - return m_userType; - } - } - private UserType m_userType; - private List m_userTypeActions; - private int m_userTypeID; - - private void BindActions() - { - lblUserTypeAlias.Text = CurrentUserType.Alias; - txtUserTypeName.Text = CurrentUserType.Name; - hidUserTypeID.Value = CurrentUserType.Id.ToString(); - - foreach (IAction ai in global::umbraco.BusinessLogic.Actions.Action.GetPermissionAssignable()) { - - ListItem li = new ListItem(umbraco.ui.Text(ai.Alias, base.getUser()), ai.Letter.ToString()); - - if(CurrentUserTypeActions.Contains(ai)) - li.Selected = true; - - cbl_rights.Items.Add(li); - } - } - - - - } -} diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/users/EditUserType.aspx.designer.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/users/EditUserType.aspx.designer.cs deleted file mode 100644 index ac1fddb9ec..0000000000 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/users/EditUserType.aspx.designer.cs +++ /dev/null @@ -1,105 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by a tool. -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -namespace umbraco.cms.presentation.user { - - - public partial class EditUserType { - - /// - /// pnlUmbraco control. - /// - /// - /// Auto-generated field. - /// To modify move field declaration from designer file to code-behind file. - /// - protected global::umbraco.uicontrols.UmbracoPanel pnlUmbraco; - - /// - /// pnl1 control. - /// - /// - /// Auto-generated field. - /// To modify move field declaration from designer file to code-behind file. - /// - protected global::umbraco.uicontrols.Pane pnl1; - - /// - /// hidUserTypeID control. - /// - /// - /// Auto-generated field. - /// To modify move field declaration from designer file to code-behind file. - /// - protected global::System.Web.UI.WebControls.HiddenField hidUserTypeID; - - /// - /// pp_name control. - /// - /// - /// Auto-generated field. - /// To modify move field declaration from designer file to code-behind file. - /// - protected global::umbraco.uicontrols.PropertyPanel pp_name; - - /// - /// txtUserTypeName control. - /// - /// - /// Auto-generated field. - /// To modify move field declaration from designer file to code-behind file. - /// - protected global::System.Web.UI.WebControls.TextBox txtUserTypeName; - - /// - /// pp_alias control. - /// - /// - /// Auto-generated field. - /// To modify move field declaration from designer file to code-behind file. - /// - protected global::umbraco.uicontrols.PropertyPanel pp_alias; - - /// - /// lblUserTypeAlias control. - /// - /// - /// Auto-generated field. - /// To modify move field declaration from designer file to code-behind file. - /// - protected global::System.Web.UI.WebControls.Label lblUserTypeAlias; - - /// - /// pnl2 control. - /// - /// - /// Auto-generated field. - /// To modify move field declaration from designer file to code-behind file. - /// - protected global::umbraco.uicontrols.Pane pnl2; - - /// - /// pp_rights control. - /// - /// - /// Auto-generated field. - /// To modify move field declaration from designer file to code-behind file. - /// - protected global::umbraco.uicontrols.PropertyPanel pp_rights; - - /// - /// cbl_rights control. - /// - /// - /// Auto-generated field. - /// To modify move field declaration from designer file to code-behind file. - /// - protected global::System.Web.UI.WebControls.CheckBoxList cbl_rights; - } -} diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/users/UserTypeTasks.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/users/UserTypeTasks.cs deleted file mode 100644 index 0a8e02341a..0000000000 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/users/UserTypeTasks.cs +++ /dev/null @@ -1,52 +0,0 @@ -using System; -using System.Data; -using System.Configuration; -using System.Web; -using System.Web.Security; -using System.Web.UI; -using System.Web.UI.WebControls; -using System.Web.UI.WebControls.WebParts; -using System.Web.UI.HtmlControls; -using Umbraco.Web.UI; -using umbraco.interfaces; -using umbraco.BusinessLogic; - -namespace umbraco.cms.presentation.user -{ - public class UserTypeTasks : LegacyDialogTask - { - public override bool PerformSave() - { - try - { - var u = UserType.MakeNew(Alias, "", Alias); - _returnUrl = string.Format("users/EditUserType.aspx?id={0}", u.Id); - return true; - } - catch - { - return false; - } - } - - public override bool PerformDelete() - { - var userType = UserType.GetUserType(ParentID); - if (userType == null) - return false; - userType.Delete(); - return true; - } - - private string _returnUrl = ""; - public override string ReturnUrl - { - get { return _returnUrl; } - } - - public override string AssignedApp - { - get { return DefaultApps.users.ToString(); } - } - } -} diff --git a/src/umbraco.businesslogic/BasePages/BasePage.cs b/src/umbraco.businesslogic/BasePages/BasePage.cs index 8e7f1f47e1..bf026a5c62 100644 --- a/src/umbraco.businesslogic/BasePages/BasePage.cs +++ b/src/umbraco.businesslogic/BasePages/BasePage.cs @@ -293,7 +293,7 @@ namespace umbraco.BasePages AllowedApplications = u.GetApplications().Select(x => x.alias).ToArray(), RealName = u.Name, //currently we only have one user type! - Roles = new[] { u.UserType.Alias }, + Roles = u.GetGroups(), StartContentNode = u.StartNodeId, StartMediaNode = u.StartMediaId, Username = u.LoginName, diff --git a/src/umbraco.businesslogic/User.cs b/src/umbraco.businesslogic/User.cs index e8ed675998..f6096306c7 100644 --- a/src/umbraco.businesslogic/User.cs +++ b/src/umbraco.businesslogic/User.cs @@ -313,24 +313,6 @@ namespace umbraco.BusinessLogic return (tmp != null); } - /// - /// Gets or sets the type of the user. - /// - /// The type of the user. - public UserType UserType - { - get - { - if (_lazyId.HasValue) SetupUser(_lazyId.Value); - return new UserType(UserEntity.UserType); - } - set - { - UserEntity.UserType = value.UserTypeItem; - } - } - - /// /// Gets all users /// @@ -447,10 +429,9 @@ namespace umbraco.BusinessLogic /// The full name. /// The login name. /// The password. - /// The user type. - public static User MakeNew(string name, string lname, string passw, UserType ut) + public static User MakeNew(string name, string lname, string passw) { - var user = new Umbraco.Core.Models.Membership.User(name, "", lname, passw, ut.UserTypeItem); + var user = new Umbraco.Core.Models.Membership.User(name, "", lname, passw); ApplicationContext.Current.Services.UserService.Save(user); var u = new User(user); @@ -467,10 +448,9 @@ namespace umbraco.BusinessLogic /// The lname. /// The passw. /// The email. - /// The ut. - public static User MakeNew(string name, string lname, string passw, string email, UserType ut) + public static User MakeNew(string name, string lname, string passw, string email) { - var user = new Umbraco.Core.Models.Membership.User(name, email, lname, passw, ut.UserTypeItem); + var user = new Umbraco.Core.Models.Membership.User(name, email, lname, passw); ApplicationContext.Current.Services.UserService.Save(user); var u = new User(user); @@ -487,8 +467,7 @@ namespace umbraco.BusinessLogic /// The name. /// The lname. /// The email. - /// The ut. - public static void Update(int id, string name, string lname, string email, UserType ut) + public static void Update(int id, string name, string lname, string email) { if (EnsureUniqueLoginName(lname, GetUser(id)) == false) throw new Exception(String.Format("A user with the login '{0}' already exists", lname)); @@ -498,11 +477,10 @@ namespace umbraco.BusinessLogic found.Name = name; found.Username = lname; found.Email = email; - found.UserType = ut.UserTypeItem; ApplicationContext.Current.Services.UserService.Save(found); } - public static void Update(int id, string name, string lname, string email, bool disabled, bool noConsole, UserType ut) + public static void Update(int id, string name, string lname, string email, bool disabled, bool noConsole) { if (EnsureUniqueLoginName(lname, GetUser(id)) == false) throw new Exception(String.Format("A user with the login '{0}' already exists", lname)); @@ -512,7 +490,6 @@ namespace umbraco.BusinessLogic found.Name = name; found.Username = lname; found.Email = email; - found.UserType = ut.UserTypeItem; found.IsApproved = disabled == false; found.IsLockedOut = noConsole; ApplicationContext.Current.Services.UserService.Save(found); @@ -681,7 +658,7 @@ namespace umbraco.BusinessLogic } /// - /// Adds a group to the list groups for the user, ensure to call Save() afterwords + /// Adds a group to the list of groups for the user, ensure to call Save() afterwords /// public void AddGroup(int groupId, string groupName) { @@ -693,6 +670,12 @@ namespace umbraco.BusinessLogic }); } + public string[] GetGroups() + { + if (_lazyId.HasValue) SetupUser(_lazyId.Value); + return UserEntity.Groups.Select(x => x.Name).ToArray(); + } + /// /// Gets or sets a value indicating whether the user has access to the Umbraco back end. diff --git a/src/umbraco.businesslogic/UserType.cs b/src/umbraco.businesslogic/UserType.cs deleted file mode 100644 index b7bc2b9675..0000000000 --- a/src/umbraco.businesslogic/UserType.cs +++ /dev/null @@ -1,259 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Data; -using System.Globalization; -using System.Linq; -using System.Runtime.CompilerServices; -using System.Web; -using System.Web.Caching; -using Umbraco.Core; -using Umbraco.Core.Cache; -using Umbraco.Core.Events; -using umbraco.DataLayer; - -namespace umbraco.BusinessLogic -{ - /// - /// Represents a umbraco Usertype - /// - [Obsolete("Use the UserService instead")] - public class UserType - { - - internal Umbraco.Core.Models.Membership.IUserType UserTypeItem; - - /// - /// Creates a new empty instance of a UserType - /// - public UserType() - { - UserTypeItem = new Umbraco.Core.Models.Membership.UserType(); - } - - internal UserType(Umbraco.Core.Models.Membership.IUserType userType) - { - UserTypeItem = userType; - } - - /// - /// Creates a new instance of a UserType and attempts to - /// load it's values from the database cache. - /// - /// - /// If the UserType is not found in the existing ID list, then this object - /// will remain an empty object - /// - /// The UserType id to find - public UserType(int id) - { - this.LoadByPrimaryKey(id); - } - - /// - /// Initializes a new instance of the class. - /// - /// The user type id. - /// The name. - public UserType(int id, string name) - { - UserTypeItem = new Umbraco.Core.Models.Membership.UserType(); - UserTypeItem.Id = id; - UserTypeItem.Name = name; - } - - /// - /// Creates a new instance of UserType with all parameters - /// - /// - /// - /// - /// - public UserType(int id, string name, string defaultPermissions, string alias) - { - UserTypeItem = new Umbraco.Core.Models.Membership.UserType(); - UserTypeItem.Id = id; - UserTypeItem.Name = name; - UserTypeItem.Alias = alias; - UserTypeItem.Permissions = defaultPermissions.ToCharArray().Select(x => x.ToString(CultureInfo.InvariantCulture)); - } - - /// - /// The cache storage for all user types - /// - private static List UserTypes - { - get - { - return ApplicationContext.Current.Services.UserService.GetAllUserTypes() - .Select(x => new UserType(x)) - .ToList(); - } - } - - #region Public Properties - /// - /// Gets or sets the user type alias. - /// - public string Alias - { - get { return UserTypeItem.Alias; } - set { UserTypeItem.Alias = value; } - } - - /// - /// Gets the name of the user type. - /// - public string Name - { - get { return UserTypeItem.Name; } - set { UserTypeItem.Name = value; } - } - - /// - /// Gets the id the user type - /// - public int Id - { - get { return UserTypeItem.Id; } - } - - /// - /// Gets the default permissions of the user type - /// - public string DefaultPermissions - { - get { return UserTypeItem.Permissions == null ? string.Empty : string.Join("", UserTypeItem.Permissions); } - set { UserTypeItem.Permissions = value.ToCharArray().Select(x => x.ToString(CultureInfo.InvariantCulture)); } - } - - /// - /// Returns an array of UserTypes - /// - [Obsolete("Use the GetAll method instead")] - public static UserType[] getAll - { - get { return GetAllUserTypes().ToArray(); } - } - #endregion - - /// - /// Saves this instance. - /// - public void Save() - { - //ensure that this object has an ID specified (it exists in the database) - if (UserTypeItem.HasIdentity == false) - throw new Exception("The current UserType object does not exist in the database. New UserTypes should be created with the MakeNew method"); - - ApplicationContext.Current.Services.UserService.SaveUserType(UserTypeItem); - - //raise event - OnUpdated(this, new EventArgs()); - } - - /// - /// Deletes this instance. - /// - public void Delete() - { - //ensure that this object has an ID specified (it exists in the database) - if (UserTypeItem.HasIdentity == false) - throw new Exception("The current UserType object does not exist in the database. New UserTypes should be created with the MakeNew method"); - - ApplicationContext.Current.Services.UserService.DeleteUserType(UserTypeItem); - - //raise event - OnDeleted(this, new EventArgs()); - } - - /// - /// Load the data for the current UserType by it's id - /// - /// - /// Returns true if the UserType id was found - /// and the data was loaded, false if it wasn't - public bool LoadByPrimaryKey(int id) - { - UserTypeItem = ApplicationContext.Current.Services.UserService.GetUserTypeById(id); - return UserTypeItem != null; - } - - /// - /// Creates a new user type - /// - /// - /// - /// - public static UserType MakeNew(string name, string defaultPermissions, string alias) - { - //ensure that the current alias does not exist - //get the id for the new user type - var existing = UserTypes.Find(ut => (ut.Alias == alias)); - - if (existing != null) - throw new Exception("The UserType alias specified already exists"); - - var userType = new Umbraco.Core.Models.Membership.UserType - { - Alias = alias, - Name = name, - Permissions = defaultPermissions.ToCharArray().Select(x => x.ToString(CultureInfo.InvariantCulture)) - }; - ApplicationContext.Current.Services.UserService.SaveUserType(userType); - - var legacy = new UserType(userType); - - //raise event - OnNew(legacy, new EventArgs()); - - return legacy; - } - - /// - /// Gets the user type with the specied ID - /// - /// The id. - /// - public static UserType GetUserType(int id) - { - return UserTypes.Find(ut => (ut.Id == id)); - } - - /// - /// Returns all UserType's - /// - /// - public static List GetAllUserTypes() - { - return UserTypes; - } - - internal static event TypedEventHandler New; - private static void OnNew(UserType userType, EventArgs args) - { - if (New != null) - { - New(userType, args); - } - } - - internal static event TypedEventHandler Deleted; - private static void OnDeleted(UserType userType, EventArgs args) - { - if (Deleted != null) - { - Deleted(userType, args); - } - } - - internal static event TypedEventHandler Updated; - private static void OnUpdated(UserType userType, EventArgs args) - { - if (Updated != null) - { - Updated(userType, args); - } - } - - } -} \ No newline at end of file diff --git a/src/umbraco.businesslogic/umbraco.businesslogic.csproj b/src/umbraco.businesslogic/umbraco.businesslogic.csproj index 0d6aae1b71..87de399469 100644 --- a/src/umbraco.businesslogic/umbraco.businesslogic.csproj +++ b/src/umbraco.businesslogic/umbraco.businesslogic.csproj @@ -242,9 +242,6 @@ Code - - Code - Code diff --git a/src/umbraco.editorControls/tinyMCE3/TinyMCE.cs b/src/umbraco.editorControls/tinyMCE3/TinyMCE.cs index fcae44b113..cf6fba9e43 100644 --- a/src/umbraco.editorControls/tinyMCE3/TinyMCE.cs +++ b/src/umbraco.editorControls/tinyMCE3/TinyMCE.cs @@ -1,5 +1,6 @@ using System; using System.Collections; +using System.Linq; using System.Text.RegularExpressions; using System.Web; using System.Web.UI; @@ -136,8 +137,8 @@ namespace umbraco.editorControls.tinyMCE3 config.Add("plugins", _plugins); // Check advanced settings - if (UmbracoEnsuredPage.CurrentUser != null && ("," + _advancedUsers + ",").IndexOf("," + UmbracoEnsuredPage.CurrentUser.UserType.Id + ",") > - -1) + var advancedUserGroupNames = _advancedUsers.Split(','); + if (UmbracoEnsuredPage.CurrentUser != null && advancedUserGroupNames.Intersect(UmbracoEnsuredPage.CurrentUser.GetGroups()).Any()) config.Add("umbraco_advancedMode", "true"); else config.Add("umbraco_advancedMode", "false"); diff --git a/src/umbraco.editorControls/tinymce/tinyMCEPreValueConfigurator.cs b/src/umbraco.editorControls/tinymce/tinyMCEPreValueConfigurator.cs index 533a961416..fe6505be54 100644 --- a/src/umbraco.editorControls/tinymce/tinyMCEPreValueConfigurator.cs +++ b/src/umbraco.editorControls/tinymce/tinyMCEPreValueConfigurator.cs @@ -1,15 +1,15 @@ using System; -using System.Collections.Generic; -using System.Text; using System.Collections; using System.Web.UI; using System.Web.UI.WebControls; - using umbraco.BusinessLogic; using umbraco.DataLayer; +using Umbraco.Core; namespace umbraco.editorControls.tinymce { + + [Obsolete("IDataType and all other references to the legacy property editors are no longer used this will be removed from the codebase in future versions")] public class tinyMCEPreValueConfigurator : System.Web.UI.WebControls.PlaceHolder, interfaces.IDataPrevalue { @@ -178,10 +178,11 @@ namespace umbraco.editorControls.tinymce } // add users - foreach (BusinessLogic.UserType ut in BusinessLogic.UserType.getAll) + var userService = ApplicationContext.Current.Services.UserService; + foreach (var ug in userService.GetAllUserGroups()) { - ListItem li = new ListItem(ut.Name, ut.Id.ToString()); - if (("," + _advancedUsers + ",").IndexOf("," + ut.Id.ToString() + ",") > -1) + ListItem li = new ListItem(ug.Name, ug.Id.ToString()); + if (("," + _advancedUsers + ",").IndexOf("," + ug.Id + ",") > -1) li.Selected = true; _advancedUsersList.Items.Add(li); diff --git a/src/umbraco.providers/UsersMembershipProvider.cs b/src/umbraco.providers/UsersMembershipProvider.cs index 93f5327cbb..39285449a9 100644 --- a/src/umbraco.providers/UsersMembershipProvider.cs +++ b/src/umbraco.providers/UsersMembershipProvider.cs @@ -137,17 +137,11 @@ namespace umbraco.providers try { // Get the usertype of the current user - var ut = UserType.GetUserType(1); - if (BasePages.UmbracoEnsuredPage.CurrentUser != null) - { - ut = BasePages.UmbracoEnsuredPage.CurrentUser.UserType; - } - //ensure the password is encrypted/hashed string salt; var encodedPass = EncryptOrHashNewPassword(password, out salt); - User.MakeNew(username, username, FormatPasswordForStorage(encodedPass, salt), email, ut); + User.MakeNew(username, username, FormatPasswordForStorage(encodedPass, salt), email); status = MembershipCreateStatus.Success; } @@ -468,8 +462,8 @@ namespace umbraco.providers } else { - //This keeps compatibility - even though this logic to update name and user type should not exist here - User.Update(m.Id, typedUser.FullName.Trim(), typedUser.UserName, typedUser.Email, user.IsApproved == false, user.IsLockedOut, typedUser.UserType); + //This keeps compatibility - even though this logic to update name should not exist here + User.Update(m.Id, typedUser.FullName.Trim(), typedUser.UserName, typedUser.Email, user.IsApproved == false, user.IsLockedOut); } m.Save(); @@ -562,7 +556,7 @@ namespace umbraco.providers return new UsersMembershipUser(base.Name, user.LoginName, user.Id, user.Email, string.Empty, string.Empty, true, user.Disabled, DateTime.Now, DateTime.Now, DateTime.Now, DateTime.Now, - DateTime.Now, user.Name, user.Language, user.UserType); + DateTime.Now, user.Name, user.Language); } #endregion diff --git a/src/umbraco.providers/UsersMembershipUser.cs b/src/umbraco.providers/UsersMembershipUser.cs index dd406662dc..ffb2d75ae9 100644 --- a/src/umbraco.providers/UsersMembershipUser.cs +++ b/src/umbraco.providers/UsersMembershipUser.cs @@ -38,17 +38,7 @@ namespace umbraco.providers get { return _Language; } set { _Language = value; } } - private UserType _UserType; - /// - /// Gets or sets the type of the user. - /// - /// The type of the user. - public UserType UserType - { - get { return _UserType; } - set { _UserType = value; } - } #endregion #region Constructors @@ -78,16 +68,14 @@ namespace umbraco.providers /// The last lockout date. /// The full name. /// The language. - /// Type of the user. public UsersMembershipUser(string providerName, string name, object providerUserKey, string email, string passwordQuestion, string comment, bool isApproved, bool isLockedOut, DateTime creationDate, DateTime lastLoginDate, DateTime lastActivityDate, DateTime lastPasswordChangedDate, - DateTime lastLockoutDate, string fullName, string language, UserType userType ) + DateTime lastLockoutDate, string fullName, string language) : base( providerName, name, providerUserKey, email, passwordQuestion, comment, isApproved, isLockedOut, creationDate, lastLoginDate, lastActivityDate, lastPasswordChangedDate, lastLockoutDate) { _FullName = fullName; - _UserType = userType; _Language = language; } #endregion