split users with direct and inherited access to folders call

This commit is contained in:
Kim 2023-03-23 08:27:29 +01:00
parent c751cb8e8f
commit 656b671962
1 changed files with 25 additions and 8 deletions

View File

@ -110,8 +110,8 @@ public class Controller : ControllerBase
.ToList(); .ToList();
} }
[HttpGet(nameof(GetUsersWithAccessToFolder))] [HttpGet(nameof(GetUsersWithDirectAccessToFolder))]
public ActionResult<IEnumerable<Object>> GetUsersWithAccessToFolder(Int64 id, Token authToken) public ActionResult<IEnumerable<Object>> GetUsersWithDirectAccessToFolder(Int64 id, Token authToken)
{ {
var user = Db.GetSession(authToken)?.User; var user = Db.GetSession(authToken)?.User;
if (user == null) if (user == null)
@ -123,12 +123,29 @@ public class Controller : ControllerBase
return Unauthorized(); return Unauthorized();
return folder return folder
.Ancestors() .UsersWithDirectAccess()
.Prepend(folder) .Where(u => u.IsDescendantOf(user))
.SelectMany(f => f.UsersWithDirectAccess() .ToList();
.Where(u => u.IsDescendantOf(user)) }
.Select(u => new { folderId = f.Id, user = u }))
.ToList(); [HttpGet(nameof(GetUsersWithInheritedAccessToFolder))]
public ActionResult<IEnumerable<Object>> GetUsersWithInheritedAccessToFolder(Int64 id, Token authToken)
{
var user = Db.GetSession(authToken)?.User;
if (user == null)
return Unauthorized();
var folder = Db.GetFolderById(id);
if (folder is null || !user.HasAccessTo(folder))
return Unauthorized();
return folder
.Ancestors()
.SelectMany(f => f.UsersWithDirectAccess()
.Where(u => u.IsDescendantOf(user))
.Select(u => new { folderId = f.Id, user = u }))
.ToList();
} }
[HttpGet(nameof(GetFolderById))] [HttpGet(nameof(GetFolderById))]