Skip to content

Commit

Permalink
Added a number of checks for adding invalid links between different r…
Browse files Browse the repository at this point in the history
…ecords (fix #612)
  • Loading branch information
Serg-Norseman committed Jan 28, 2025
1 parent 59632fc commit 7fbb3e3
Show file tree
Hide file tree
Showing 31 changed files with 90 additions and 5 deletions.
1 change: 1 addition & 0 deletions locales/Afrikaans.lng
Original file line number Diff line number Diff line change
Expand Up @@ -1026,3 +1026,4 @@
1013=contains mask
1014=not contains mask
1015=Move files
1016=Invalid link: identical records!
1 change: 1 addition & 0 deletions locales/Belarusian.lng
Original file line number Diff line number Diff line change
Expand Up @@ -1026,3 +1026,4 @@
1013=contains mask
1014=not contains mask
1015=Move files
1016=Invalid link: identical records!
1 change: 1 addition & 0 deletions locales/Chinese Simplified.lng
Original file line number Diff line number Diff line change
Expand Up @@ -1026,3 +1026,4 @@
1013=包含掩码
1014=不包含掩码
1015=Move files
1016=Invalid link: identical records!
1 change: 1 addition & 0 deletions locales/Czech.lng
Original file line number Diff line number Diff line change
Expand Up @@ -1026,3 +1026,4 @@
1013=contains mask
1014=not contains mask
1015=Move files
1016=Invalid link: identical records!
1 change: 1 addition & 0 deletions locales/Dutch.lng
Original file line number Diff line number Diff line change
Expand Up @@ -1026,3 +1026,4 @@
1013=contains mask
1014=not contains mask
1015=Move files
1016=Invalid link: identical records!
1 change: 1 addition & 0 deletions locales/English.lng
Original file line number Diff line number Diff line change
Expand Up @@ -1026,3 +1026,4 @@
1013=contains mask
1014=not contains mask
1015=Move files
1016=Invalid link: identical records!
1 change: 1 addition & 0 deletions locales/French.lng
Original file line number Diff line number Diff line change
Expand Up @@ -1026,3 +1026,4 @@
1013=contains mask
1014=not contains mask
1015=Move files
1016=Invalid link: identical records!
1 change: 1 addition & 0 deletions locales/German.lng
Original file line number Diff line number Diff line change
Expand Up @@ -1026,3 +1026,4 @@
1013=enthält Maske
1014=enthält keine Maske
1015=Move files
1016=Invalid link: identical records!
1 change: 1 addition & 0 deletions locales/Hungarian.lng
Original file line number Diff line number Diff line change
Expand Up @@ -1026,3 +1026,4 @@
1013=maszkot tartalmaz
1014=nem tartalmaz maszkot
1015=Move files
1016=Invalid link: identical records!
1 change: 1 addition & 0 deletions locales/Icelandic.lng
Original file line number Diff line number Diff line change
Expand Up @@ -1026,3 +1026,4 @@
1013=contains mask
1014=not contains mask
1015=Move files
1016=Invalid link: identical records!
1 change: 1 addition & 0 deletions locales/Italian.lng
Original file line number Diff line number Diff line change
Expand Up @@ -1026,3 +1026,4 @@
1013=contains mask
1014=not contains mask
1015=Move files
1016=Invalid link: identical records!
1 change: 1 addition & 0 deletions locales/Japanese.lng
Original file line number Diff line number Diff line change
Expand Up @@ -1026,3 +1026,4 @@
1013=マスクを含む
1014=マスクを含まない
1015=Move files
1016=Invalid link: identical records!
1 change: 1 addition & 0 deletions locales/Kazakh (Cyrillic).lng
Original file line number Diff line number Diff line change
Expand Up @@ -1026,3 +1026,4 @@
1013=contains mask
1014=not contains mask
1015=Move files
1016=Invalid link: identical records!
1 change: 1 addition & 0 deletions locales/Polish.lng
Original file line number Diff line number Diff line change
Expand Up @@ -1026,3 +1026,4 @@
1013=contains mask
1014=not contains mask
1015=Move files
1016=Invalid link: identical records!
1 change: 1 addition & 0 deletions locales/Portuguese.lng
Original file line number Diff line number Diff line change
Expand Up @@ -1026,3 +1026,4 @@
1013=contains mask
1014=not contains mask
1015=Move files
1016=Invalid link: identical records!
1 change: 1 addition & 0 deletions locales/Russian.lng
Original file line number Diff line number Diff line change
Expand Up @@ -1026,3 +1026,4 @@
1013=содержит маску
1014=не содержит маску
1015=Переместить файлы
1016=Недопустимая ссылка: идентичные записи!
1 change: 1 addition & 0 deletions locales/Serbian (Latin).lng
Original file line number Diff line number Diff line change
Expand Up @@ -1026,3 +1026,4 @@
1013=contains mask
1014=not contains mask
1015=Move files
1016=Invalid link: identical records!
1 change: 1 addition & 0 deletions locales/Spanish.lng
Original file line number Diff line number Diff line change
Expand Up @@ -1026,3 +1026,4 @@
1013=contiene máscara
1014=no contiene máscara
1015=Move files
1016=Invalid link: identical records!
1 change: 1 addition & 0 deletions locales/Turkish.lng
Original file line number Diff line number Diff line change
Expand Up @@ -1026,3 +1026,4 @@
1013=contains mask
1014=not contains mask
1015=Move files
1016=Invalid link: identical records!
1 change: 1 addition & 0 deletions locales/Ukrainian.lng
Original file line number Diff line number Diff line change
Expand Up @@ -1026,3 +1026,4 @@
1013=contains mask
1014=not contains mask
1015=Move files
1016=Invalid link: identical records!
1 change: 1 addition & 0 deletions locales/help_enu/gkhHistory.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ <h1>Change log</h1>

<p><b>??.??.2025 [v2.32.1 &amp; v3.8.1]</b></p>
<ul>
<li>Added a number of checks for adding invalid links between different records.</li>
<li>Added functions for moving multimedia files between absolute and relative paths, archive and storage.</li>
<li>Minor improvements.</li>
</ul>
Expand Down
1 change: 1 addition & 0 deletions locales/help_rus/gkhHistory.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ <h1>История версий</h1>

<p><b>??.??.2025 [v2.32.1 &amp; v3.8.1]</b></p>
<ul>
<li>Добавлен ряд проверок на добавление недопустимых ссылок между различными записями.</li>
<li>Добавлены функции перемещения мультимедиа-файлов между абсолютными и относительными путями, архивом и хранилищем.</li>
<li>Мелкие улучшения.</li>
</ul>
Expand Down
5 changes: 5 additions & 0 deletions projects/GKCore/GDModel/GDMFamilyRecord.cs
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,11 @@ public void RemoveSpouse(GDMIndividualRecord spouse)
}
}

public bool HasMember(GDMIndividualRecord member)
{
return HasSpouse(member) || HasChild(member);
}

public bool HasSpouse(GDMIndividualRecord spouse)
{
return (spouse != null) && (fHusband.XRef == spouse.XRef || fWife.XRef == spouse.XRef);
Expand Down
5 changes: 5 additions & 0 deletions projects/GKCore/GKCore/BaseContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2041,6 +2041,11 @@ public async Task<GDMIndividualRecord> AddChildForParent(IView owner, GDMIndivid
}
}

if (family.HasMember(child)) {
AppHost.StdDialogs.ShowAlert(LangMan.LS(LSID.InvalidLink));
return null;
}

if (family.AddChild(child)) {
// this repetition necessary, because the call of CreatePersonDialog only works if person already has a father,
// what to call AddChild () is no; all this is necessary in order to in the namebook were correct patronymics.
Expand Down
18 changes: 17 additions & 1 deletion projects/GKCore/GKCore/Controllers/BaseController.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* "GEDKeeper", the personal genealogical database editor.
* Copyright (C) 2009-2024 by Sergey V. Zhdanovskih.
* Copyright (C) 2009-2025 by Sergey V. Zhdanovskih.
*
* This file is part of "GEDKeeper".
*
Expand Down Expand Up @@ -621,6 +621,12 @@ public static async Task<ModificationResult<GDMLocationLink>> ModifyLocationLink
result.Result = await AppHost.Instance.ShowModalAsync(dlg, owner, false);
}

if (locRec.XRef == locLink.XRef) {
AppHost.StdDialogs.ShowAlert(LangMan.LS(LSID.InvalidLink));
result.Result = false;
return result;
}

if (!exists) {
if (result.Result) {
result.Result = undoman.DoOrdinaryOperation(OperationType.otLocationLinkAdd, locRec, locLink);
Expand Down Expand Up @@ -1246,6 +1252,11 @@ public static async Task<bool> AddFamilyHusband(IView owner, IBaseWindow baseWin
var wife = baseWin.Context.Tree.GetPtrValue(family.Wife);
GDMIndividualRecord husband = await baseWin.Context.SelectPerson(owner, wife, TargetMode.tmSpouse, GDMSex.svMale);
if (husband != null && family.Husband.IsEmpty()) {
if (family.HasChild(husband)) {
AppHost.StdDialogs.ShowWarning(LangMan.LS(LSID.FatherAsChild));
return result;
}

result = localUndoman.DoOrdinaryOperation(OperationType.otFamilySpouseAttach, family, husband);
}

Expand Down Expand Up @@ -1273,6 +1284,11 @@ public static async Task<bool> AddFamilyWife(IView owner, IBaseWindow baseWin, C
var husband = baseWin.Context.Tree.GetPtrValue(family.Husband);
GDMIndividualRecord wife = await baseWin.Context.SelectPerson(owner, husband, TargetMode.tmSpouse, GDMSex.svFemale);
if (wife != null && family.Wife.IsEmpty()) {
if (family.HasChild(wife)) {
AppHost.StdDialogs.ShowWarning(LangMan.LS(LSID.MotherAsChild));
return result;
}

result = localUndoman.DoOrdinaryOperation(OperationType.otFamilySpouseAttach, family, wife);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,12 @@ public async void AddParents()
AcceptTempData();

GDMFamilyRecord family = await fBase.Context.SelectFamily(fView, fIndividualRecord);
if (family != null && family.IndexOfChild(fIndividualRecord) < 0) {
if (family != null) {
if (family.HasMember(fIndividualRecord)) {
AppHost.StdDialogs.ShowAlert(LangMan.LS(LSID.InvalidLink));
return;
}

fLocalUndoman.DoOrdinaryOperation(OperationType.otIndividualParentsAttach, fIndividualRecord, family);
}
UpdateControls();
Expand Down
5 changes: 5 additions & 0 deletions projects/GKCore/GKCore/Controllers/TreeChartWinController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,11 @@ private async void ParentAdd(GDMSex needSex)
fam.AddChild(p.Rec);
}

if (fam.HasMember(parent)) {
AppHost.StdDialogs.ShowAlert(LangMan.LS(LSID.InvalidLink));
return;
}

fam.AddSpouse(parent);

UpdateChart();
Expand Down
4 changes: 3 additions & 1 deletion projects/GKCore/GKCore/LangMan.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1090,8 +1090,9 @@ public enum LSID
/* 1013 */ CondContainsMask,
/* 1014 */ CondNotContainsMask,
/* 1015 */ MoveFiles,
/* 1016 */ InvalidLink,

/* 000 */ Last = MoveFiles
/* 000 */ Last = InvalidLink
}


Expand Down Expand Up @@ -2135,6 +2136,7 @@ public static class LangMan
/* 1013 */ "contains mask",
/* 1014 */ "not contains mask",
/* 1015 */ "Move files",
/* 1016 */ "Invalid link: identical records!",
};

private static readonly LangManager fLangMan = new LangManager();
Expand Down
12 changes: 11 additions & 1 deletion projects/GKCore/GKCore/Lists/ChildrenListModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,13 @@ public override async Task Modify(object sender, ModifyEventArgs eArgs)
switch (eArgs.Action) {
case RecordAction.raAdd:
child = await fBaseWin.Context.SelectPerson(fOwner, tree.GetPtrValue(family.Husband), TargetMode.tmParent, GDMSex.svUnknown);
result = (child != null && fBaseWin.Context.IsAvailableRecord(child) && !family.HasChild(child));
result = (child != null && fBaseWin.Context.IsAvailableRecord(child));
if (result) {
if (family.HasMember(child)) {
AppHost.StdDialogs.ShowAlert(LangMan.LS(LSID.InvalidLink));
return;
}

result = fUndoman.DoOrdinaryOperation(OperationType.otIndividualParentsAttach, child, family);
}
break;
Expand Down Expand Up @@ -191,6 +196,11 @@ public override async Task Modify(object sender, ModifyEventArgs eArgs)
child = await fBaseWin.Context.SelectPerson(fOwner, target, TargetMode.tmParent, GDMSex.svUnknown);
result = (child != null && fBaseWin.Context.IsAvailableRecord(child));
if (result) {
if (family.HasMember(child)) {
AppHost.StdDialogs.ShowAlert(LangMan.LS(LSID.InvalidLink));
return;
}

result = fUndoman.DoOrdinaryOperation(OperationType.otIndividualParentsAttach, child, family);
}
}
Expand Down
5 changes: 5 additions & 0 deletions projects/GKCore/GKCore/Lists/GroupListModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,11 @@ public override async Task Modify(object sender, ModifyEventArgs eArgs)
case RecordAction.raAdd:
member = await fBaseWin.Context.SelectPerson(fOwner, null, TargetMode.tmNone, GDMSex.svUnknown);
if (member != null) {
if (grp.IndexOfMember(member) >= 0) {
AppHost.StdDialogs.ShowAlert(LangMan.LS(LSID.InvalidLink));
return;
}

result = fUndoman.DoOrdinaryOperation(OperationType.otGroupMemberAttach, grp, member);
}
break;
Expand Down
12 changes: 11 additions & 1 deletion projects/GKCore/GKCore/Lists/IndividualListModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -782,6 +782,11 @@ public override async Task Modify(object sender, ModifyEventArgs eArgs)
case RecordAction.raAdd:
groupRec = await fBaseWin.Context.SelectRecord(fOwner, GDMRecordType.rtGroup, null) as GDMGroupRecord;
if (groupRec != null) {
if (groupRec.IndexOfMember(iRec) >= 0) {
AppHost.StdDialogs.ShowAlert(LangMan.LS(LSID.InvalidLink));
return;
}

result = fUndoman.DoOrdinaryOperation(OperationType.otGroupMemberAttach, groupRec, iRec);
}
break;
Expand Down Expand Up @@ -985,7 +990,12 @@ public override async Task Modify(object sender, ModifyEventArgs eArgs)
switch (eArgs.Action) {
case RecordAction.raAdd:
GDMFamilyRecord family = await fBaseWin.Context.SelectFamily(fOwner, iRec);
if (family != null && family.IndexOfChild(iRec) < 0) {
if (family != null) {
if (family.HasMember(iRec)) {
AppHost.StdDialogs.ShowAlert(LangMan.LS(LSID.InvalidLink));
return;
}

result = fUndoman.DoOrdinaryOperation(OperationType.otIndividualParentsAttach, iRec, family);
}
break;
Expand Down

0 comments on commit 7fbb3e3

Please sign in to comment.