make Ancestors exclude self
This commit is contained in:
parent
96018a5867
commit
405308d7d6
|
@ -33,7 +33,9 @@ public static class FolderMethods
|
||||||
|
|
||||||
public static IEnumerable<Folder> Ancestors(this Folder folder)
|
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)
|
public static Folder? Parent(this Folder folder)
|
||||||
|
|
|
@ -9,9 +9,12 @@ public static class InstallationMethods
|
||||||
{
|
{
|
||||||
var parentFolder = Parent(installation);
|
var parentFolder = Parent(installation);
|
||||||
|
|
||||||
return parentFolder is null
|
if (parentFolder is null)
|
||||||
? Enumerable.Empty<Folder>()
|
return Enumerable.Empty<Folder>();
|
||||||
: parentFolder.Ancestors();
|
|
||||||
|
return parentFolder
|
||||||
|
.Ancestors()
|
||||||
|
.Prepend(parentFolder);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Folder? Parent(this Installation installation)
|
public static Folder? Parent(this Installation installation)
|
||||||
|
|
|
@ -1,8 +1,5 @@
|
||||||
using System.Net.Http.Headers;
|
|
||||||
using System.Net.Mail;
|
using System.Net.Mail;
|
||||||
using System.Security.Cryptography;
|
using System.Security.Cryptography;
|
||||||
using System.Text.Json.Nodes;
|
|
||||||
using System.Text.RegularExpressions;
|
|
||||||
using InnovEnergy.App.Backend.Database;
|
using InnovEnergy.App.Backend.Database;
|
||||||
using InnovEnergy.Lib.Utils;
|
using InnovEnergy.Lib.Utils;
|
||||||
using Convert = System.Convert;
|
using Convert = System.Convert;
|
||||||
|
@ -88,7 +85,9 @@ public static class UserMethods
|
||||||
|
|
||||||
private static IEnumerable<User> Ancestors(this User user)
|
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)
|
public static Boolean VerifyPassword(this User user, String password)
|
||||||
|
@ -135,7 +134,8 @@ public static class UserMethods
|
||||||
if (folder is null)
|
if (folder is null)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return folder
|
return user.HasDirectAccessTo(folder)
|
||||||
|
|| folder
|
||||||
.Ancestors()
|
.Ancestors()
|
||||||
.Any(user.HasDirectAccessTo);
|
.Any(user.HasDirectAccessTo);
|
||||||
}
|
}
|
||||||
|
@ -144,7 +144,7 @@ public static class UserMethods
|
||||||
{
|
{
|
||||||
return Db
|
return Db
|
||||||
.User2Installation
|
.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)
|
public static Boolean HasAccessTo(this User user, Installation? installation)
|
||||||
|
@ -163,7 +163,6 @@ public static class UserMethods
|
||||||
|
|
||||||
return other
|
return other
|
||||||
.Ancestors()
|
.Ancestors()
|
||||||
.Skip(1) // Important! skip self, user cannot delete or edit himself
|
|
||||||
.Contains(user);
|
.Contains(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue