avoid adding folder to itself, children and parent
This commit is contained in:
parent
80639e9169
commit
abedc6c203
|
|
@ -44,6 +44,9 @@ public static class SessionMethods
|
||||||
|
|
||||||
return user is not null
|
return user is not null
|
||||||
&& folder is not null
|
&& folder is not null
|
||||||
|
&& parent is not null
|
||||||
|
&& folderId != parentId // can't move into itself
|
||||||
|
&& !IsFolderAncestorOf(folderId, parentId) // can't move into a descendant
|
||||||
&& user.UserType==2
|
&& user.UserType==2
|
||||||
&& user.HasAccessTo(folder)
|
&& user.HasAccessTo(folder)
|
||||||
&& user.HasAccessTo(parent)
|
&& user.HasAccessTo(parent)
|
||||||
|
|
@ -52,6 +55,19 @@ public static class SessionMethods
|
||||||
.Apply(Db.Update);
|
.Apply(Db.Update);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Walks up the folder tree from candidateDescendantId to check if ancestorId is an ancestor.
|
||||||
|
// Prevents circular references when moving a folder into one of its own descendants.
|
||||||
|
private static Boolean IsFolderAncestorOf(Int64 ancestorId, Int64 candidateDescendantId)
|
||||||
|
{
|
||||||
|
var current = Db.GetFolderById(candidateDescendantId);
|
||||||
|
while (current is not null && current.ParentId != 0)
|
||||||
|
{
|
||||||
|
if (current.ParentId == ancestorId) return true;
|
||||||
|
current = Db.GetFolderById(current.ParentId);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
public static Boolean MoveInstallation(this Session? session, Int64 installationId, Int64 parentId)
|
public static Boolean MoveInstallation(this Session? session, Int64 installationId, Int64 parentId)
|
||||||
{
|
{
|
||||||
var user = session?.User;
|
var user = session?.User;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue