files tree made better.
This commit is contained in:
parent
ffbf032480
commit
ccc91bbf19
1630 changed files with 18209 additions and 41860 deletions
34
src/Yavsc/AuthorizationHandlers/BlogViewHandler.cs
Normal file
34
src/Yavsc/AuthorizationHandlers/BlogViewHandler.cs
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
using System.Linq;
|
||||
using System.Security.Claims;
|
||||
using Microsoft.AspNet.Authorization;
|
||||
using Yavsc.Models.Blog;
|
||||
|
||||
namespace Yavsc.ViewModels.Auth.Handlers
|
||||
{
|
||||
public class BlogViewHandler : AuthorizationHandler<ViewRequirement, BlogPost>
|
||||
{
|
||||
protected override void Handle(AuthorizationContext context, ViewRequirement requirement, BlogPost resource)
|
||||
{
|
||||
bool ok=false;
|
||||
if (resource.Visible) {
|
||||
if (resource.ACL==null)
|
||||
ok=true;
|
||||
else if (resource.ACL.Count==0) ok=true;
|
||||
else {
|
||||
if (context.User.IsSignedIn()) {
|
||||
var uid = context.User.GetUserId();
|
||||
if (resource.ACL.Any(a=>a.Allowed!=null && a.Allowed.Members.Any(m=>m.MemberId == uid )))
|
||||
ok=true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (ok) context.Succeed(requirement);
|
||||
else {
|
||||
if (context.User.IsInRole(Constants.AdminGroupName) ||
|
||||
context.User.IsInRole(Constants.BlogModeratorGroupName))
|
||||
context.Succeed(requirement);
|
||||
else context.Fail();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue