Files
Umbraco-CMS/src/Umbraco.PublishedCache.NuCache/PublishedMember.cs
Shannon Deminick 3792cafb9f Published members cleanup (#10159)
* Getting new netcore PublicAccessChecker in place

* Adds full test coverage for PublicAccessChecker

* remove PublicAccessComposer

* adjust namespaces, ensure RoleManager works, separate public access controller, reduce content controller

* Implements the required methods on IMemberManager, removes old migrated code

* Updates routing to be able to re-route, Fixes middleware ordering ensuring endpoints are last, refactors pipeline options, adds public access middleware, ensures public access follows all hops

* adds note

* adds note

* Cleans up ext methods, ensures that members identity is added on both front-end and back ends. updates how UmbracoApplicationBuilder works in that it explicitly starts endpoints at the time of calling.

* Changes name to IUmbracoEndpointBuilder

* adds note

* Fixing tests, fixing error describers so there's 2x one for back office, one for members, fixes TryConvertTo, fixes login redirect

* fixing build

* Updates user manager to correctly validate password hashing and injects the IBackOfficeUserPasswordChecker

* Merges PR

* Fixes up build and notes

* Implements security stamp and email confirmed for members, cleans up a bunch of repo/service level member groups stuff, shares user store code between members and users and fixes the user identity object so we arent' tracking both groups and roles.

* Security stamp for members is now working

* Fixes keepalive, fixes PublicAccessMiddleware to not throw, updates startup code to be more clear and removes magic that registers middleware.

* adds note

* removes unused filter, fixes build

* fixes WebPath and tests

* Looks up entities in one query

* remove usings

* Fix test, remove stylesheet

* Set status code before we write to response to avoid error

* Ensures that users and members are validated when logging in. Shares more code between users and members.

* merge changes

* oops

* Reducing and removing published member cache

* Fixes RepositoryCacheKeys to ensure the keys are normalized

* oops didn't mean to commit this

* Fix casing issues with caching, stop boxing value types for all cache operations, stop re-creating string keys in DefaultRepositoryCachePolicy

* oops didn't mean to comit this

* bah, far out this keeps getting recommitted. sorry

* cannot inject IPublishedMemberCache and cannot have IPublishedMember

* splits out files, fixes build

* fix tests

* removes membership provider classes

* removes membership provider classes

* updates the identity map definition

* reverts commented out lines

* reverts commented out lines

Co-authored-by: Bjarke Berg <mail@bergmania.dk>
2021-04-22 13:21:43 +02:00

130 lines
5.4 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using Umbraco.Cms.Core.Models;
using Umbraco.Cms.Core.Models.PublishedContent;
using Umbraco.Cms.Core.PublishedCache;
using Umbraco.Cms.Infrastructure.PublishedCache.DataSource;
using Umbraco.Extensions;
namespace Umbraco.Cms.Infrastructure.PublishedCache
{
// note
// the whole PublishedMember thing should be refactored because as soon as a member
// is wrapped on in a model, the inner IMember and all associated properties are lost
internal class PublishedMember : PublishedContent
{
private PublishedMember(
IMember member,
ContentNode contentNode,
ContentData contentData,
IPublishedSnapshotAccessor publishedSnapshotAccessor,
IVariationContextAccessor variationContextAccessor,
IPublishedModelFactory publishedModelFactory)
: base(contentNode, contentData, publishedSnapshotAccessor, variationContextAccessor, publishedModelFactory)
{
Member = member;
}
public static IPublishedContent Create(
IMember member,
IPublishedContentType contentType,
bool previewing,
IPublishedSnapshotAccessor publishedSnapshotAccessor,
IVariationContextAccessor variationContextAccessor,
IPublishedModelFactory publishedModelFactory)
{
var d = new ContentData
{
Name = member.Name,
Published = previewing,
TemplateId = -1,
VersionDate = member.UpdateDate,
WriterId = member.CreatorId, // what else?
Properties = GetPropertyValues(contentType, member)
};
var n = new ContentNode(
member.Id,
member.Key,
contentType,
member.Level,
member.Path,
member.SortOrder,
member.ParentId,
member.CreateDate,
member.CreatorId);
return new PublishedMember(member, n, d, publishedSnapshotAccessor, variationContextAccessor, publishedModelFactory)
.CreateModel(publishedModelFactory);
}
private static Dictionary<string, PropertyData[]> GetPropertyValues(IPublishedContentType contentType, IMember member)
{
// see node in PublishedSnapshotService
// we do not (want to) support ConvertDbToXml/String
//var propertyEditorResolver = PropertyEditorResolver.Current;
// see note in MemberType.Variations
// we don't want to support variations on members
var properties = member
.Properties
//.Select(property =>
//{
// var e = propertyEditorResolver.GetByAlias(property.PropertyType.PropertyEditorAlias);
// var v = e == null
// ? property.Value
// : e.ValueEditor.ConvertDbToString(property, property.PropertyType, ApplicationContext.Current.Services.DataTypeService);
// return new KeyValuePair<string, object>(property.Alias, v);
//})
//.ToDictionary(x => x.Key, x => x.Value);
.ToDictionary(x => x.Alias, x => new[] { new PropertyData { Value = x.GetValue(), Culture = string.Empty, Segment = string.Empty } }, StringComparer.OrdinalIgnoreCase);
// see also PublishedContentType
AddIf(contentType, properties, nameof(IMember.Email), member.Email);
AddIf(contentType, properties, nameof(IMember.Username), member.Username);
AddIf(contentType, properties, nameof(IMember.Comments), member.Comments);
AddIf(contentType, properties, nameof(IMember.IsApproved), member.IsApproved);
AddIf(contentType, properties, nameof(IMember.IsLockedOut), member.IsLockedOut);
AddIf(contentType, properties, nameof(IMember.LastLockoutDate), member.LastLockoutDate);
AddIf(contentType, properties, nameof(IMember.CreateDate), member.CreateDate);
AddIf(contentType, properties, nameof(IMember.LastLoginDate), member.LastLoginDate);
AddIf(contentType, properties, nameof(IMember.LastPasswordChangeDate), member.LastPasswordChangeDate);
return properties;
}
private static void AddIf(IPublishedContentType contentType, IDictionary<string, PropertyData[]> properties, string alias, object value)
{
var propertyType = contentType.GetPropertyType(alias);
if (propertyType == null || propertyType.IsUserProperty) return;
properties[alias] = new[] { new PropertyData { Value = value, Culture = string.Empty, Segment = string.Empty } };
}
#region IPublishedMember
public IMember Member { get; }
public string Email => Member.Email;
public string UserName => Member.Username;
public string Comments => Member.Comments;
public bool IsApproved => Member.IsApproved;
public bool IsLockedOut => Member.IsLockedOut;
public DateTime LastLockoutDate => Member.LastLockoutDate;
public DateTime CreationDate => Member.CreateDate;
public DateTime LastLoginDate => Member.LastLoginDate;
public DateTime LastPasswordChangedDate => Member.LastPasswordChangeDate;
#endregion
}
}