diff --git a/src/Umbraco.Core/Models/DictionaryItem.cs b/src/Umbraco.Abstractions/Models/DictionaryItem.cs similarity index 100% rename from src/Umbraco.Core/Models/DictionaryItem.cs rename to src/Umbraco.Abstractions/Models/DictionaryItem.cs diff --git a/src/Umbraco.Core/Models/DictionaryItemExtensions.cs b/src/Umbraco.Abstractions/Models/DictionaryItemExtensions.cs similarity index 100% rename from src/Umbraco.Core/Models/DictionaryItemExtensions.cs rename to src/Umbraco.Abstractions/Models/DictionaryItemExtensions.cs diff --git a/src/Umbraco.Core/Models/DictionaryTranslation.cs b/src/Umbraco.Abstractions/Models/DictionaryTranslation.cs similarity index 93% rename from src/Umbraco.Core/Models/DictionaryTranslation.cs rename to src/Umbraco.Abstractions/Models/DictionaryTranslation.cs index afb4063b97..a00f9e887f 100644 --- a/src/Umbraco.Core/Models/DictionaryTranslation.cs +++ b/src/Umbraco.Abstractions/Models/DictionaryTranslation.cs @@ -11,7 +11,7 @@ namespace Umbraco.Core.Models [DataContract(IsReference = true)] public class DictionaryTranslation : EntityBase, IDictionaryTranslation { - internal Func GetLanguage { get; set; } + public Func GetLanguage { get; set; } private ILanguage _language; private string _value; @@ -35,13 +35,13 @@ namespace Umbraco.Core.Models Key = uniqueId; } - internal DictionaryTranslation(int languageId, string value) + public DictionaryTranslation(int languageId, string value) { _languageId = languageId; _value = value; } - internal DictionaryTranslation(int languageId, string value, Guid uniqueId) + public DictionaryTranslation(int languageId, string value, Guid uniqueId) { _languageId = languageId; _value = value; diff --git a/src/Umbraco.Core/Models/EntityExtensions.cs b/src/Umbraco.Abstractions/Models/EntityExtensions.cs similarity index 100% rename from src/Umbraco.Core/Models/EntityExtensions.cs rename to src/Umbraco.Abstractions/Models/EntityExtensions.cs diff --git a/src/Umbraco.Core/Models/MacroProperty.cs b/src/Umbraco.Abstractions/Models/MacroProperty.cs similarity index 97% rename from src/Umbraco.Core/Models/MacroProperty.cs rename to src/Umbraco.Abstractions/Models/MacroProperty.cs index 62ba6a7a7d..9dfb81cf71 100644 --- a/src/Umbraco.Core/Models/MacroProperty.cs +++ b/src/Umbraco.Abstractions/Models/MacroProperty.cs @@ -41,7 +41,7 @@ namespace Umbraco.Core.Models /// /// /// - internal MacroProperty(int id, Guid key, string @alias, string name, int sortOrder, string editorAlias) + public MacroProperty(int id, Guid key, string @alias, string name, int sortOrder, string editorAlias) { _id = id; _alias = alias; diff --git a/src/Umbraco.Core/Models/MemberGroup.cs b/src/Umbraco.Abstractions/Models/MemberGroup.cs similarity index 100% rename from src/Umbraco.Core/Models/MemberGroup.cs rename to src/Umbraco.Abstractions/Models/MemberGroup.cs diff --git a/src/Umbraco.Core/Models/MemberTypePropertyProfileAccess.cs b/src/Umbraco.Abstractions/Models/MemberTypePropertyProfileAccess.cs similarity index 91% rename from src/Umbraco.Core/Models/MemberTypePropertyProfileAccess.cs rename to src/Umbraco.Abstractions/Models/MemberTypePropertyProfileAccess.cs index 386fdf560b..0be9080841 100644 --- a/src/Umbraco.Core/Models/MemberTypePropertyProfileAccess.cs +++ b/src/Umbraco.Abstractions/Models/MemberTypePropertyProfileAccess.cs @@ -3,7 +3,7 @@ /// /// Used to track the property types that are visible/editable on member profiles /// - internal class MemberTypePropertyProfileAccess + public class MemberTypePropertyProfileAccess { public MemberTypePropertyProfileAccess(bool isVisible, bool isEditable, bool isSenstive) { diff --git a/src/Umbraco.Core/Models/PagedResultOfT.cs b/src/Umbraco.Abstractions/Models/PagedResultOfT.cs similarity index 100% rename from src/Umbraco.Core/Models/PagedResultOfT.cs rename to src/Umbraco.Abstractions/Models/PagedResultOfT.cs diff --git a/src/Umbraco.Core/Models/PublicAccessEntry.cs b/src/Umbraco.Abstractions/Models/PublicAccessEntry.cs similarity index 98% rename from src/Umbraco.Core/Models/PublicAccessEntry.cs rename to src/Umbraco.Abstractions/Models/PublicAccessEntry.cs index cfb30de147..b7f9caed44 100644 --- a/src/Umbraco.Core/Models/PublicAccessEntry.cs +++ b/src/Umbraco.Abstractions/Models/PublicAccessEntry.cs @@ -77,7 +77,7 @@ namespace Umbraco.Core.Models } } - internal IEnumerable RemovedRules => _removedRules; + public IEnumerable RemovedRules => _removedRules; public IEnumerable Rules => _ruleCollection; diff --git a/src/Umbraco.Core/Models/UmbracoDomain.cs b/src/Umbraco.Abstractions/Models/UmbracoDomain.cs similarity index 95% rename from src/Umbraco.Core/Models/UmbracoDomain.cs rename to src/Umbraco.Abstractions/Models/UmbracoDomain.cs index 093acef5b5..c4a49de5d3 100644 --- a/src/Umbraco.Core/Models/UmbracoDomain.cs +++ b/src/Umbraco.Abstractions/Models/UmbracoDomain.cs @@ -49,6 +49,6 @@ namespace Umbraco.Core.Models /// /// Readonly value of the language ISO code for the domain /// - public string LanguageIsoCode { get; internal set; } + public string LanguageIsoCode { get; set; } } } diff --git a/src/Umbraco.Abstractions/Models/UmbracoUserExtensions.cs b/src/Umbraco.Abstractions/Models/UmbracoUserExtensions.cs new file mode 100644 index 0000000000..6ed3e6279b --- /dev/null +++ b/src/Umbraco.Abstractions/Models/UmbracoUserExtensions.cs @@ -0,0 +1,76 @@ +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Text; +using Umbraco.Core.Configuration; +using Umbraco.Core.Models.Membership; +using Umbraco.Core.Services; + +namespace Umbraco.Core.Models +{ + public static class UmbracoUserExtensions + { + public static IEnumerable GetPermissions(this IUser user, string path, IUserService userService) + { + return userService.GetPermissionsForPath(user, path).GetAllPermissions(); + } + + public static bool HasSectionAccess(this IUser user, string app) + { + var apps = user.AllowedSections; + return apps.Any(uApp => uApp.InvariantEquals(app)); + } + + /// + /// Determines whether this user is the 'super' user. + /// + public static bool IsSuper(this IUser user) + { + if (user == null) throw new ArgumentNullException(nameof(user)); + return user.Id == Constants.Security.SuperUserId; + } + + /// + /// Determines whether this user belongs to the administrators group. + /// + /// The 'super' user does not automatically belongs to the administrators group. + public static bool IsAdmin(this IUser user) + { + if (user == null) throw new ArgumentNullException(nameof(user)); + return user.Groups != null && user.Groups.Any(x => x.Alias == Constants.Security.AdminGroupAlias); + } + + /// + /// Returns the culture info associated with this user, based on the language they're assigned to in the back office + /// + /// + /// + /// + /// + public static CultureInfo GetUserCulture(this IUser user, ILocalizedTextService textService, IGlobalSettings globalSettings) + { + if (user == null) throw new ArgumentNullException(nameof(user)); + if (textService == null) throw new ArgumentNullException(nameof(textService)); + return GetUserCulture(user.Language, textService, globalSettings); + } + + public static CultureInfo GetUserCulture(string userLanguage, ILocalizedTextService textService, IGlobalSettings globalSettings) + { + try + { + var culture = CultureInfo.GetCultureInfo(userLanguage.Replace("_", "-")); + // TODO: This is a hack because we store the user language as 2 chars instead of the full culture + // which is actually stored in the language files (which are also named with 2 chars!) so we need to attempt + // to convert to a supported full culture + var result = textService.ConvertToSupportedCultureWithRegionCode(culture); + return result; + } + catch (CultureNotFoundException) + { + //return the default one + return CultureInfo.GetCultureInfo(globalSettings.DefaultUILanguage); + } + } + } +} diff --git a/src/Umbraco.Core/Models/Validation/RequiredForPersistenceAttribute.cs b/src/Umbraco.Abstractions/Models/Validation/RequiredForPersistenceAttribute.cs similarity index 94% rename from src/Umbraco.Core/Models/Validation/RequiredForPersistenceAttribute.cs rename to src/Umbraco.Abstractions/Models/Validation/RequiredForPersistenceAttribute.cs index f54741e489..feb889e962 100644 --- a/src/Umbraco.Core/Models/Validation/RequiredForPersistenceAttribute.cs +++ b/src/Umbraco.Abstractions/Models/Validation/RequiredForPersistenceAttribute.cs @@ -19,7 +19,7 @@ namespace Umbraco.Core.Models.Validation /// /// Determines whether an object has all required values for persistence. /// - internal static bool HasRequiredValuesForPersistence(object model) + public static bool HasRequiredValuesForPersistence(object model) { return model.GetType().GetProperties().All(x => { diff --git a/src/Umbraco.Core/Services/IMembershipUserService.cs b/src/Umbraco.Abstractions/Services/IMembershipUserService.cs similarity index 100% rename from src/Umbraco.Core/Services/IMembershipUserService.cs rename to src/Umbraco.Abstractions/Services/IMembershipUserService.cs diff --git a/src/Umbraco.Core/Services/IUserService.cs b/src/Umbraco.Abstractions/Services/IUserService.cs similarity index 99% rename from src/Umbraco.Core/Services/IUserService.cs rename to src/Umbraco.Abstractions/Services/IUserService.cs index 35a3be9eac..950b4f548d 100644 --- a/src/Umbraco.Core/Services/IUserService.cs +++ b/src/Umbraco.Abstractions/Services/IUserService.cs @@ -1,9 +1,6 @@ using System; using System.Collections.Generic; -using System.Linq; -using Umbraco.Core.Models; using Umbraco.Core.Models.Membership; -using Umbraco.Core.Persistence.DatabaseModelDefinitions; using Umbraco.Core.Persistence.Querying; namespace Umbraco.Core.Services diff --git a/src/Umbraco.Core/Models/UserExtensions.cs b/src/Umbraco.Core/Models/UserExtensions.cs index 6e77ee456d..d5dda1a49a 100644 --- a/src/Umbraco.Core/Models/UserExtensions.cs +++ b/src/Umbraco.Core/Models/UserExtensions.cs @@ -16,35 +16,7 @@ namespace Umbraco.Core.Models { public static class UserExtensions { - public static IEnumerable GetPermissions(this IUser user, string path, IUserService userService) - { - return userService.GetPermissionsForPath(user, path).GetAllPermissions(); - } - - public static bool HasSectionAccess(this IUser user, string app) - { - var apps = user.AllowedSections; - return apps.Any(uApp => uApp.InvariantEquals(app)); - } - - /// - /// Determines whether this user is the 'super' user. - /// - public static bool IsSuper(this IUser user) - { - if (user == null) throw new ArgumentNullException(nameof(user)); - return user.Id == Constants.Security.SuperUserId; - } - - /// - /// Determines whether this user belongs to the administrators group. - /// - /// The 'super' user does not automatically belongs to the administrators group. - public static bool IsAdmin(this IUser user) - { - if (user == null) throw new ArgumentNullException(nameof(user)); - return user.Groups != null && user.Groups.Any(x => x.Alias == Constants.Security.AdminGroupAlias); - } + /// /// Tries to lookup the user's Gravatar to see if the endpoint can be reached, if so it returns the valid URL @@ -117,37 +89,7 @@ namespace Umbraco.Core.Models } - /// - /// Returns the culture info associated with this user, based on the language they're assigned to in the back office - /// - /// - /// - /// - /// - public static CultureInfo GetUserCulture(this IUser user, ILocalizedTextService textService, IGlobalSettings globalSettings) - { - if (user == null) throw new ArgumentNullException(nameof(user)); - if (textService == null) throw new ArgumentNullException(nameof(textService)); - return GetUserCulture(user.Language, textService, globalSettings); - } - - internal static CultureInfo GetUserCulture(string userLanguage, ILocalizedTextService textService, IGlobalSettings globalSettings) - { - try - { - var culture = CultureInfo.GetCultureInfo(userLanguage.Replace("_", "-")); - // TODO: This is a hack because we store the user language as 2 chars instead of the full culture - // which is actually stored in the language files (which are also named with 2 chars!) so we need to attempt - // to convert to a supported full culture - var result = textService.ConvertToSupportedCultureWithRegionCode(culture); - return result; - } - catch (CultureNotFoundException) - { - //return the default one - return CultureInfo.GetCultureInfo(globalSettings.DefaultUILanguage); - } - } + internal static bool HasContentRootAccess(this IUser user, IEntityService entityService) { diff --git a/src/Umbraco.Core/Umbraco.Core.csproj b/src/Umbraco.Core/Umbraco.Core.csproj index 1c1bd30418..00aa5c37f9 100755 --- a/src/Umbraco.Core/Umbraco.Core.csproj +++ b/src/Umbraco.Core/Umbraco.Core.csproj @@ -213,6 +213,7 @@ + @@ -225,12 +226,10 @@ - - @@ -524,25 +523,17 @@ - - - - - - - - @@ -601,10 +592,8 @@ - - @@ -999,11 +988,9 @@ - - @@ -1062,8 +1049,6 @@ Umbraco.Abstractions - - - + \ No newline at end of file diff --git a/src/Umbraco.Web/Editors/AuthenticationController.cs b/src/Umbraco.Web/Editors/AuthenticationController.cs index c2c481e8e4..a2d6a594b2 100644 --- a/src/Umbraco.Web/Editors/AuthenticationController.cs +++ b/src/Umbraco.Web/Editors/AuthenticationController.cs @@ -305,13 +305,13 @@ namespace Umbraco.Web.Editors var message = Services.TextService.Localize("resetPasswordEmailCopyFormat", // Ensure the culture of the found user is used for the email! - UserExtensions.GetUserCulture(identityUser.Culture, Services.TextService, GlobalSettings), + UmbracoUserExtensions.GetUserCulture(identityUser.Culture, Services.TextService, GlobalSettings), new[] { identityUser.UserName, callbackUrl }); await UserManager.SendEmailAsync(identityUser.Id, Services.TextService.Localize("login/resetPasswordEmailCopySubject", // Ensure the culture of the found user is used for the email! - UserExtensions.GetUserCulture(identityUser.Culture, Services.TextService, GlobalSettings)), + UmbracoUserExtensions.GetUserCulture(identityUser.Culture, Services.TextService, GlobalSettings)), message); UserManager.RaiseForgotPasswordRequestedEvent(user.Id); diff --git a/src/Umbraco.Web/Editors/UsersController.cs b/src/Umbraco.Web/Editors/UsersController.cs index 5cc77e7eb0..e30054df78 100644 --- a/src/Umbraco.Web/Editors/UsersController.cs +++ b/src/Umbraco.Web/Editors/UsersController.cs @@ -466,10 +466,10 @@ namespace Umbraco.Web.Editors var emailSubject = Services.TextService.Localize("user/inviteEmailCopySubject", //Ensure the culture of the found user is used for the email! - UserExtensions.GetUserCulture(to.Language, Services.TextService, GlobalSettings)); + UmbracoUserExtensions.GetUserCulture(to.Language, Services.TextService, GlobalSettings)); var emailBody = Services.TextService.Localize("user/inviteEmailCopyFormat", //Ensure the culture of the found user is used for the email! - UserExtensions.GetUserCulture(to.Language, Services.TextService, GlobalSettings), + UmbracoUserExtensions.GetUserCulture(to.Language, Services.TextService, GlobalSettings), new[] { userDisplay.Name, from, message, inviteUri.ToString(), fromEmail }); await UserManager.EmailService.SendAsync( diff --git a/src/Umbraco.Web/WebApi/Filters/CheckIfUserTicketDataIsStaleAttribute.cs b/src/Umbraco.Web/WebApi/Filters/CheckIfUserTicketDataIsStaleAttribute.cs index 2a57ec10b2..c3070fcf53 100644 --- a/src/Umbraco.Web/WebApi/Filters/CheckIfUserTicketDataIsStaleAttribute.cs +++ b/src/Umbraco.Web/WebApi/Filters/CheckIfUserTicketDataIsStaleAttribute.cs @@ -11,7 +11,7 @@ using Umbraco.Core.Models.Membership; using Umbraco.Core.Security; using Umbraco.Web.Security; using Umbraco.Core.Mapping; -using UserExtensions = Umbraco.Core.Models.UserExtensions; +using Umbraco.Core.Models; namespace Umbraco.Web.WebApi.Filters { @@ -78,19 +78,19 @@ namespace Umbraco.Web.WebApi.Filters () => user.Username != identity.Username, () => { - var culture = UserExtensions.GetUserCulture(user, Current.Services.TextService, Current.Configs.Global()); + var culture = user.GetUserCulture(Current.Services.TextService, Current.Configs.Global()); return culture != null && culture.ToString() != identity.Culture; }, () => user.AllowedSections.UnsortedSequenceEqual(identity.AllowedApplications) == false, () => user.Groups.Select(x => x.Alias).UnsortedSequenceEqual(identity.Roles) == false, () => { - var startContentIds = UserExtensions.CalculateContentStartNodeIds(user, Current.Services.EntityService); + var startContentIds = user.CalculateContentStartNodeIds(Current.Services.EntityService); return startContentIds.UnsortedSequenceEqual(identity.StartContentNodes) == false; }, () => { - var startMediaIds = UserExtensions.CalculateMediaStartNodeIds(user, Current.Services.EntityService); + var startMediaIds = user.CalculateMediaStartNodeIds(Current.Services.EntityService); return startMediaIds.UnsortedSequenceEqual(identity.StartMediaNodes) == false; } };