Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a realtionship to CO to be able to add parent COG #5433

Open
wants to merge 12 commits into
base: production
Choose a base branch
from
19 changes: 19 additions & 0 deletions specifyweb/businessrules/rules/cojo_rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@ def cojo_pre_save(cojo):
):
raise BusinessRuleException('ChildCog is already in use as a child in another COG.')

if (
cojo.childco is not None
and cojo.childco.cojo is not None
and cojo.childco.cojo.id is not cojo.id
and not is_running_tests()
):
raise BusinessRuleException('ChildCo is already in use as a child in another COG.')

if (cojo.childcog_id == cojo.parentcog_id):
raise BusinessRuleException(f"Cannot add a COG to itself. COG name: {cojo.childcog.name}")

Expand All @@ -50,4 +58,15 @@ def cog_post_save(cog):
childcog=cog,
childco=None,
parentcog=cog.parentcog
)

@orm_signal_handler('post_save', 'Collectionobject')
def cog_post_save(co):
CarolineDenis marked this conversation as resolved.
Show resolved Hide resolved
# Delete cojos that point to this CO to ensure we avoid multiple COGs having the same child co
Collectionobjectgroupjoin.objects.filter(childco=co).delete()
if co.coparentcog is not None:
Collectionobjectgroupjoin.objects.get_or_create(
childco=co,
childcog=None,
parentcog=co.coparentcog
)
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,20 @@ export const businessRuleDefs: MappedBusinessRuleDefs = {
});
return undefined;
},
parentCog: async (cog): Promise<BusinessRuleResult> => {
if (cog.url() === cog.get('parentCog')) {
return {
isValid: false,
reason: resourcesText.parentCogSameAsChild(),
saveBlockerKey: PARENTCOG_KEY,
};
}

return {
isValid: true,
saveBlockerKey: PARENTCOG_KEY,
};
},
CarolineDenis marked this conversation as resolved.
Show resolved Hide resolved
},
},

Expand Down
Loading
Loading