2021-04-09 15:24:12 +10:00
|
|
|
using System;
|
2014-03-11 14:23:51 +11:00
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
2021-02-18 11:06:02 +01:00
|
|
|
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>
|
2016-06-09 19:38:51 +02:00
|
|
|
public sealed class PublishedMember : PublishedContentBase
|
2014-03-11 14:23:51 +11:00
|
|
|
{
|
|
|
|
|
private readonly IMember _member;
|
2014-07-08 18:07:59 +10:00
|
|
|
private readonly IMembershipUser _membershipUser;
|
2014-04-02 11:13:54 +02:00
|
|
|
private readonly IPublishedProperty[] _properties;
|
2019-04-15 13:04:14 +02:00
|
|
|
private readonly IPublishedContentType _publishedMemberType;
|
2014-03-11 14:23:51 +11:00
|
|
|
|
2019-01-23 14:16:42 +01:00
|
|
|
public PublishedMember(
|
|
|
|
|
IMember member,
|
2019-12-18 13:38:03 +01:00
|
|
|
IPublishedContentType publishedMemberType,
|
2019-12-19 10:43:00 +01:00
|
|
|
IVariationContextAccessor variationContextAccessor) : base(variationContextAccessor)
|
2014-03-11 14:23:51 +11:00
|
|
|
{
|
2017-07-21 17:19:00 +02:00
|
|
|
_member = member ?? throw new ArgumentNullException(nameof(member));
|
2014-07-08 18:07:59 +10:00
|
|
|
_membershipUser = member;
|
2017-07-21 17:19:00 +02:00
|
|
|
_publishedMemberType = publishedMemberType ?? throw new ArgumentNullException(nameof(publishedMemberType));
|
2014-04-02 11:13:54 +02:00
|
|
|
|
2018-01-10 12:48:51 +01:00
|
|
|
// 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()));
|
2018-01-10 12:48:51 +01:00
|
|
|
}
|
|
|
|
|
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
|
|
|
|
|
|
2019-06-06 16:54:00 +02:00
|
|
|
public override PublishedItemType ItemType => PublishedItemType.Member;
|
|
|
|
|
|
2018-12-13 15:08:12 +01:00
|
|
|
public override bool IsDraft(string culture = null) => false;
|
2014-03-11 14:23:51 +11:00
|
|
|
|
2019-01-23 07:54:45 +01:00
|
|
|
public override bool IsPublished(string culture = null) => true;
|
|
|
|
|
|
2019-06-06 16:54:00 +02:00
|
|
|
public override IPublishedContent Parent => null;
|
|
|
|
|
|
|
|
|
|
public override IEnumerable<IPublishedContent> Children => Enumerable.Empty<IPublishedContent>();
|
2014-03-11 14:23:51 +11:00
|
|
|
|
2019-06-06 16:54:00 +02:00
|
|
|
public override IEnumerable<IPublishedContent> ChildrenForAllCultures => Enumerable.Empty<IPublishedContent>();
|
2016-06-03 10:57:54 +02:00
|
|
|
|
2016-06-10 16:37:28 +02:00
|
|
|
public override IEnumerable<IPublishedProperty> Properties => _properties;
|
2014-03-11 14:23:51 +11:00
|
|
|
|
|
|
|
|
public override IPublishedProperty GetProperty(string alias)
|
|
|
|
|
{
|
2018-01-10 12:48:51 +01:00
|
|
|
return _properties.FirstOrDefault(x => x.Alias.InvariantEquals(alias));
|
2014-03-11 14:23:51 +11:00
|
|
|
}
|
|
|
|
|
|
2018-01-10 12:48:51 +01:00
|
|
|
private void EnsureMemberProperties(List<IPublishedProperty> properties)
|
2017-09-26 14:57:50 +02:00
|
|
|
{
|
2018-01-10 12:48:51 +01:00
|
|
|
var aliases = properties.Select(x => x.Alias).ToList();
|
|
|
|
|
|
2019-11-26 12:49:57 +11:00
|
|
|
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);
|
2018-01-10 12:48:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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;
|
2015-08-31 18:59:51 +02:00
|
|
|
|
2018-11-15 07:23:09 +00:00
|
|
|
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
|
|
|
|
2019-06-06 16:54:00 +02:00
|
|
|
public override string Name => _member.Name;
|
2018-04-24 01:31:01 +10:00
|
|
|
|
2019-06-06 16:54:00 +02:00
|
|
|
public override IReadOnlyDictionary<string, PublishedCultureInfo> Cultures => throw new NotSupportedException();
|
2014-03-11 14:23:51 +11:00
|
|
|
|
2019-06-06 16:54:00 +02: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
|
|
|
|
|
}
|
|
|
|
|
}
|