bug fixes
parent
86dc1b8a2b
commit
f3a63c9e46
@ -0,0 +1,46 @@
|
|||||||
|
using System.Security.Claims;
|
||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using Yavsc.ViewModels.Auth;
|
||||||
|
|
||||||
|
namespace Yavsc.Extensions;
|
||||||
|
|
||||||
|
public class PermissionHandler : IAuthorizationHandler
|
||||||
|
{
|
||||||
|
public Task HandleAsync(AuthorizationHandlerContext context)
|
||||||
|
{
|
||||||
|
var pendingRequirements = context.PendingRequirements.ToList();
|
||||||
|
|
||||||
|
foreach (var requirement in pendingRequirements)
|
||||||
|
{
|
||||||
|
if (requirement is ReadPermission)
|
||||||
|
{
|
||||||
|
if (IsOwner(context.User, context.Resource)
|
||||||
|
|| IsSponsor(context.User, context.Resource))
|
||||||
|
{
|
||||||
|
context.Succeed(requirement);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (requirement is EditPermission || requirement is DeletePermission)
|
||||||
|
{
|
||||||
|
if (IsOwner(context.User, context.Resource))
|
||||||
|
{
|
||||||
|
context.Succeed(requirement);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return Task.CompletedTask;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static bool IsOwner(ClaimsPrincipal user, object? resource)
|
||||||
|
{
|
||||||
|
// Code omitted for brevity
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static bool IsSponsor(ClaimsPrincipal user, object? resource)
|
||||||
|
{
|
||||||
|
// Code omitted for brevity
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,85 @@
|
|||||||
|
@model Yavsc.ViewModels.Blog.BlogPostInputViewModel
|
||||||
|
|
||||||
|
@{
|
||||||
|
ViewData["Title"] = "Blog post edition";
|
||||||
|
}
|
||||||
|
|
||||||
|
@section header {
|
||||||
|
|
||||||
|
<link href="~/css/main/dropzone.css" rel="stylesheet">
|
||||||
|
|
||||||
|
<script src="~/js/dropzone.js"></script>
|
||||||
|
|
||||||
|
@{ await Html.RenderPartialAsync("_FSScriptsPartial"); }
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
<h2>Blog post</h2>
|
||||||
|
<label><input type="checkbox" id="vcbtn" />Editer le code source Markdown</label>
|
||||||
|
|
||||||
|
<div asp-validation-summary="All" class="text-danger"></div>
|
||||||
|
|
||||||
|
<img class="blogphoto" alt="" src="@Model.Photo" title="Photo associée au post">
|
||||||
|
<h2 title="Titre du post" class="blogtitle" id="titleview" >@Model.Title</h2>
|
||||||
|
|
||||||
|
<div title="Contenu du post" id="contentview">@Model.Content</div>
|
||||||
|
|
||||||
|
<hr>
|
||||||
|
<form asp-controller="Blogspot" asp-action="Create">
|
||||||
|
<div class="form-horizontal">
|
||||||
|
|
||||||
|
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
|
||||||
|
|
||||||
|
<div class="form-group mdcoding">
|
||||||
|
<label asp-for="Title" class="col-md-2 control-label"></label>
|
||||||
|
<div class="col-md-10">
|
||||||
|
<input asp-for="Title" class="form-control" data-from="titleview"/>
|
||||||
|
<span asp-validation-for="Title" class="text-danger" >
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<label asp-for="Photo" class="col-md-2 control-label"></label>
|
||||||
|
<div class="col-md-10">
|
||||||
|
<input asp-for="Photo" class="form-control" />
|
||||||
|
<span asp-validation-for="Photo" class="text-danger" >
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="form-group mdcoding">
|
||||||
|
<label asp-for="Content" class="col-md-2 control-label" ></label>
|
||||||
|
<div class="col-md-10">
|
||||||
|
<textarea asp-for="Content" class="form-control" id="Content" data-from="contentview">
|
||||||
|
</textarea>
|
||||||
|
<span asp-validation-for="Content" class="text-danger" >
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<label asp-for="Visible" class="col-md-2 control-label"></label>
|
||||||
|
<div class="col-md-10">
|
||||||
|
<input asp-for="Visible" class="form-control"/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<label asp-for="ACL" class="col-md-2 control-label"></label>
|
||||||
|
<div class="col-md-10">
|
||||||
|
@await Component.InvokeAsync("CirclesControl", Model)
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<div class="col-md-offset-2 col-md-10">
|
||||||
|
<button class="btn btn-primary" >Save</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
@await Component.InvokeAsync("Directory","")
|
||||||
|
<div >
|
||||||
|
@{ await Html.RenderPartialAsync("_PostFilesPartial"); }
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<a asp-action="Index">Back to List</a>
|
||||||
|
</div>
|
||||||
Binary file not shown.
Loading…
Reference in New Issue