Removes more usages of legacy Access class to use new IPublicAccessService
This commit is contained in:
@@ -20,12 +20,7 @@ namespace Umbraco.Core.Models
|
||||
/// </summary>
|
||||
bool Published { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Language of the data contained within this Content object.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Left internal until multilingual support is implemented.
|
||||
/// </remarks>
|
||||
[Obsolete("This will be removed in future versions")]
|
||||
string Language { get; set; }
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -11,7 +11,37 @@ namespace Umbraco.Core.Services
|
||||
public static class PublicAccessServiceExtensions
|
||||
{
|
||||
|
||||
internal static bool HasAccess(this IPublicAccessService publicAccessService, int documentId, IContentService contentService, IEnumerable<string> currentMemberRoles)
|
||||
public static bool RenameMemberGroupRoleRules(this IPublicAccessService publicAccessService, string oldRolename, string newRolename)
|
||||
{
|
||||
var hasChange = false;
|
||||
if (oldRolename == newRolename) return false;
|
||||
|
||||
var allEntries = publicAccessService.GetAll();
|
||||
|
||||
foreach (var entry in allEntries)
|
||||
{
|
||||
//get rules that match
|
||||
var roleRules = entry.Rules
|
||||
.Where(x => x.RuleType == Constants.Conventions.PublicAccess.MemberRoleRuleType)
|
||||
.Where(x => x.RuleValue == oldRolename);
|
||||
var save = false;
|
||||
foreach (var roleRule in roleRules)
|
||||
{
|
||||
//a rule is being updated so flag this entry to be saved
|
||||
roleRule.RuleValue = newRolename;
|
||||
save = true;
|
||||
}
|
||||
if (save)
|
||||
{
|
||||
hasChange = true;
|
||||
publicAccessService.Save(entry);
|
||||
}
|
||||
}
|
||||
|
||||
return hasChange;
|
||||
}
|
||||
|
||||
public static bool HasAccess(this IPublicAccessService publicAccessService, int documentId, IContentService contentService, IEnumerable<string> currentMemberRoles)
|
||||
{
|
||||
var content = contentService.GetById(documentId);
|
||||
if (content == null) return true;
|
||||
|
||||
@@ -10,7 +10,7 @@ using Umbraco.Core.Services;
|
||||
namespace Umbraco.Web.Strategies
|
||||
{
|
||||
/// <summary>
|
||||
/// Used to ensure that the access.xml file is kept up to date properly
|
||||
/// Used to ensure that the public access data file is kept up to date properly
|
||||
/// </summary>
|
||||
public sealed class PublicAccessEventHandler : ApplicationEventHandler
|
||||
{
|
||||
@@ -31,7 +31,7 @@ namespace Umbraco.Web.Strategies
|
||||
&& grp.AdditionalData["previousName"].ToString().IsNullOrWhiteSpace() == false
|
||||
&& grp.AdditionalData["previousName"].ToString() != grp.Name)
|
||||
{
|
||||
Access.RenameMemberShipRole(grp.AdditionalData["previousName"].ToString(), grp.Name);
|
||||
ApplicationContext.Current.Services.PublicAccessService.RenameMemberGroupRoleRules(grp.AdditionalData["previousName"].ToString(), grp.Name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -106,7 +106,7 @@ namespace Umbraco.Web.Trees
|
||||
if (entity.HasPendingChanges)
|
||||
node.SetHasUnpublishedVersionStyle();
|
||||
|
||||
if (Access.IsProtected(e.Id, e.Path))
|
||||
if (Services.PublicAccessService.IsProtected(e.Path))
|
||||
node.SetProtectedStyle();
|
||||
|
||||
return node;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.ComponentModel;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
@@ -14,6 +15,7 @@ using Umbraco.Core.Dictionary;
|
||||
using Umbraco.Core.Dynamics;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Security;
|
||||
using Umbraco.Core.Services;
|
||||
using Umbraco.Core.Xml;
|
||||
using Umbraco.Web.Routing;
|
||||
using Umbraco.Web.Security;
|
||||
@@ -23,6 +25,7 @@ using System.Collections.Generic;
|
||||
using umbraco.cms.businesslogic.web;
|
||||
using umbraco.presentation.templateControls;
|
||||
using Umbraco.Core.Cache;
|
||||
using AttributeCollection = System.Web.UI.AttributeCollection;
|
||||
|
||||
namespace Umbraco.Web
|
||||
{
|
||||
@@ -484,32 +487,44 @@ namespace Umbraco.Web
|
||||
|
||||
#region Membership
|
||||
|
||||
/// <summary>
|
||||
/// Check if a document object is protected by the "Protect Pages" functionality in umbraco
|
||||
/// </summary>
|
||||
/// <param name="documentId">The identifier of the document object to check</param>
|
||||
/// <param name="path">The full path of the document object to check</param>
|
||||
/// <returns>True if the document object is protected</returns>
|
||||
public bool IsProtected(int documentId, string path)
|
||||
[EditorBrowsable(EditorBrowsableState.Never)]
|
||||
[Obsolete("Use the IsProtected method that only specifies path")]
|
||||
public bool IsProtected(int documentId, string path)
|
||||
{
|
||||
return Access.IsProtected(documentId, path);
|
||||
return IsProtected(path.EnsureEndsWith("," + documentId));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Check if the current user has access to a document
|
||||
/// </summary>
|
||||
/// <param name="nodeId">The identifier of the document object to check</param>
|
||||
/// <param name="path">The full path of the document object to check</param>
|
||||
/// <returns>True if the current user has access or if the current document isn't protected</returns>
|
||||
public bool MemberHasAccess(int nodeId, string path)
|
||||
{
|
||||
if (IsProtected(nodeId, path))
|
||||
{
|
||||
/// <summary>
|
||||
/// Check if a document object is protected by the "Protect Pages" functionality in umbraco
|
||||
/// </summary>
|
||||
/// <param name="path">The full path of the document object to check</param>
|
||||
/// <returns>True if the document object is protected</returns>
|
||||
public bool IsProtected(string path)
|
||||
{
|
||||
return UmbracoContext.Application.Services.PublicAccessService.IsProtected(path);
|
||||
}
|
||||
|
||||
[EditorBrowsable(EditorBrowsableState.Never)]
|
||||
[Obsolete("Use the MemberHasAccess method that only specifies path")]
|
||||
public bool MemberHasAccess(int nodeId, string path)
|
||||
{
|
||||
return MemberHasAccess(path.EnsureEndsWith("," + nodeId));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Check if the current user has access to a document
|
||||
/// </summary>
|
||||
/// <param name="path">The full path of the document object to check</param>
|
||||
/// <returns>True if the current user has access or if the current document isn't protected</returns>
|
||||
public bool MemberHasAccess(string path)
|
||||
{
|
||||
if (IsProtected(path))
|
||||
{
|
||||
return _membershipHelper.IsLoggedIn()
|
||||
&& Access.HasAccess(nodeId, path, GetCurrentMember());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
&& UmbracoContext.Application.Services.PublicAccessService.HasAccess(path, GetCurrentMember(), Roles.Provider);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets (or adds) the current member from the current request cache
|
||||
|
||||
@@ -180,30 +180,8 @@ namespace umbraco.cms.businesslogic.web
|
||||
|
||||
public static bool RenameMemberShipRole(string oldRolename, string newRolename)
|
||||
{
|
||||
var hasChange = false;
|
||||
if (oldRolename == newRolename) return false;
|
||||
|
||||
var allEntries = ApplicationContext.Current.Services.PublicAccessService.GetAll();
|
||||
|
||||
foreach (var entry in allEntries)
|
||||
{
|
||||
//get rules that match
|
||||
var roleRules = entry.Rules
|
||||
.Where(x => x.RuleType == Constants.Conventions.PublicAccess.MemberRoleRuleType)
|
||||
.Where(x => x.RuleValue == oldRolename);
|
||||
var save = false;
|
||||
foreach (var roleRule in roleRules)
|
||||
{
|
||||
//a rule is being updated so flag this entry to be saved
|
||||
roleRule.RuleValue = newRolename;
|
||||
save = true;
|
||||
}
|
||||
if (save)
|
||||
{
|
||||
hasChange = true;
|
||||
ApplicationContext.Current.Services.PublicAccessService.Save(entry);
|
||||
}
|
||||
}
|
||||
var hasChange = ApplicationContext.Current.Services.PublicAccessService.RenameMemberGroupRoleRules(oldRolename, newRolename);
|
||||
|
||||
if (hasChange)
|
||||
Save();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user