mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2026-01-22 21:02:08 +08:00
Fixing a problem caused applying a patch
--HG-- extra : convert_revision : svn%3A5ff7c347-ad56-4c35-b696-ccb81de16e03/trunk%4045863
This commit is contained in:
@@ -46,51 +46,3 @@ namespace Orchard.Pages.Security {
|
||||
|
||||
}
|
||||
}
|
||||
using JetBrains.Annotations;
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.ContentManagement.Aspects;
|
||||
using Orchard.Pages.Models;
|
||||
using Orchard.Security;
|
||||
using Orchard.Security.Permissions;
|
||||
|
||||
namespace Orchard.Pages.Security {
|
||||
[UsedImplicitly]
|
||||
public class Authorization : AuthorizationServiceEvents {
|
||||
public override void Adjust(CheckAccessContext context) {
|
||||
if (context.Granted == false &&
|
||||
context.Content.Is<Page>() &&
|
||||
HasOwnerVariation(context.Permission) &&
|
||||
HasOwnership(context.User, context.Content)) {
|
||||
|
||||
context.Adjusted = true;
|
||||
context.Permission = GetOwnerVariation(context.Permission);
|
||||
}
|
||||
}
|
||||
|
||||
private static bool HasOwnership(IUser user, IContent content) {
|
||||
if (user==null || content==null)
|
||||
return false;
|
||||
|
||||
var common = content.As<ICommonAspect>();
|
||||
if (common==null || common.Owner==null)
|
||||
return false;
|
||||
|
||||
return user.Id == common.Owner.Id;
|
||||
}
|
||||
|
||||
private static bool HasOwnerVariation(Permission permission) {
|
||||
return GetOwnerVariation(permission) != null;
|
||||
}
|
||||
|
||||
private static Permission GetOwnerVariation(Permission permission) {
|
||||
if (permission.Name == Permissions.PublishOthersPages.Name)
|
||||
return Permissions.PublishPages;
|
||||
if (permission.Name == Permissions.EditOthersPages.Name)
|
||||
return Permissions.EditPages;
|
||||
if (permission.Name == Permissions.DeleteOthersPages.Name)
|
||||
return Permissions.DeletePages;
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,28 +23,3 @@ namespace Orchard.Security {
|
||||
public virtual void Complete(CheckAccessContext context) { }
|
||||
}
|
||||
}
|
||||
using System;
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.Security.Permissions;
|
||||
|
||||
namespace Orchard.Security {
|
||||
public interface IAuthorizationServiceEvents : IEvents {
|
||||
void Checking(CheckAccessContext context);
|
||||
void Adjust(CheckAccessContext context);
|
||||
void Complete(CheckAccessContext context);
|
||||
}
|
||||
|
||||
public class CheckAccessContext {
|
||||
public Permission Permission { get; set; }
|
||||
public IUser User { get; set; }
|
||||
public IContent Content { get; set; }
|
||||
public bool Granted { get; set; }
|
||||
public bool Adjusted { get; set; }
|
||||
}
|
||||
|
||||
public abstract class AuthorizationServiceEvents : IAuthorizationServiceEvents {
|
||||
public virtual void Checking(CheckAccessContext context) { }
|
||||
public virtual void Adjust(CheckAccessContext context) { }
|
||||
public virtual void Complete(CheckAccessContext context) { }
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user