permission handling

This commit is contained in:
Paul Schneider
2025-02-23 20:23:23 +00:00
parent 04bcecad9e
commit 7ccb9cd1da
27 changed files with 243 additions and 288 deletions

View File

@ -30,7 +30,7 @@ namespace Yavsc.Helpers
{
var userPosts = dbContext.BlogSpot.Include(
b => b.Author
).Where(x => ((x.AuthorId == posterId) && (x.Visible))).ToArray();
).Where(x => ((x.AuthorId == posterId))).ToArray();
return userPosts;
}
else
@ -42,8 +42,7 @@ namespace Yavsc.Helpers
return dbContext.BlogSpot.Include(
b => b.Author
).Include(p => p.ACL).Where(x => x.Author.Id == posterId &&
(x.Visible &&
(x.ACL.Count == 0 || x.ACL.Any(a => readerCirclesMemberships.Contains(a.CircleId)))));
(x.ACL.Count == 0 || x.ACL.Any(a => readerCirclesMemberships.Contains(a.CircleId))));
}

View File

@ -18,14 +18,14 @@ namespace Yavsc.Models.Blog
{
[Key(), DatabaseGenerated(DatabaseGeneratedOption.Identity)]
[Display(Name="Identifiant du post")]
public long Id { get; set; }
public long Id { get; set; }
[Display(Name="Identifiant de l'auteur")]
[ForeignKey("Author")]
public string AuthorId { get; set; }
public string AuthorId { get; set; }
[Display(Name="Auteur")]
public virtual ApplicationUser Author { set; get; }
public virtual ApplicationUser Author { set; get; }
[Display(Name="Date de création")]
@ -35,7 +35,7 @@ namespace Yavsc.Models.Blog
}
[Display(Name="Créateur")]
public string UserCreated
public string UserCreated
{
get; set;
}
@ -47,7 +47,7 @@ namespace Yavsc.Models.Blog
}
[Display(Name="Utilisateur ayant modifé le dernier")]
public string UserModified
public string UserModified
{
get; set;
}
@ -68,7 +68,7 @@ namespace Yavsc.Models.Blog
if (existent==null) Tags.Add(new BlogTag { PostId = Id, Tag = tag } );
}
public void Detag(Tag tag)
public void DeTag(Tag tag)
{
var existent = Tags.SingleOrDefault(t => (( t.TagId == tag.Id) && t.PostId == Id));
if (existent!=null) Tags.Remove(existent);
@ -80,10 +80,10 @@ namespace Yavsc.Models.Blog
}
[InverseProperty("Post")]
public virtual List<BlogTag> Tags { get; set; }
public virtual List<BlogTag> Tags { get; set; }
[InverseProperty("Post")]
public virtual List<Comment> Comments { get; set; }
public virtual List<Comment> Comments { get; set; }
[NotMapped]
public string OwnerId => AuthorId;

View File

@ -0,0 +1,12 @@
using Microsoft.AspNetCore.Authorization;
namespace Yavsc.ViewModels.Auth
{
public class DeletePermission: IAuthorizationRequirement
{
public DeletePermission()
{
}
}
}

View File

@ -0,0 +1,12 @@
using Microsoft.AspNetCore.Authorization;
namespace Yavsc.ViewModels.Auth
{
public class EditPermission : IAuthorizationRequirement
{
public EditPermission()
{
}
}
}

View File

@ -1,26 +0,0 @@
using Microsoft.AspNetCore.Authorization;
namespace Yavsc.ViewModels.Auth
{
public class EditPermission : IAuthorizationRequirement
{
public EditPermission()
{
}
}
public class ReadPermission: IAuthorizationRequirement
{
public ReadPermission()
{
}
}
public class DeletePermission: IAuthorizationRequirement
{
public DeletePermission()
{
}
}
}

View File

@ -2,10 +2,11 @@ using Microsoft.AspNetCore.Authorization;
namespace Yavsc.ViewModels.Auth
{
public class ViewRequirement : IAuthorizationRequirement
public class ReadPermission: IAuthorizationRequirement
{
public ViewRequirement()
public ReadPermission()
{
}
}
}

View File

@ -0,0 +1,11 @@
using System.ComponentModel.DataAnnotations;
namespace Yavsc.ViewModels.Blog;
public class BlogPostEditViewModel : BlogPostInputViewModel
{
[Required]
public required long Id { get; set; }
}

View File

@ -8,19 +8,18 @@ namespace Yavsc.ViewModels.Blog
public class BlogPostInputViewModel
{
[StringLength(1024)]
public string? Photo { get; set; }
public string? Photo { get; set; }
[StringLength(1024)]
public required string Title { get; set; }
public string Title { get; set; }
[StringLength(56224)]
public required string Content { get; set; }
public bool Visible { get; set; }
public string Content { get; set; }
[InverseProperty("Target")]
[Display(Name="Liste de contrôle d'accès")]
public virtual List<CircleAuthorizationToBlogPost>? ACL { get; set; }
}
}

View File

@ -1,17 +0,0 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Threading.Tasks;
namespace Yavsc.ViewModels.BlogSpot
{
public class NewPost
{
[Required]
public string Title{ get; set; }
[Required]
public string Content { get; set; }
}
}