From a665d3ef45359199ba649cefc8699709e1965a39 Mon Sep 17 00:00:00 2001 From: Paul Schneider Date: Mon, 6 Feb 2017 17:30:16 +0100 Subject: [PATCH] A listing of allowed posts only --- Yavsc/Controllers/BlogspotController.cs | 28 +++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/Yavsc/Controllers/BlogspotController.cs b/Yavsc/Controllers/BlogspotController.cs index cb9df4ef..622afde1 100644 --- a/Yavsc/Controllers/BlogspotController.cs +++ b/Yavsc/Controllers/BlogspotController.cs @@ -41,14 +41,30 @@ namespace Yavsc.Controllers [AllowAnonymous] public IActionResult Index(string id, int skip=0, int maxLen=25) { - string uid = null; - if (User.IsSignedIn()) - uid = User.GetUserId(); + if (!string.IsNullOrEmpty(id)) return UserPosts(id); - return View(_context.Blogspot.Include( - b => b.Author - ).Where(p => p.Visible || p.AuthorId == uid ).OrderByDescending(p => p.DateCreated) + string uid = User.GetUserId(); + long[] usercircles = _context.Circle.Include(c=>c.Members).Where(c=>c.Members.Any(m=>m.MemberId == uid)) + .Select(c=>c.Id).ToArray(); + IQueryable posts ; + if (usercircles != null) { + posts = _context.Blogspot.Include( + b => b.Author + ).Include(p=>p.ACL).Where(p=>p.Visible && (p.ACL.Count == 0 || p.ACL.Any(a=> usercircles.Contains(a.CircleId)))); + /* posts = _context.Blogspot.Include( + b => b.Author + ).Include(p=>p.ACL).Where(p=>p.Visible || p.ACL.Any(a => usercircles.Contains(a.Allowed) + )); */ + } + else { + posts = _context.Blogspot.Include( + b => b.Author + ).Include(p=>p.ACL).Where(p=>p.Visible && p.ACL.Count == 0); + } + + return View(posts + .OrderByDescending(p => p.DateCreated) .Skip(skip).Take(maxLen)); }