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

Refactor business rules #2965

Merged
merged 58 commits into from
May 19, 2023
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
135b342
Create static uniqueness rules file
melton-jason Feb 10, 2023
3bc8718
Refactor non-interaction business rules on the frontend
melton-jason Feb 10, 2023
2fc31dc
Refactor interaction business rules
melton-jason Feb 13, 2023
c4772c1
Fix remaining bugs
melton-jason Feb 16, 2023
86dfeba
Merge branch 'production' into refactor-busrules
melton-jason Feb 16, 2023
ad3f75d
Fix dockerize errors
melton-jason Feb 16, 2023
047b17a
Add missing UniquenessRules
melton-jason Feb 22, 2023
c810ea8
Remove _ dependency from businessRule files
melton-jason Feb 24, 2023
1d09705
Remove unnecessary _this statements
melton-jason Feb 24, 2023
7017a3c
Refactor out pluck function
melton-jason Feb 24, 2023
5611147
Remove unnecessary return statements in arrow functions
melton-jason Feb 24, 2023
ee19feb
Add type for Uniqueness Rules
melton-jason Feb 27, 2023
01a7275
Fix most typescript errors
melton-jason Feb 27, 2023
b08cf8e
Add type to BusinessRuleResult
melton-jason Feb 27, 2023
be8197f
Add count support for DNASequence geneSequence
melton-jason Feb 28, 2023
9713e12
Add UniquenessRule for TaxonTreeDef and TaxonTreeDefItem
melton-jason Feb 28, 2023
0068372
Merge branch 'production' into refactor-busrules
melton-jason Feb 28, 2023
070bce5
Fix typescript errors in interactionBusinessRules.ts
melton-jason Mar 1, 2023
7c4bb25
Address most code comments
melton-jason Mar 2, 2023
029d2da
Fix other misc. Typescript errors
melton-jason Mar 3, 2023
410fcf9
Merge branch 'production' into refactor-busrules
melton-jason Mar 6, 2023
6990364
Remove globalEvents in businessRules.ts
melton-jason Mar 6, 2023
684548a
Create a new a new object for assigning uniqueness rules
melton-jason Mar 7, 2023
cfed4da
Merge branch 'production' into refactor-busrules
melton-jason Mar 10, 2023
eea0b3c
Set Taxon.isAccepted on save to whether it is synonimized or not
melton-jason Mar 10, 2023
ced0397
Begin writing business rule tests
melton-jason Mar 10, 2023
3881441
Fix LoanReturnPreparation bugs
melton-jason Mar 14, 2023
73bbdc0
Merge branch 'production' into refactor-busrules
melton-jason Mar 14, 2023
f413f69
Narrow type of fieldName in checkField(...) to SCHEMA['fields']
melton-jason Mar 14, 2023
7252156
Add uniqueness rule tests
melton-jason Mar 16, 2023
c18fd80
Make field names lowercase in rule definitions
melton-jason Mar 16, 2023
d9513f6
Check prep availabiliy for Disposal when DisposalPrep quantity changes
melton-jason Mar 31, 2023
8bc316f
Merge branch 'production' into refactor-busrules
melton-jason Mar 31, 2023
f8083d0
Revert fieldnames to lowercase in business rule definitions
melton-jason Apr 4, 2023
1048348
Merge branch 'production' into refactor-busrules
melton-jason Apr 4, 2023
3fd7aad
Merge branch 'production' into refactor-busrules
melton-jason Apr 5, 2023
25997e2
Fix remaining Typescript errors
melton-jason Apr 12, 2023
4fdd0e1
Add static division for tests
melton-jason Apr 14, 2023
a056fec
Add overrideAjax calls to fix failing unit tests
melton-jason Apr 14, 2023
243ee0b
Modify getUniqueFields to follow new UniquenessRules format
melton-jason Apr 17, 2023
2245448
Add static files to address failing tests
melton-jason Apr 17, 2023
e846ab1
Change resource tests to accomadate new uniqueness rules
melton-jason Apr 17, 2023
2498fca
Add unique fields in fields to not clone test
melton-jason Apr 17, 2023
e23a148
Fix CollectionObject not being defined for schema.models in business …
melton-jason Apr 18, 2023
d130369
Add overrideAjax to all resources in business rule tests
melton-jason Apr 18, 2023
fb3389f
Remove redundant text-left classNames
maxpatiiuk Apr 19, 2023
86de81a
Cleanup manual overrdieAjax resources in business rule tests
melton-jason Apr 19, 2023
11c329e
Move resource creation into test block from describe block
melton-jason Apr 19, 2023
313914e
Move determination resource creation into test() blocks
melton-jason Apr 19, 2023
b5ddfe4
Move all overrideAjax calls to describe() scope
melton-jason Apr 19, 2023
8c71c70
Add missing getResourceApiUrl in overrideAjax call
melton-jason Apr 19, 2023
05bd279
Save original permit before checking for duplicate in businessRule tests
melton-jason Apr 19, 2023
f7ecb0e
Add fields to resources for uniqueness rule tests
melton-jason Apr 19, 2023
a5a3c2e
Move overrideAjax calls outside if describe() blocks
melton-jason Apr 19, 2023
672f283
Rename toOneField to scope
melton-jason Apr 19, 2023
73c0b84
Manually specify resource api url
melton-jason Apr 19, 2023
60da04b
Add static file ajax tests
melton-jason Apr 19, 2023
b9eeea0
Address code comments
melton-jason May 2, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 13 additions & 63 deletions specifyweb/businessrules/uniqueness_rules.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import json
from django.core.exceptions import ObjectDoesNotExist
from typing import Dict
from specifyweb.specify import models
from .orm_signal_handler import orm_signal_handler
from .exceptions import BusinessRuleException
Expand Down Expand Up @@ -27,6 +29,7 @@ def check_unique(instance):
else:
@orm_signal_handler('pre_save', model_name)
def check_unique(instance):
if isinstance(parent_field, dict): return
try:
parent = getattr(instance, parent_field + '_id', None)
except ObjectDoesNotExist:
Expand All @@ -52,71 +55,18 @@ def check_unique(instance):
"conflicting" : list(conflicts.values_list('id', flat=True)[:100])})
return check_unique

UNIQUENESS_RULES = {
'Accession': {
'accessionnumber': ['division'],
},
'Appraisal': {
'appraisalnumber': ['accession'],
},
'Author': {
'agent': ['referencework'],
'ordernumber': ['referencework'],
},
'Collection': {
'collectionname': ['discipline'],
'code': ['discipline'],
},
'Collectionobject': {
'catalognumber': ['collection'],
},
'Collector': {
'agent': ['collectingevent'],
},
'Discipline': {
'name': ['division'],
},
'Division': {
'name': ['institution'],
},
'Gift': {
'giftnumber': ['discipline'],
},
'Groupperson': {
'member': ['group'],
},
'Institution': {
'name': [None],
},
'Loan': {
'loannumber': ['discipline'],
},
'Permit': {
'permitnumber': [None],
},
'Picklist': {
'name': ['collection'],
},
'Preptype': {
'name': ['collection'],
},
'Repositoryagreement': {
'repositoryagreementnumber': ['division'],
},
'Spappresourcedata': {
'spappresource': [None],
},
}
RAW_UNIQUENESS_RULES: Dict[str, Dict[str, list]] = json.load(open('specifyweb/frontend/js_src/lib/components/DataModel/uniquness_rules.json'))

def parse_uniqueness_rules():
PARSED_UNIQUENESS_RULES = {}
for table, value in RAW_UNIQUENESS_RULES.items():
table = table.lower().capitalize()
if hasattr(models, table):
PARSED_UNIQUENESS_RULES[table] = value

# This check is provided to support the Specify 6.8.01
# datamodel (schema version 2.9). When support for that
# version is dropped it can be removed and this definition
# can be included in the block above.
if hasattr(models, 'Determiner'):
UNIQUENESS_RULES['Determiner'] = {
'agent': ['determination'],
}
return PARSED_UNIQUENESS_RULES

UNIQUENESS_RULES = parse_uniqueness_rules()


uniqueness_rules = [make_uniqueness_rule(model, parent_field, unique_field)
Expand Down
Loading