Fixe l'accès en lecture anonyme des blogs
This commit is contained in:
parent
9948f47b5e
commit
46701fea9d
6 changed files with 34 additions and 31 deletions
|
|
@ -2,23 +2,23 @@ using System.IO;
|
||||||
using Microsoft.AspNet.Authorization;
|
using Microsoft.AspNet.Authorization;
|
||||||
using Microsoft.AspNet.Mvc;
|
using Microsoft.AspNet.Mvc;
|
||||||
using System.Web.Routing;
|
using System.Web.Routing;
|
||||||
|
using System.Linq;
|
||||||
|
using Microsoft.Data.Entity;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using Microsoft.Extensions.Localization;
|
||||||
|
using Microsoft.Extensions.OptionsModel;
|
||||||
|
using System;
|
||||||
|
using System.Security.Claims;
|
||||||
|
|
||||||
namespace Yavsc.ApiControllers
|
namespace Yavsc.ApiControllers
|
||||||
{
|
{
|
||||||
using Models;
|
using Models;
|
||||||
using Helpers;
|
using Helpers;
|
||||||
using System.Linq;
|
using Services;
|
||||||
using Microsoft.Data.Entity;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Microsoft.Extensions.Logging;
|
|
||||||
using System;
|
|
||||||
using System.Security.Claims;
|
|
||||||
using Microsoft.Extensions.Localization;
|
|
||||||
using Yavsc.Services;
|
|
||||||
using Yavsc.Models.Messaging;
|
|
||||||
using Yavsc.ViewModels;
|
|
||||||
using Microsoft.Extensions.OptionsModel;
|
|
||||||
|
|
||||||
|
using Models.Messaging;
|
||||||
|
using ViewModels.Auth;
|
||||||
[Route("api/pdfestimate"), Authorize]
|
[Route("api/pdfestimate"), Authorize]
|
||||||
public class PdfEstimateController : Controller
|
public class PdfEstimateController : Controller
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,6 @@ using Microsoft.Extensions.OptionsModel;
|
||||||
using Yavsc.Models;
|
using Yavsc.Models;
|
||||||
using Yavsc.ViewModels.Auth;
|
using Yavsc.ViewModels.Auth;
|
||||||
using Microsoft.AspNet.Mvc.Rendering;
|
using Microsoft.AspNet.Mvc.Rendering;
|
||||||
using Yavsc.ViewModels;
|
|
||||||
|
|
||||||
// For more information on enabling Web API for empty projects, visit http://go.microsoft.com/fwlink/?LinkID=397860
|
// For more information on enabling Web API for empty projects, visit http://go.microsoft.com/fwlink/?LinkID=397860
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@ namespace Yavsc.Controllers
|
||||||
using Models;
|
using Models;
|
||||||
using Models.Billing;
|
using Models.Billing;
|
||||||
using Models.Workflow;
|
using Models.Workflow;
|
||||||
using ViewModels;
|
using ViewModels.Auth;
|
||||||
[Authorize]
|
[Authorize]
|
||||||
public class EstimateController : Controller
|
public class EstimateController : Controller
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -9,25 +9,26 @@ namespace Yavsc.ViewModels.Auth.Handlers
|
||||||
{
|
{
|
||||||
protected override void Handle(AuthorizationContext context, ViewRequirement requirement, Blog resource)
|
protected override void Handle(AuthorizationContext context, ViewRequirement requirement, Blog resource)
|
||||||
{
|
{
|
||||||
if (context.User.IsInRole(Constants.BlogModeratorGroupName)
|
bool ok=false;
|
||||||
|| context.User.IsInRole(Constants.AdminGroupName))
|
if (resource.Visible) {
|
||||||
context.Succeed(requirement);
|
|
||||||
else if (context.User.Identity.IsAuthenticated)
|
|
||||||
if (resource.AuthorId == context.User.GetUserId())
|
|
||||||
context.Succeed(requirement);
|
|
||||||
else if (resource.Visible) {
|
|
||||||
if (resource.ACL==null)
|
if (resource.ACL==null)
|
||||||
context.Succeed(requirement);
|
ok=true;
|
||||||
else if (resource.ACL.Count>0)
|
else if (resource.ACL.Count==0) ok=true;
|
||||||
{
|
else {
|
||||||
var uid = context.User.GetUserId();
|
if (context.User.IsSignedIn()) {
|
||||||
if (resource.ACL.Any(a=>a.Allowed!=null && a.Allowed.Members.Any(m=>m.MemberId == uid )))
|
var uid = context.User.GetUserId();
|
||||||
context.Succeed(requirement);
|
if (resource.ACL.Any(a=>a.Allowed!=null && a.Allowed.Members.Any(m=>m.MemberId == uid )))
|
||||||
else context.Fail();
|
ok=true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else context.Succeed(requirement);
|
}
|
||||||
}
|
if (ok) context.Succeed(requirement);
|
||||||
else context.Fail();
|
else {
|
||||||
|
if (context.User.IsInRole(Constants.AdminGroupName) ||
|
||||||
|
context.User.IsInRole(Constants.BlogModeratorGroupName))
|
||||||
|
context.Succeed(requirement);
|
||||||
|
else context.Fail();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
using Microsoft.AspNet.Authorization;
|
using Microsoft.AspNet.Authorization;
|
||||||
|
|
||||||
namespace Yavsc.ViewModels
|
namespace Yavsc.ViewModels.Auth
|
||||||
{
|
{
|
||||||
public class ViewRequirement : IAuthorizationRequirement
|
public class ViewRequirement : IAuthorizationRequirement
|
||||||
{
|
{
|
||||||
|
|
@ -50,8 +50,11 @@
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<ul class="actiongroup">
|
<ul class="actiongroup">
|
||||||
<li><a asp-action="Details" asp-route-id="@item.Id">Details</a>
|
@if (await AuthorizationService.AuthorizeAsync(User, item, new ViewRequirement())) {
|
||||||
|
<li>
|
||||||
|
<a asp-action="Details" asp-route-id="@item.Id">Details</a>
|
||||||
</li>
|
</li>
|
||||||
|
}
|
||||||
@if (await AuthorizationService.AuthorizeAsync(User, item, new EditRequirement())) {
|
@if (await AuthorizationService.AuthorizeAsync(User, item, new EditRequirement())) {
|
||||||
<li><a asp-action="Edit" asp-route-id="@item.Id">@SR["Edit"]</a>
|
<li><a asp-action="Edit" asp-route-id="@item.Id">@SR["Edit"]</a>
|
||||||
</li>
|
</li>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue