A Circle must pre-exist before beeing used by an authorization
This commit is contained in:
parent
88461786ee
commit
8f91cbed02
3 changed files with 21 additions and 6 deletions
10
src/Yavsc.Abstract/Blogspot/PostAccessControlRulePayload.cs
Normal file
10
src/Yavsc.Abstract/Blogspot/PostAccessControlRulePayload.cs
Normal file
|
|
@ -0,0 +1,10 @@
|
||||||
|
|
||||||
|
using Yavsc.Abstract.Identity.Security;
|
||||||
|
|
||||||
|
namespace Yavsc.Abstract.BlogSpot;
|
||||||
|
|
||||||
|
public class PostAccessControlRulePayload : ICircleAuthorization
|
||||||
|
{
|
||||||
|
public long CircleId { get; set; }
|
||||||
|
public long BlogPostId { get; set; }
|
||||||
|
}
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
using System.Security.Claims;
|
using System.Security.Claims;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Yavsc.Abstract.BlogSpot;
|
||||||
using Yavsc.Models;
|
using Yavsc.Models;
|
||||||
using Yavsc.Models.Access;
|
using Yavsc.Models.Access;
|
||||||
using Yavsc.Server.Helpers;
|
using Yavsc.Server.Helpers;
|
||||||
|
|
@ -103,7 +104,8 @@ namespace Yavsc.Blogs.Controllers
|
||||||
}
|
}
|
||||||
// POST: api/BlogAclApi
|
// POST: api/BlogAclApi
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
public async Task<IActionResult> PostCircleAuthorizationToBlogPost([FromBody] CircleAuthorizationToBlogPost circleAuthorizationToBlogPost)
|
public async Task<IActionResult> PostCircleAuthorizationToBlogPost(
|
||||||
|
[FromBody] PostAccessControlRulePayload circleAuthorizationToBlogPost)
|
||||||
{
|
{
|
||||||
if (!ModelState.IsValid)
|
if (!ModelState.IsValid)
|
||||||
{
|
{
|
||||||
|
|
@ -113,7 +115,12 @@ namespace Yavsc.Blogs.Controllers
|
||||||
{
|
{
|
||||||
return new ChallengeResult();
|
return new ChallengeResult();
|
||||||
}
|
}
|
||||||
_context.CircleAuthorizationToBlogPost.Add(circleAuthorizationToBlogPost);
|
CircleAuthorizationToBlogPost entity = new CircleAuthorizationToBlogPost
|
||||||
|
{
|
||||||
|
BlogPostId = circleAuthorizationToBlogPost.BlogPostId,
|
||||||
|
CircleId = circleAuthorizationToBlogPost.CircleId
|
||||||
|
};
|
||||||
|
_context.CircleAuthorizationToBlogPost.Add(entity);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
await _context.SaveChangesAsync(User.GetUserId());
|
await _context.SaveChangesAsync(User.GetUserId());
|
||||||
|
|
|
||||||
|
|
@ -5,12 +5,10 @@ namespace Yavsc.Models.Access
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using Blog;
|
using Blog;
|
||||||
using Yavsc.Abstract.Identity.Security;
|
using Yavsc.Abstract.Identity.Security;
|
||||||
|
using Yavsc.Abstract.BlogSpot;
|
||||||
|
|
||||||
public class CircleAuthorizationToBlogPost : ICircleAuthorization
|
public class CircleAuthorizationToBlogPost : PostAccessControlRulePayload
|
||||||
{
|
{
|
||||||
public long CircleId { get; set; }
|
|
||||||
public long BlogPostId { get; set; }
|
|
||||||
|
|
||||||
[JsonIgnore]
|
[JsonIgnore]
|
||||||
[ForeignKey("BlogPostId")]
|
[ForeignKey("BlogPostId")]
|
||||||
public virtual BlogPost Target { get; set; }
|
public virtual BlogPost Target { get; set; }
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue