Files
Umbraco-CMS/tests/Umbraco.Tests/LegacyXmlPublishedCache/PublishedMember.cs

155 lines
6.2 KiB
C#
Raw Normal View History

using System;
2014-03-11 14:23:51 +11:00
using System.Collections.Generic;
using System.Linq;
using Umbraco.Cms.Core.Models;
using Umbraco.Cms.Core.Models.Membership;
using Umbraco.Cms.Core.Models.PublishedContent;
using Umbraco.Cms.Core.Services;
using Umbraco.Extensions;
2014-03-11 14:23:51 +11:00
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 21:21:43 +10:00
namespace Umbraco.Tests.LegacyXmlPublishedCache
2014-03-11 14:23:51 +11:00
{
/// <summary>
/// Exposes a member object as IPublishedContent
/// </summary>
public sealed class PublishedMember : PublishedContentBase
2014-03-11 14:23:51 +11:00
{
private readonly IMember _member;
private readonly IMembershipUser _membershipUser;
private readonly IPublishedProperty[] _properties;
2019-04-15 13:04:14 +02:00
private readonly IPublishedContentType _publishedMemberType;
2014-03-11 14:23:51 +11:00
public PublishedMember(
IMember member,
2019-12-18 13:38:03 +01:00
IPublishedContentType publishedMemberType,
IVariationContextAccessor variationContextAccessor) : base(variationContextAccessor)
2014-03-11 14:23:51 +11:00
{
_member = member ?? throw new ArgumentNullException(nameof(member));
_membershipUser = member;
_publishedMemberType = publishedMemberType ?? throw new ArgumentNullException(nameof(publishedMemberType));
// RawValueProperty is used for two things here
// - for the 'map properties' thing that we should really get rid of
// - for populating properties that every member should always have, and that we force-create
// if they are not part of the member type properties - in which case they are created as
// simple raw properties - which are completely invariant
var properties = new List<IPublishedProperty>();
foreach (var propertyType in _publishedMemberType.PropertyTypes)
{
var property = _member.Properties[propertyType.Alias];
if (property == null) continue;
2019-04-22 11:58:51 +02:00
properties.Add(new RawValueProperty(propertyType, this, property.GetValue()));
}
EnsureMemberProperties(properties);
_properties = properties.ToArray();
2014-03-11 14:23:51 +11:00
}
#region Membership provider member properties
2016-06-03 10:57:54 +02:00
public string Email => _membershipUser.Email;
public string UserName => _membershipUser.Username;
public string Comments => _membershipUser.Comments;
public bool IsApproved => _membershipUser.IsApproved;
public bool IsLockedOut => _membershipUser.IsLockedOut;
public DateTime LastLockoutDate => _membershipUser.LastLockoutDate;
public DateTime CreationDate => _membershipUser.CreateDate;
public DateTime LastLoginDate => _membershipUser.LastLoginDate;
public DateTime LastPasswordChangeDate => _membershipUser.LastPasswordChangeDate;
2014-03-11 14:23:51 +11:00
#endregion
#region IPublishedContent
public override PublishedItemType ItemType => PublishedItemType.Member;
public override bool IsDraft(string culture = null) => false;
2014-03-11 14:23:51 +11:00
public override bool IsPublished(string culture = null) => true;
public override IPublishedContent Parent => null;
public override IEnumerable<IPublishedContent> Children => Enumerable.Empty<IPublishedContent>();
2014-03-11 14:23:51 +11:00
public override IEnumerable<IPublishedContent> ChildrenForAllCultures => Enumerable.Empty<IPublishedContent>();
2016-06-03 10:57:54 +02:00
public override IEnumerable<IPublishedProperty> Properties => _properties;
2014-03-11 14:23:51 +11:00
public override IPublishedProperty GetProperty(string alias)
{
return _properties.FirstOrDefault(x => x.Alias.InvariantEquals(alias));
2014-03-11 14:23:51 +11:00
}
private void EnsureMemberProperties(List<IPublishedProperty> properties)
2017-09-26 14:57:50 +02:00
{
var aliases = properties.Select(x => x.Alias).ToList();
EnsureMemberProperty(properties, aliases, nameof(IMember.Email), Email);
EnsureMemberProperty(properties, aliases, nameof(IMember.Username), UserName);
EnsureMemberProperty(properties, aliases, nameof(IMember.Comments), Comments);
EnsureMemberProperty(properties, aliases, nameof(IMember.IsApproved), IsApproved);
EnsureMemberProperty(properties, aliases, nameof(IMember.IsLockedOut), IsLockedOut);
EnsureMemberProperty(properties, aliases, nameof(IMember.LastLockoutDate), LastLockoutDate);
EnsureMemberProperty(properties, aliases, nameof(IMember.CreateDate), CreateDate);
EnsureMemberProperty(properties, aliases, nameof(IMember.LastLoginDate), LastLoginDate);
EnsureMemberProperty(properties, aliases, nameof(IMember.LastPasswordChangeDate), LastPasswordChangeDate);
}
private void EnsureMemberProperty(List<IPublishedProperty> properties, List<string> aliases, string alias, object value)
{
// if the property already has a value, nothing to do
if (aliases.Contains(alias)) return;
// if not a property type, ignore
var propertyType = ContentType.GetPropertyType(alias);
if (propertyType == null) return;
// create a raw-value property
// note: throws if propertyType variations is not InvariantNeutral
var property = new RawValueProperty(propertyType, this, value);
properties.Add(property);
2017-09-26 14:57:50 +02:00
}
2019-04-15 13:04:14 +02:00
public override IPublishedContentType ContentType => _publishedMemberType;
2014-03-11 14:23:51 +11:00
2016-06-03 10:57:54 +02:00
public override int Id => _member.Id;
2014-03-11 14:23:51 +11:00
2016-06-03 10:57:54 +02:00
public override Guid Key => _member.Key;
public override int? TemplateId => throw new NotSupportedException();
2014-03-11 14:23:51 +11:00
2016-06-03 10:57:54 +02:00
public override int SortOrder => 0;
2014-03-11 14:23:51 +11:00
public override string Name => _member.Name;
public override IReadOnlyDictionary<string, PublishedCultureInfo> Cultures => throw new NotSupportedException();
2014-03-11 14:23:51 +11:00
public override string UrlSegment => throw new NotSupportedException();
2014-03-11 14:23:51 +11:00
2016-06-03 10:57:54 +02:00
public override int WriterId => _member.CreatorId;
2014-03-11 14:23:51 +11:00
2016-06-03 10:57:54 +02:00
public override int CreatorId => _member.CreatorId;
2014-03-11 14:23:51 +11:00
2016-06-03 10:57:54 +02:00
public override string Path => _member.Path;
2014-03-11 14:23:51 +11:00
2016-06-03 10:57:54 +02:00
public override DateTime CreateDate => _member.CreateDate;
2014-03-11 14:23:51 +11:00
2016-06-03 10:57:54 +02:00
public override DateTime UpdateDate => _member.UpdateDate;
2014-03-11 14:23:51 +11:00
2016-06-03 10:57:54 +02:00
public override int Level => _member.Level;
2014-03-11 14:23:51 +11:00
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 21:21:43 +10:00
public DateTime LastPasswordChangedDate => throw new NotImplementedException();
2014-03-11 14:23:51 +11:00
#endregion
}
}