make Ancestors exclude self

This commit is contained in:
ig 2023-03-16 09:18:39 +01:00
parent 96018a5867
commit 405308d7d6
3 changed files with 15 additions and 11 deletions

View File

@ -33,7 +33,9 @@ public static class FolderMethods
public static IEnumerable<Folder> Ancestors(this Folder folder)
{
return folder.Unfold(Parent);
return folder
.Unfold(Parent)
.Skip(1); // skip self
}
public static Folder? Parent(this Folder folder)

View File

@ -9,9 +9,12 @@ public static class InstallationMethods
{
var parentFolder = Parent(installation);
return parentFolder is null
? Enumerable.Empty<Folder>()
: parentFolder.Ancestors();
if (parentFolder is null)
return Enumerable.Empty<Folder>();
return parentFolder
.Ancestors()
.Prepend(parentFolder);
}
public static Folder? Parent(this Installation installation)

View File

@ -1,8 +1,5 @@
using System.Net.Http.Headers;
using System.Net.Mail;
using System.Security.Cryptography;
using System.Text.Json.Nodes;
using System.Text.RegularExpressions;
using InnovEnergy.App.Backend.Database;
using InnovEnergy.Lib.Utils;
using Convert = System.Convert;
@ -88,7 +85,9 @@ public static class UserMethods
private static IEnumerable<User> Ancestors(this User user)
{
return user.Unfold(Parent);
return user
.Unfold(Parent)
.Skip(1); // skip self
}
public static Boolean VerifyPassword(this User user, String password)
@ -135,7 +134,8 @@ public static class UserMethods
if (folder is null)
return false;
return folder
return user.HasDirectAccessTo(folder)
|| folder
.Ancestors()
.Any(user.HasDirectAccessTo);
}
@ -144,7 +144,7 @@ public static class UserMethods
{
return Db
.User2Installation
.Any(r => r.InstallationId == installation.Id && r.UserId == user.Id);
.Any(r => r.UserId == user.Id && r.InstallationId == installation.Id);
}
public static Boolean HasAccessTo(this User user, Installation? installation)
@ -163,7 +163,6 @@ public static class UserMethods
return other
.Ancestors()
.Skip(1) // Important! skip self, user cannot delete or edit himself
.Contains(user);
}