# Conflicts: # .gitignore # build/NuSpecs/UmbracoCms.Core.nuspec # src/SolutionInfo.cs # src/Umbraco.Core/Configuration/UmbracoSettings/BackOfficeElement.cs # src/Umbraco.Core/Configuration/UmbracoSettings/ContentElement.cs # src/Umbraco.Core/Configuration/UmbracoSettings/IBackOfficeSection.cs # src/Umbraco.Core/Configuration/UmbracoSettings/IContentSection.cs # src/Umbraco.Core/IO/SystemFiles.cs # src/Umbraco.Core/Models/ContentBase.cs # src/Umbraco.Core/Models/Identity/BackOfficeIdentityUser.cs # src/Umbraco.Core/Persistence/UmbracoDatabaseExtensions.cs # src/Umbraco.Core/Runtime/CoreRuntime.cs # src/Umbraco.Core/RuntimeOptions.cs # src/Umbraco.Core/RuntimeState.cs # src/Umbraco.Core/Telemetry/TelemetryMarkerComponent.cs # src/Umbraco.Core/Telemetry/TelemetryMarkerComposer.cs # src/Umbraco.Examine/Umbraco.Examine.csproj # src/Umbraco.Infrastructure/HostedServices/ReportSiteTask.cs # src/Umbraco.Infrastructure/Install/InstallStepCollection.cs # src/Umbraco.Infrastructure/Install/InstallSteps/NewInstallStep.cs # src/Umbraco.Infrastructure/Migrations/Install/DatabaseBuilder.cs # src/Umbraco.Infrastructure/Migrations/Install/DatabaseSchemaCreator.cs # src/Umbraco.Infrastructure/Runtime/SqlMainDomLock.cs # src/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/ContentTypeRepositoryTest.cs # src/Umbraco.Tests/Runtimes/CoreRuntimeTests.cs # src/Umbraco.Tests/Runtimes/StandaloneTests.cs # src/Umbraco.Tests/Testing/TestDatabase.cs # src/Umbraco.Web.BackOffice/Controllers/BackOfficeServerVariables.cs # src/Umbraco.Web.UI.Client/src/installer/steps/database.controller.js # src/Umbraco.Web.UI.NetCore/Views/Partials/Grid/Editors/TextString.cshtml # src/Umbraco.Web.UI.NetCore/umbraco/config/lang/da.xml # src/Umbraco.Web.UI.NetCore/umbraco/config/lang/en.xml # src/Umbraco.Web.UI.NetCore/umbraco/config/lang/en_us.xml # src/Umbraco.Web.UI/Umbraco/config/lang/cs.xml # src/Umbraco.Web.UI/config/umbracoSettings.Release.config # src/Umbraco.Web/Composing/CompositionExtensions/Installer.cs # src/Umbraco.Web/Editors/PreviewController.cs # src/Umbraco.Web/Editors/UsersController.cs # src/Umbraco.Web/JavaScript/PreviewInitialize.js # src/Umbraco.Web/Telemetry/TelemetryComponent.cs # src/Umbraco.Web/UmbracoApplication.cs
158 lines
5.2 KiB
C#
158 lines
5.2 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Collections.ObjectModel;
|
|
using System.Collections.Specialized;
|
|
using System.Linq;
|
|
using System.Runtime.Serialization;
|
|
using Umbraco.Core.Collections;
|
|
using Umbraco.Core.Models.Entities;
|
|
|
|
namespace Umbraco.Core.Models
|
|
{
|
|
[Serializable]
|
|
[DataContract(IsReference = true)]
|
|
public class PublicAccessEntry : EntityBase
|
|
{
|
|
private readonly EventClearingObservableCollection<PublicAccessRule> _ruleCollection;
|
|
private int _protectedNodeId;
|
|
private int _noAccessNodeId;
|
|
private int _loginNodeId;
|
|
private readonly List<Guid> _removedRules = new List<Guid>();
|
|
|
|
public PublicAccessEntry(IContent protectedNode, IContent loginNode, IContent noAccessNode, IEnumerable<PublicAccessRule> ruleCollection)
|
|
{
|
|
if (protectedNode == null) throw new ArgumentNullException(nameof(protectedNode));
|
|
if (loginNode == null) throw new ArgumentNullException(nameof(loginNode));
|
|
if (noAccessNode == null) throw new ArgumentNullException(nameof(noAccessNode));
|
|
|
|
LoginNodeId = loginNode.Id;
|
|
NoAccessNodeId = noAccessNode.Id;
|
|
_protectedNodeId = protectedNode.Id;
|
|
|
|
_ruleCollection = new EventClearingObservableCollection<PublicAccessRule>(ruleCollection);
|
|
_ruleCollection.CollectionChanged += _ruleCollection_CollectionChanged;
|
|
|
|
foreach (var rule in _ruleCollection)
|
|
rule.AccessEntryId = Key;
|
|
}
|
|
|
|
public PublicAccessEntry(Guid id, int protectedNodeId, int loginNodeId, int noAccessNodeId, IEnumerable<PublicAccessRule> ruleCollection)
|
|
{
|
|
Key = id;
|
|
Id = Key.GetHashCode();
|
|
|
|
LoginNodeId = loginNodeId;
|
|
NoAccessNodeId = noAccessNodeId;
|
|
_protectedNodeId = protectedNodeId;
|
|
|
|
_ruleCollection = new EventClearingObservableCollection<PublicAccessRule>(ruleCollection);
|
|
_ruleCollection.CollectionChanged += _ruleCollection_CollectionChanged;
|
|
|
|
foreach (var rule in _ruleCollection)
|
|
rule.AccessEntryId = Key;
|
|
}
|
|
|
|
void _ruleCollection_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
|
|
{
|
|
OnPropertyChanged(nameof(Rules));
|
|
|
|
//if (e.Action == NotifyCollectionChangedAction.Add)
|
|
//{
|
|
// var item = e.NewItems.Cast<PublicAccessRule>().First();
|
|
|
|
// if (_addedSections.Contains(item) == false)
|
|
// {
|
|
// _addedSections.Add(item);
|
|
// }
|
|
//}
|
|
|
|
if (e.Action == NotifyCollectionChangedAction.Remove)
|
|
{
|
|
var item = e.OldItems.Cast<PublicAccessRule>().First();
|
|
|
|
if (_removedRules.Contains(item.Key) == false)
|
|
{
|
|
_removedRules.Add(item.Key);
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
public IEnumerable<Guid> RemovedRules => _removedRules;
|
|
|
|
public IEnumerable<PublicAccessRule> Rules => _ruleCollection;
|
|
|
|
public PublicAccessRule AddRule(string ruleValue, string ruleType)
|
|
{
|
|
var rule = new PublicAccessRule
|
|
{
|
|
AccessEntryId = Key,
|
|
RuleValue = ruleValue,
|
|
RuleType = ruleType
|
|
};
|
|
_ruleCollection.Add(rule);
|
|
return rule;
|
|
}
|
|
|
|
public void RemoveRule(PublicAccessRule rule)
|
|
{
|
|
_ruleCollection.Remove(rule);
|
|
}
|
|
|
|
public void ClearRules()
|
|
{
|
|
_ruleCollection.Clear();
|
|
}
|
|
|
|
|
|
internal void ClearRemovedRules()
|
|
{
|
|
_removedRules.Clear();
|
|
}
|
|
|
|
[DataMember]
|
|
public int LoginNodeId
|
|
{
|
|
get => _loginNodeId;
|
|
set => SetPropertyValueAndDetectChanges(value, ref _loginNodeId, nameof(LoginNodeId));
|
|
}
|
|
|
|
[DataMember]
|
|
public int NoAccessNodeId
|
|
{
|
|
get => _noAccessNodeId;
|
|
set => SetPropertyValueAndDetectChanges(value, ref _noAccessNodeId, nameof(NoAccessNodeId));
|
|
}
|
|
|
|
[DataMember]
|
|
public int ProtectedNodeId
|
|
{
|
|
get => _protectedNodeId;
|
|
set => SetPropertyValueAndDetectChanges(value, ref _protectedNodeId, nameof(ProtectedNodeId));
|
|
}
|
|
|
|
public override void ResetDirtyProperties(bool rememberDirty)
|
|
{
|
|
_removedRules.Clear();
|
|
base.ResetDirtyProperties(rememberDirty);
|
|
foreach (var publicAccessRule in _ruleCollection)
|
|
{
|
|
publicAccessRule.ResetDirtyProperties(rememberDirty);
|
|
}
|
|
}
|
|
|
|
protected override void PerformDeepClone(object clone)
|
|
{
|
|
base.PerformDeepClone(clone);
|
|
|
|
var cloneEntity = (PublicAccessEntry)clone;
|
|
|
|
if (cloneEntity._ruleCollection != null)
|
|
{
|
|
cloneEntity._ruleCollection.ClearCollectionChangedEvents(); //clear this event handler if any
|
|
cloneEntity._ruleCollection.CollectionChanged += cloneEntity._ruleCollection_CollectionChanged; //re-assign correct event handler
|
|
}
|
|
}
|
|
}
|
|
}
|