Blog Post Id
This commit is contained in:
parent
c450bd7ff8
commit
67da921bce
22 changed files with 4869 additions and 96 deletions
|
|
@ -14,9 +14,9 @@ namespace Yavsc.Server.Helpers
|
|||
if (readerId == null)
|
||||
{
|
||||
var userPosts = dbContext.blogSpotPublications.Include(
|
||||
b => b.BlogPost
|
||||
).Where(x => x.BlogPost.AuthorId == posterId)
|
||||
.Select(x => x.BlogPost).ToArray();
|
||||
b => b.Post
|
||||
).Where(x => x.Post.AuthorId == posterId)
|
||||
.Select(x => x.Post).ToArray();
|
||||
return userPosts;
|
||||
}
|
||||
else
|
||||
|
|
|
|||
|
|
@ -96,6 +96,9 @@ namespace Yavsc.Models.Blog
|
|||
[InverseProperty("Post")]
|
||||
public virtual List<Comment> Comments { get; set; }
|
||||
|
||||
[InverseProperty("Post")]
|
||||
public virtual BlogSpotPublication Publication { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Whether this post is published. Not a column: the
|
||||
/// existence of a row in <c>BlogSpotPublication</c>
|
||||
|
|
@ -147,5 +150,7 @@ namespace Yavsc.Models.Blog
|
|||
}).ToList() ?? new List<CircleAuthorization>();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,9 +7,9 @@ namespace Yavsc.Models
|
|||
public class BlogSpotPublication
|
||||
{
|
||||
[Key]
|
||||
public long BlogpostId { get; set; }
|
||||
|
||||
[ForeignKey("BlogpostId")]
|
||||
public virtual BlogPost BlogPost{ get; set; }
|
||||
public long PostId { get; set; }
|
||||
|
||||
[ForeignKey("PostId")]
|
||||
public virtual BlogPost Post{ get; set; }
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -61,7 +61,7 @@ public class BlogSpotService
|
|||
blogFilesSubdir);
|
||||
var di = new DirectoryInfo(destDir);
|
||||
|
||||
if (!di.Exists)
|
||||
if (!di.Exists)
|
||||
{
|
||||
logger.LogInformation("Creating directory for blog attachments: {destDir}", destDir);
|
||||
di.Create();
|
||||
|
|
@ -126,7 +126,7 @@ public class BlogSpotService
|
|||
if (!auth.Succeeded)
|
||||
throw new AuthorizationFailureException(auth);
|
||||
|
||||
var pub = await _context.blogSpotPublications.AnyAsync(x => x.BlogpostId == blog.Id);
|
||||
var pub = await _context.blogSpotPublications.AnyAsync(x => x.PostId == blog.Id);
|
||||
ScrubAclForViewer(blog, user);
|
||||
|
||||
return new BlogPostEditViewModel(blog, pub);
|
||||
|
|
@ -146,7 +146,7 @@ public class BlogSpotService
|
|||
|
||||
// Hydrate le flag [NotMapped] depuis la table de publication.
|
||||
blog.IsPublished = await _context.blogSpotPublications
|
||||
.AnyAsync(pub => pub.BlogpostId == blogPostId);
|
||||
.AnyAsync(pub => pub.PostId == blogPostId);
|
||||
|
||||
var auth = await _authorizationService.AuthorizeAsync(user, blog, new ReadPermission());
|
||||
if (!auth.Succeeded)
|
||||
|
|
@ -176,7 +176,7 @@ public class BlogSpotService
|
|||
_context.Update(blog);
|
||||
|
||||
var publication = await _context.blogSpotPublications
|
||||
.SingleOrDefaultAsync(p => p.BlogpostId == blogEdit.Id);
|
||||
.SingleOrDefaultAsync(p => p.PostId == blogEdit.Id);
|
||||
|
||||
if (publication != null)
|
||||
{
|
||||
|
|
@ -185,7 +185,7 @@ public class BlogSpotService
|
|||
}
|
||||
else if (blogEdit.Publish)
|
||||
{
|
||||
_context.blogSpotPublications.Add(new BlogSpotPublication { BlogpostId = blogEdit.Id });
|
||||
_context.blogSpotPublications.Add(new BlogSpotPublication { PostId = blogEdit.Id });
|
||||
}
|
||||
|
||||
_context.SaveChanges(user.GetUserId());
|
||||
|
|
@ -231,21 +231,19 @@ public class BlogSpotService
|
|||
.Include(p => p.ACL)
|
||||
.Include(p => p.Tags)
|
||||
.Include(p => p.Comments)
|
||||
.Where(p => p.ACL == null
|
||||
|| p.ACL.Count == 0
|
||||
|| p.AuthorId == viewerId
|
||||
.Include(p => p.Publication)
|
||||
.Where(p => p.Publication != null
|
||||
|| (userCircles != null && p.ACL.Any(a => userCircles.Contains(a.CircleId))));
|
||||
}
|
||||
else
|
||||
{
|
||||
posts = _context.blogSpotPublications
|
||||
.Include(p => p.BlogPost)
|
||||
.Include(b => b.BlogPost.Author)
|
||||
.Include(p => p.BlogPost.ACL)
|
||||
.Include(p => p.BlogPost.Tags)
|
||||
.Include(p => p.BlogPost.Comments)
|
||||
.Where(p => p.BlogPost.ACL == null || p.BlogPost.ACL.Count == 0)
|
||||
.Select(p => p.BlogPost)
|
||||
.Include(p => p.Post)
|
||||
.Include(b => b.Post.Author)
|
||||
.Include(p => p.Post.ACL)
|
||||
.Include(p => p.Post.Tags)
|
||||
.Include(p => p.Post.Comments)
|
||||
.Select(p => p.Post)
|
||||
.ToArray();
|
||||
}
|
||||
|
||||
|
|
@ -255,8 +253,8 @@ public class BlogSpotService
|
|||
if (postIds.Count > 0)
|
||||
{
|
||||
var publishedIds = await _context.blogSpotPublications
|
||||
.Where(pub => postIds.Contains(pub.BlogpostId))
|
||||
.Select(pub => pub.BlogpostId)
|
||||
.Where(pub => postIds.Contains(pub.PostId))
|
||||
.Select(pub => pub.PostId)
|
||||
.ToListAsync();
|
||||
|
||||
var publishedSet = publishedIds.ToHashSet();
|
||||
|
|
@ -323,11 +321,11 @@ public class BlogSpotService
|
|||
if (!auth.Succeeded)
|
||||
throw new AuthorizationFailureException(auth);
|
||||
|
||||
var existing = await _context.blogSpotPublications.SingleOrDefaultAsync(p => p.BlogpostId == postId);
|
||||
var existing = await _context.blogSpotPublications.SingleOrDefaultAsync(p => p.PostId == postId);
|
||||
if (publish)
|
||||
{
|
||||
if (existing == null)
|
||||
_context.blogSpotPublications.Add(new BlogSpotPublication { BlogpostId = postId });
|
||||
_context.blogSpotPublications.Add(new BlogSpotPublication { PostId = postId });
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
|||
|
|
@ -59,7 +59,7 @@ public class PermissionHandler : IAuthorizationHandler
|
|||
{
|
||||
return
|
||||
applicationDbContext.blogSpotPublications
|
||||
.Any(p=>p.BlogpostId == blogPost.Id);
|
||||
.Any(p=>p.PostId == blogPost.Id);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue