added method to get all child users, split get user with access to installation to direct and inherited
This commit is contained in:
parent
5f8f7b1e66
commit
c751cb8e8f
|
@ -72,8 +72,8 @@ public class Controller : ControllerBase
|
||||||
return installation;
|
return installation;
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet(nameof(GetUsersWithAccessToInstallation))]
|
[HttpGet(nameof(GetUsersWithDirectAccessToInstallation))]
|
||||||
public ActionResult<IEnumerable<Object>> GetUsersWithAccessToInstallation(Int64 id, Token authToken)
|
public ActionResult<IEnumerable<Object>> GetUsersWithDirectAccessToInstallation(Int64 id, Token authToken)
|
||||||
{
|
{
|
||||||
var user = Db.GetSession(authToken)?.User;
|
var user = Db.GetSession(authToken)?.User;
|
||||||
if (user == null)
|
if (user == null)
|
||||||
|
@ -84,21 +84,32 @@ public class Controller : ControllerBase
|
||||||
if (installation is null || !user.HasAccessTo(installation))
|
if (installation is null || !user.HasAccessTo(installation))
|
||||||
return Unauthorized();
|
return Unauthorized();
|
||||||
|
|
||||||
var directAccess = installation
|
return installation
|
||||||
.UsersWithDirectAccess()
|
.UsersWithDirectAccess()
|
||||||
.Where(u => u.IsDescendantOf(user));
|
.Where(u => u.IsDescendantOf(user))
|
||||||
|
.ToList();
|
||||||
var inheritedAccess = installation
|
|
||||||
.Ancestors()
|
|
||||||
.SelectMany(f => f.UsersWithDirectAccess()
|
|
||||||
.Where(u => u.IsDescendantOf(user))
|
|
||||||
.Select(u => new { folderId = f.Id, user = u }));
|
|
||||||
|
|
||||||
return directAccess
|
|
||||||
.Concat<Object>(inheritedAccess)
|
|
||||||
.Apply(Ok); // TODO: typing
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[HttpGet(nameof(GetUsersWithInheritedAccessToInstallation))]
|
||||||
|
public ActionResult<IEnumerable<Object>> GetUsersWithInheritedAccessToInstallation(Int64 id, Token authToken)
|
||||||
|
{
|
||||||
|
var user = Db.GetSession(authToken)?.User;
|
||||||
|
if (user == null)
|
||||||
|
return Unauthorized();
|
||||||
|
|
||||||
|
var installation = Db.GetInstallationById(id);
|
||||||
|
|
||||||
|
if (installation is null || !user.HasAccessTo(installation))
|
||||||
|
return Unauthorized();
|
||||||
|
|
||||||
|
return installation
|
||||||
|
.Ancestors()
|
||||||
|
.SelectMany(f => f.UsersWithDirectAccess()
|
||||||
|
.Where(u => u.IsDescendantOf(user))
|
||||||
|
.Select(u => new { folderId = f.Id, user = u }))
|
||||||
|
.ToList();
|
||||||
|
}
|
||||||
|
|
||||||
[HttpGet(nameof(GetUsersWithAccessToFolder))]
|
[HttpGet(nameof(GetUsersWithAccessToFolder))]
|
||||||
public ActionResult<IEnumerable<Object>> GetUsersWithAccessToFolder(Int64 id, Token authToken)
|
public ActionResult<IEnumerable<Object>> GetUsersWithAccessToFolder(Int64 id, Token authToken)
|
||||||
{
|
{
|
||||||
|
@ -135,6 +146,15 @@ public class Controller : ControllerBase
|
||||||
return folder;
|
return folder;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[HttpGet(nameof(GetAllChildUsers))]
|
||||||
|
public ActionResult<IEnumerable<User>> GetAllChildUsers(Token authToken)
|
||||||
|
{
|
||||||
|
var user = Db.GetSession(authToken)?.User;
|
||||||
|
if (user == null)
|
||||||
|
return Unauthorized();
|
||||||
|
|
||||||
|
return user.ChildUsers().ToList();
|
||||||
|
}
|
||||||
|
|
||||||
[HttpGet(nameof(GetAllInstallations))]
|
[HttpGet(nameof(GetAllInstallations))]
|
||||||
public ActionResult<IEnumerable<Installation>> GetAllInstallations(Token authToken)
|
public ActionResult<IEnumerable<Installation>> GetAllInstallations(Token authToken)
|
||||||
|
|
Loading…
Reference in New Issue