files tree made better.
This commit is contained in:
parent
ffbf032480
commit
ccc91bbf19
1630 changed files with 18209 additions and 41860 deletions
22
src/Yavsc/AuthorizationHandlers/AnnouceEditHandler.cs
Normal file
22
src/Yavsc/AuthorizationHandlers/AnnouceEditHandler.cs
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
|
||||
|
||||
using System.Security.Claims;
|
||||
using Microsoft.AspNet.Authorization;
|
||||
using Yavsc.Interfaces;
|
||||
|
||||
namespace Yavsc.ViewModels.Auth.Handlers
|
||||
{
|
||||
public class AnnouceEditHandler : AuthorizationHandler<EditRequirement, IOwned>
|
||||
{
|
||||
protected override void Handle(AuthorizationContext context, EditRequirement requirement,
|
||||
IOwned resource)
|
||||
{
|
||||
if (context.User.IsInRole(Constants.BlogModeratorGroupName)
|
||||
|| context.User.IsInRole(Constants.AdminGroupName))
|
||||
context.Succeed(requirement);
|
||||
if (resource.OwnerId == context.User.GetUserId())
|
||||
context.Succeed(requirement);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
20
src/Yavsc/AuthorizationHandlers/BillEditHandler.cs
Normal file
20
src/Yavsc/AuthorizationHandlers/BillEditHandler.cs
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
using System.Security.Claims;
|
||||
using Microsoft.AspNet.Authorization;
|
||||
|
||||
namespace Yavsc.ViewModels.Auth.Handlers
|
||||
{
|
||||
using Billing;
|
||||
public class BillEditHandler : AuthorizationHandler<EditRequirement, IBillable>
|
||||
{
|
||||
protected override void Handle(AuthorizationContext context, EditRequirement requirement, IBillable resource)
|
||||
{
|
||||
|
||||
if (context.User.IsInRole("FrontOffice"))
|
||||
context.Succeed(requirement);
|
||||
else if (context.User.Identity.IsAuthenticated)
|
||||
if (resource.ClientId == context.User.GetUserId())
|
||||
context.Succeed(requirement);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
22
src/Yavsc/AuthorizationHandlers/BillViewHandlers.cs
Normal file
22
src/Yavsc/AuthorizationHandlers/BillViewHandlers.cs
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
using System.Security.Claims;
|
||||
using Microsoft.AspNet.Authorization;
|
||||
|
||||
namespace Yavsc.ViewModels.Auth.Handlers
|
||||
{
|
||||
using Billing;
|
||||
|
||||
public class BillViewHandler : AuthorizationHandler<ViewRequirement, IBillable>
|
||||
{
|
||||
protected override void Handle(AuthorizationContext context, ViewRequirement requirement, IBillable resource)
|
||||
{
|
||||
if (context.User.IsInRole("FrontOffice"))
|
||||
context.Succeed(requirement);
|
||||
else if (context.User.Identity.IsAuthenticated)
|
||||
if (resource.ClientId == context.User.GetUserId())
|
||||
context.Succeed(requirement);
|
||||
else if (resource.PerformerId == context.User.GetUserId())
|
||||
context.Succeed(requirement);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
19
src/Yavsc/AuthorizationHandlers/BlogEditHandler.cs
Normal file
19
src/Yavsc/AuthorizationHandlers/BlogEditHandler.cs
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
using Microsoft.AspNet.Authorization;
|
||||
using System.Security.Claims;
|
||||
using Yavsc.Models.Blog;
|
||||
|
||||
namespace Yavsc.ViewModels.Auth.Handlers
|
||||
{
|
||||
public class BlogEditHandler : AuthorizationHandler<EditRequirement, BlogPost>
|
||||
{
|
||||
protected override void Handle(AuthorizationContext context, EditRequirement requirement, BlogPost resource)
|
||||
{
|
||||
if (context.User.IsInRole(Constants.BlogModeratorGroupName))
|
||||
context.Succeed(requirement);
|
||||
else if (context.User.Identity.IsAuthenticated)
|
||||
if (resource.AuthorId == context.User.GetUserId())
|
||||
context.Succeed(requirement);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
17
src/Yavsc/AuthorizationHandlers/HasBadgeHandler.cs
Normal file
17
src/Yavsc/AuthorizationHandlers/HasBadgeHandler.cs
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
using Microsoft.AspNet.Authorization;
|
||||
|
||||
namespace Yavsc.ViewModels.Auth.Handlers
|
||||
{
|
||||
public class HasBadgeHandler : AuthorizationHandler<PrivateChatEntryRequirement>
|
||||
{
|
||||
protected override void Handle(AuthorizationContext context, PrivateChatEntryRequirement requirement)
|
||||
{
|
||||
if (!context.User.HasClaim(c => c.Type == "BadgeNumber" &&
|
||||
c.Issuer == Startup.Authority))
|
||||
{
|
||||
return;
|
||||
}
|
||||
context.Succeed(requirement);
|
||||
}
|
||||
}
|
||||
}
|
||||
27
src/Yavsc/AuthorizationHandlers/HasTemporaryPassHandler.cs
Normal file
27
src/Yavsc/AuthorizationHandlers/HasTemporaryPassHandler.cs
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
using System;
|
||||
using Microsoft.AspNet.Authorization;
|
||||
|
||||
namespace Yavsc.ViewModels.Auth.Handlers
|
||||
{
|
||||
public class HasTemporaryPassHandler : AuthorizationHandler<PrivateChatEntryRequirement>
|
||||
{
|
||||
protected override void Handle(AuthorizationContext context, PrivateChatEntryRequirement requirement)
|
||||
{
|
||||
if (!context.User.HasClaim(c => c.Type == "TemporaryBadgeExpiry" &&
|
||||
c.Issuer == Startup.Authority))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var temporaryBadgeExpiry =
|
||||
Convert.ToDateTime(context.User.FindFirst(
|
||||
c => c.Type == "TemporaryBadgeExpiry" &&
|
||||
c.Issuer == Startup.Authority).Value);
|
||||
|
||||
if (temporaryBadgeExpiry > DateTime.Now)
|
||||
{
|
||||
context.Succeed(requirement);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
18
src/Yavsc/AuthorizationHandlers/ManageGitHookHandler.cs
Normal file
18
src/Yavsc/AuthorizationHandlers/ManageGitHookHandler.cs
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
using Microsoft.AspNet.Authorization;
|
||||
using Yavsc.Server.Models.IT.SourceCode;
|
||||
using Yavsc.ViewModels.Auth;
|
||||
|
||||
namespace Yavsc.AuthorizationHandlers
|
||||
{
|
||||
public class ManageGitHookHandler: AuthorizationHandler<EditRequirement, GitRepositoryReference>
|
||||
{
|
||||
protected override void Handle(AuthorizationContext context, EditRequirement requirement, GitRepositoryReference resource)
|
||||
{
|
||||
if (context.User.IsInRole("FrontOffice"))
|
||||
context.Succeed(requirement);
|
||||
else if (context.User.Identity.IsAuthenticated)
|
||||
context.Succeed(requirement);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
22
src/Yavsc/AuthorizationHandlers/PostUserFileHandler.cs
Normal file
22
src/Yavsc/AuthorizationHandlers/PostUserFileHandler.cs
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
using System.Security.Claims;
|
||||
using Microsoft.AspNet.Authorization;
|
||||
using Yavsc.ViewModel.Auth;
|
||||
|
||||
namespace Yavsc.ViewModels.Auth.Handlers
|
||||
{
|
||||
public class PostUserFileHandler : AuthorizationHandler<EditRequirement, FileSpotInfo>
|
||||
{
|
||||
protected override void Handle(AuthorizationContext context, EditRequirement requirement, FileSpotInfo resource)
|
||||
{
|
||||
if (context.User.IsInRole(Constants.BlogModeratorGroupName)
|
||||
|| context.User.IsInRole(Constants.AdminGroupName))
|
||||
context.Succeed(requirement);
|
||||
if (!context.User.Identity.IsAuthenticated)
|
||||
context.Fail();
|
||||
if (resource.AuthorId == context.User.GetUserId())
|
||||
context.Succeed(requirement);
|
||||
else context.Fail();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
18
src/Yavsc/AuthorizationHandlers/ViewFileHandler.cs
Normal file
18
src/Yavsc/AuthorizationHandlers/ViewFileHandler.cs
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
using Microsoft.AspNet.Authorization;
|
||||
|
||||
namespace Yavsc.ViewModels.Auth.Handlers
|
||||
{
|
||||
public class ViewFileHandler : AuthorizationHandler<ViewRequirement, ViewFileContext>
|
||||
{
|
||||
protected override void Handle(AuthorizationContext context, ViewRequirement requirement, ViewFileContext fileContext)
|
||||
{
|
||||
// TODO file access rules
|
||||
if (fileContext.Path.StartsWith("/pub/"))
|
||||
context.Succeed(requirement);
|
||||
else {
|
||||
// TODO use "/blog/{num}/" path to link to blog access list
|
||||
context.Succeed(requirement);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue