Moves UserGroup and UserGroupExtensions to core
This commit is contained in:
@@ -17,6 +17,7 @@ using Umbraco.Core.Strings;
|
||||
using Umbraco.Web.Actions;
|
||||
using Umbraco.Web.Services;
|
||||
using Umbraco.Core.Media;
|
||||
using Umbraco.Core.Persistence.Dtos;
|
||||
|
||||
namespace Umbraco.Web.Models.Mapping
|
||||
{
|
||||
@@ -444,6 +445,6 @@ namespace Umbraco.Web.Models.Mapping
|
||||
Trashed = false,
|
||||
ParentId = -1
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,127 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.Serialization;
|
||||
using Umbraco.Core.Models.Entities;
|
||||
using Umbraco.Core.Strings;
|
||||
|
||||
namespace Umbraco.Core.Models.Membership
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a Group for a Backoffice User
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
[DataContract(IsReference = true)]
|
||||
public class UserGroup : EntityBase, IUserGroup, IReadOnlyUserGroup
|
||||
{
|
||||
private readonly IShortStringHelper _shortStringHelper;
|
||||
private int? _startContentId;
|
||||
private int? _startMediaId;
|
||||
private string _alias;
|
||||
private string _icon;
|
||||
private string _name;
|
||||
private IEnumerable<string> _permissions;
|
||||
private readonly List<string> _sectionCollection;
|
||||
|
||||
//Custom comparer for enumerable
|
||||
private static readonly DelegateEqualityComparer<IEnumerable<string>> StringEnumerableComparer =
|
||||
new DelegateEqualityComparer<IEnumerable<string>>(
|
||||
(enum1, enum2) => enum1.UnsortedSequenceEqual(enum2),
|
||||
enum1 => enum1.GetHashCode());
|
||||
|
||||
/// <summary>
|
||||
/// Constructor to create a new user group
|
||||
/// </summary>
|
||||
public UserGroup(IShortStringHelper shortStringHelper)
|
||||
{
|
||||
_shortStringHelper = shortStringHelper;
|
||||
_sectionCollection = new List<string>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructor to create an existing user group
|
||||
/// </summary>
|
||||
/// <param name="userCount"></param>
|
||||
/// <param name="alias"></param>
|
||||
/// <param name="name"></param>
|
||||
/// <param name="permissions"></param>
|
||||
/// <param name="icon"></param>
|
||||
public UserGroup(IShortStringHelper shortStringHelper, int userCount, string alias, string name, IEnumerable<string> permissions, string icon)
|
||||
: this(shortStringHelper)
|
||||
{
|
||||
UserCount = userCount;
|
||||
_alias = alias;
|
||||
_name = name;
|
||||
_permissions = permissions;
|
||||
_icon = icon;
|
||||
}
|
||||
|
||||
[DataMember]
|
||||
public int? StartMediaId
|
||||
{
|
||||
get => _startMediaId;
|
||||
set => SetPropertyValueAndDetectChanges(value, ref _startMediaId, nameof(StartMediaId));
|
||||
}
|
||||
|
||||
[DataMember]
|
||||
public int? StartContentId
|
||||
{
|
||||
get => _startContentId;
|
||||
set => SetPropertyValueAndDetectChanges(value, ref _startContentId, nameof(StartContentId));
|
||||
}
|
||||
|
||||
[DataMember]
|
||||
public string Icon
|
||||
{
|
||||
get => _icon;
|
||||
set => SetPropertyValueAndDetectChanges(value, ref _icon, nameof(Icon));
|
||||
}
|
||||
|
||||
[DataMember]
|
||||
public string Alias
|
||||
{
|
||||
get => _alias;
|
||||
set => SetPropertyValueAndDetectChanges(value.ToCleanString(_shortStringHelper, CleanStringType.Alias | CleanStringType.UmbracoCase), ref _alias, nameof(Alias));
|
||||
}
|
||||
|
||||
[DataMember]
|
||||
public string Name
|
||||
{
|
||||
get => _name;
|
||||
set => SetPropertyValueAndDetectChanges(value, ref _name, nameof(Name));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The set of default permissions for the user group
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// 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.
|
||||
/// </remarks>
|
||||
[DataMember]
|
||||
public IEnumerable<string> Permissions
|
||||
{
|
||||
get => _permissions;
|
||||
set => SetPropertyValueAndDetectChanges(value, ref _permissions, nameof(Permissions), StringEnumerableComparer);
|
||||
}
|
||||
|
||||
public IEnumerable<string> AllowedSections => _sectionCollection;
|
||||
|
||||
public void RemoveAllowedSection(string sectionAlias)
|
||||
{
|
||||
if (_sectionCollection.Contains(sectionAlias))
|
||||
_sectionCollection.Remove(sectionAlias);
|
||||
}
|
||||
|
||||
public void AddAllowedSection(string sectionAlias)
|
||||
{
|
||||
if (_sectionCollection.Contains(sectionAlias) == false)
|
||||
_sectionCollection.Add(sectionAlias);
|
||||
}
|
||||
|
||||
public void ClearAllowedSections()
|
||||
{
|
||||
_sectionCollection.Clear();
|
||||
}
|
||||
|
||||
public int UserCount { get; }
|
||||
}
|
||||
}
|
||||
@@ -1,39 +0,0 @@
|
||||
using System.Linq;
|
||||
using Umbraco.Core.Persistence.Dtos;
|
||||
|
||||
namespace Umbraco.Core.Models.Membership
|
||||
{
|
||||
public static class UserGroupExtensions
|
||||
{
|
||||
public static IReadOnlyUserGroup ToReadOnlyGroup(this IUserGroup group)
|
||||
{
|
||||
//this will generally always be the case
|
||||
var readonlyGroup = group as IReadOnlyUserGroup;
|
||||
if (readonlyGroup != null) return readonlyGroup;
|
||||
|
||||
//otherwise create one
|
||||
return new ReadOnlyUserGroup(group.Id, group.Name, group.Icon, group.StartContentId, group.StartMediaId, group.Alias, group.AllowedSections, group.Permissions);
|
||||
}
|
||||
|
||||
public static bool IsSystemUserGroup(this IUserGroup group) =>
|
||||
IsSystemUserGroup(group.Alias);
|
||||
|
||||
public static bool IsSystemUserGroup(this IReadOnlyUserGroup group) =>
|
||||
IsSystemUserGroup(group.Alias);
|
||||
|
||||
public static IReadOnlyUserGroup ToReadOnlyGroup(this UserGroupDto group)
|
||||
{
|
||||
return new ReadOnlyUserGroup(group.Id, group.Name, group.Icon,
|
||||
group.StartContentId, group.StartMediaId, group.Alias,
|
||||
group.UserGroup2AppDtos.Select(x => x.AppAlias).ToArray(),
|
||||
group.DefaultPermissions == null ? Enumerable.Empty<string>() : group.DefaultPermissions.ToCharArray().Select(x => x.ToString()));
|
||||
}
|
||||
|
||||
private static bool IsSystemUserGroup(this string groupAlias)
|
||||
{
|
||||
return groupAlias == Constants.Security.AdminGroupAlias
|
||||
|| groupAlias == Constants.Security.SensitiveDataGroupAlias
|
||||
|| groupAlias == Constants.Security.TranslatorGroupAlias;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user