removes todos, reverts tree controller, fixes up review notes.

This commit is contained in:
Shannon
2021-03-26 14:18:41 +11:00
parent 33b5f402b4
commit db3dc01321
4 changed files with 19 additions and 38 deletions

View File

@@ -119,7 +119,7 @@ namespace Umbraco.Cms.Core.Models.Mapping
Value = _localizedTextService.UmbracoDictionaryTranslate(CultureDictionary, member.ContentType.Name),
View = _propertyEditorCollection[Constants.PropertyEditors.Aliases.Label].GetValueEditor().View
},
GetLoginProperty(_memberTypeService, member, _localizedTextService),
GetLoginProperty(member, _localizedTextService),
new ContentPropertyDisplay
{
Alias = $"{Constants.PropertyEditors.InternalGenericPropertiesPrefix}email",
@@ -208,7 +208,6 @@ namespace Umbraco.Cms.Core.Models.Mapping
/// <summary>
/// Returns the login property display field
/// </summary>
/// <param name="memberTypeService"></param>
/// <param name="member"></param>
/// <param name="display"></param>
/// <param name="localizedText"></param>
@@ -218,7 +217,7 @@ namespace Umbraco.Cms.Core.Models.Mapping
/// the membership provider is a custom one, we cannot allow changing the username because MembershipProvider's do not actually natively
/// allow that.
/// </remarks>
internal static ContentPropertyDisplay GetLoginProperty(IMemberTypeService memberTypeService, IMember member, ILocalizedTextService localizedText)
internal static ContentPropertyDisplay GetLoginProperty(IMember member, ILocalizedTextService localizedText)
{
var prop = new ContentPropertyDisplay
{
@@ -234,10 +233,9 @@ namespace Umbraco.Cms.Core.Models.Mapping
internal IDictionary<string, bool> GetMemberGroupValue(string username)
{
var userRoles = username.IsNullOrWhiteSpace() ? null : _memberService.GetAllRoles(username);
IEnumerable<string> userRoles = username.IsNullOrWhiteSpace() ? null : _memberService.GetAllRoles(username);
// create a dictionary of all roles (except internal roles) + "false"
//TODO: use member role manager instead
var result = _memberGroupService.GetAll()
.Select(x => x.Name)
// if a role starts with __umbracoRole we won't show it as it's an internal role used for public access
@@ -246,11 +244,16 @@ namespace Umbraco.Cms.Core.Models.Mapping
.ToDictionary(x => x, x => false);
// if user has no roles, just return the dictionary
if (userRoles == null) return result;
if (userRoles == null)
{
return result;
}
// else update the dictionary to "true" for the user roles (except internal roles)
foreach (var userRole in userRoles.Where(x => x.StartsWith(Constants.Conventions.Member.InternalRolePrefix) == false))
{
result[userRole] = true;
}
return result;
}

View File

@@ -363,13 +363,6 @@ namespace Umbraco.Cms.Core.Security
cancellationToken.ThrowIfCancellationRequested();
ThrowIfDisposed();
MemberIdentityUser user = await FindUserAsync(userId, cancellationToken);
if (user == null)
{
//TODO: error throw or null result?
return await Task.FromResult((IdentityUserLogin<string>)null);
}
if (string.IsNullOrWhiteSpace(loginProvider))
{
throw new ArgumentNullException(nameof(loginProvider));
@@ -380,11 +373,16 @@ namespace Umbraco.Cms.Core.Security
throw new ArgumentNullException(nameof(providerKey));
}
MemberIdentityUser user = await FindUserAsync(userId, cancellationToken);
if (user == null)
{
return await Task.FromResult((IdentityUserLogin<string>)null);
}
IList<UserLoginInfo> logins = await GetLoginsAsync(user, cancellationToken);
UserLoginInfo found = logins.FirstOrDefault(x => x.ProviderKey == providerKey && x.LoginProvider == loginProvider);
if (found == null)
{
//TODO: error throw or null result?
return await Task.FromResult((IdentityUserLogin<string>)null);
}

View File

@@ -35,7 +35,6 @@ namespace Umbraco.Cms.Web.BackOffice.Mapping
mapper.Define<IMember, MemberDisplay>((source, context) => new MemberDisplay(), Map);
mapper.Define<IMember, MemberBasic>((source, context) => new MemberBasic(), Map);
mapper.Define<IMemberGroup, MemberGroupDisplay>((source, context) => new MemberGroupDisplay(), Map);
mapper.Define<IdentityRole, MemberGroupDisplay>((source, context) => new MemberGroupDisplay(), Map);
mapper.Define<IMember, ContentPropertyCollectionDto>((source, context) => new ContentPropertyCollectionDto(), Map);
}
@@ -103,18 +102,5 @@ namespace Umbraco.Cms.Web.BackOffice.Mapping
{
target.Properties = context.MapEnumerable<IProperty, ContentPropertyDto>(source.Properties);
}
/// <summary>
/// Maps an identity role to a member group display
/// </summary>
/// <param name="arg1"></param>
/// <param name="arg2"></param>
/// <param name="arg3"></param>
private void Map(IdentityRole source, MemberGroupDisplay target, MapperContext context)
{
//TODO: this is all that is mapped at this time, we're losing a lot of properties
target.Id = source.Id;
target.Name = source.Name;
}
}
}

View File

@@ -28,29 +28,23 @@ namespace Umbraco.Cms.Web.BackOffice.Trees
IMemberGroupService memberGroupService,
IEventAggregator eventAggregator)
: base(localizedTextService, umbracoApiControllerTypeCollection, menuItemCollectionFactory, eventAggregator)
{
_memberGroupService = memberGroupService;
}
=> _memberGroupService = memberGroupService;
//TODO: change to role store
protected override IEnumerable<TreeNode> GetTreeNodesFromService(string id, FormCollection queryStrings)
{
return _memberGroupService.GetAll()
=> _memberGroupService.GetAll()
.OrderBy(x => x.Name)
.Select(dt => CreateTreeNode(dt.Id.ToString(), id, queryStrings, dt.Name, Constants.Icons.MemberGroup, false));
}
protected override ActionResult<TreeNode> CreateRootNode(FormCollection queryStrings)
{
var rootResult = base.CreateRootNode(queryStrings);
ActionResult<TreeNode> rootResult = base.CreateRootNode(queryStrings);
if (!(rootResult.Result is null))
{
return rootResult;
}
var root = rootResult.Value;
TreeNode root = rootResult.Value;
//check if there are any groups
//TODO: change to role store
root.HasChildren = _memberGroupService.GetAll().Any();
return root;
}