Commit 6dae52b6 authored by Sylvain Thénault's avatar Sylvain Thénault
Browse files

Set sensible default user_cardinality on some entities

For those entities, user cardinality will be hidden for simplified profile
because it's expected to be '1'. Changing the default in the schema will
ensure that entities created on a simplified profile will have the proper
cardinality, and that default values displayed on a full profile will be
compatible.
parent 508d1fb489a7
......@@ -284,7 +284,7 @@ class archive_transfer_need_authorization(RelationDefinition):
inlined = True
constraints = []
@seda_profile_element(cardinalities=['0..1', '0..n', '1', '1..n'], default_cardinality='0..1',
@seda_profile_element(cardinalities=['0..1', '0..n', '1', '1..n'], default_cardinality='1',
annotable=True)
class SEDASeqClassificationRuleRule(EntityType):
u""""""
......@@ -403,7 +403,7 @@ class seq_classification_rule_rule_rule(RelationDefinition):
inlined = True
constraints = [RQLConstraint('O in_scheme CS, CACLV seda_classification_rule_code_list_version_from AT, CACLV seda_classification_rule_code_list_version_to CS,S container AT')]
@seda_profile_element(cardinalities=['0..1', '1'], default_cardinality='0..1',
@seda_profile_element(cardinalities=['0..1', '1'], default_cardinality='1',
annotable=True)
class SEDAStartDate(EntityType):
u""""""
......@@ -418,7 +418,7 @@ class seq_classification_rule_rule_start_date(RelationDefinition):
inlined = True
constraints = []
@seda_profile_element(cardinalities=['0..1', '0..n', '1', '1..n'], default_cardinality='0..1',
@seda_profile_element(cardinalities=['0..1', '0..n', '1', '1..n'], default_cardinality='1',
annotable=True)
class SEDASeqReuseRuleRule(EntityType):
u""""""
......@@ -457,7 +457,7 @@ class seq_reuse_rule_rule_rule(RelationDefinition):
inlined = True
constraints = [RQLConstraint('O in_scheme CS, CACLV seda_reuse_rule_code_list_version_from AT, CACLV seda_reuse_rule_code_list_version_to CS,S container AT')]
@seda_profile_element(cardinalities=['0..1', '0..n', '1', '1..n'], default_cardinality='0..1',
@seda_profile_element(cardinalities=['0..1', '0..n', '1', '1..n'], default_cardinality='1',
annotable=True)
class SEDASeqDisseminationRuleRule(EntityType):
u""""""
......@@ -496,7 +496,7 @@ class seq_dissemination_rule_rule_rule(RelationDefinition):
inlined = True
constraints = [RQLConstraint('O in_scheme CS, CACLV seda_dissemination_rule_code_list_version_from AT, CACLV seda_dissemination_rule_code_list_version_to CS,S container AT')]
@seda_profile_element(cardinalities=['0..1', '0..n', '1', '1..n'], default_cardinality='0..1',
@seda_profile_element(cardinalities=['0..1', '0..n', '1', '1..n'], default_cardinality='1',
annotable=True)
class SEDASeqAccessRuleRule(EntityType):
u""""""
......@@ -535,7 +535,7 @@ class seq_access_rule_rule_rule(RelationDefinition):
inlined = True
constraints = [RQLConstraint('O in_scheme CS, CACLV seda_access_rule_code_list_version_from AT, CACLV seda_access_rule_code_list_version_to CS,S container AT')]
@seda_profile_element(cardinalities=['0..1', '0..n', '1', '1..n'], default_cardinality='0..1',
@seda_profile_element(cardinalities=['0..1', '0..n', '1', '1..n'], default_cardinality='1',
annotable=True)
class SEDASeqAppraisalRuleRule(EntityType):
u""""""
......@@ -583,7 +583,7 @@ class seq_appraisal_rule_rule_rule(RelationDefinition):
inlined = True
constraints = [RQLConstraint('O in_scheme CS, CACLV seda_appraisal_rule_code_list_version_from AT, CACLV seda_appraisal_rule_code_list_version_to CS,S container AT')]
@seda_profile_element(cardinalities=['0..1', '0..n', '1', '1..n'], default_cardinality='0..1',
@seda_profile_element(cardinalities=['0..1', '0..n', '1', '1..n'], default_cardinality='1',
annotable=True)
class SEDASeqStorageRuleRule(EntityType):
u""""""
......
......@@ -537,7 +537,7 @@ class SEDAExportFuncTCMixIn(object):
access_rule = create('SEDAAccessRule', seda_access_rule=transfer)
access_rule_seq = create('SEDASeqAccessRuleRule',
reverse_seda_seq_access_rule_rule=access_rule)
create('SEDAStartDate', seda_start_date=access_rule_seq)
create('SEDAStartDate', user_cardinality=u'0..1', seda_start_date=access_rule_seq)
# binary data object
bdo = create('SEDABinaryDataObject', id=u"bdo1", user_cardinality=u'0..n',
seda_binary_data_object=transfer,
......@@ -557,7 +557,7 @@ class SEDAExportFuncTCMixIn(object):
appraisal_rule = create('SEDAAppraisalRule', seda_appraisal_rule=unit_alt_seq)
appraisal_rule_seq = create('SEDASeqAppraisalRuleRule',
reverse_seda_seq_appraisal_rule_rule=appraisal_rule)
create('SEDAStartDate', seda_start_date=appraisal_rule_seq)
create('SEDAStartDate', user_cardinality=u'0..1', seda_start_date=appraisal_rule_seq)
access_rule = create('SEDAAccessRule', seda_access_rule=unit_alt_seq)
create('SEDADisseminationRule', seda_dissemination_rule=unit_alt_seq)
create('SEDAReuseRule', seda_reuse_rule=unit_alt_seq)
......@@ -703,7 +703,8 @@ class OldSEDAExportMixin(object):
user_cardinality=u'1',
seda_content=unit_alt_seq,
seda_description_level=concepts['file'],
reverse_seda_start_date=create('SEDAStartDate'),
reverse_seda_start_date=create('SEDAStartDate',
user_cardinality=u'0..1'),
reverse_seda_end_date=create('SEDAEndDate'),
# XXX, value=date(2015, 2, 24)),
reverse_seda_description=create('SEDADescription'))
......
......@@ -125,6 +125,21 @@ class SchemaTC(CubicWebTC):
self.assertEqual(rqlexpr.expression, 'U has_{action}_permission C, '
'X container C'.format(action=action))
def test_rule_default_cardinality(self):
with self.admin_access.client_cnx() as cnx:
transfer = cnx.create_entity('SEDAArchiveTransfer', title=u'test profile')
for rule_type in ('access', 'appraisal'):
rule_etype = 'SEDA{0}Rule'.format(rule_type.capitalize())
rule_rtype = 'seda_{0}_rule'.format(rule_type)
rule = cnx.create_entity(rule_etype, **{rule_rtype: transfer})
rule_rule_etype = 'SEDASeq{0}RuleRule'.format(rule_type.capitalize())
rule_rule_rtype = 'reverse_seda_seq_{0}_rule_rule'.format(rule_type)
rule_rule = cnx.create_entity(rule_rule_etype, **{rule_rule_rtype: rule})
self.assertEqual(rule_rule.user_cardinality, '1')
start_date = cnx.create_entity('SEDAStartDate', seda_start_date=rule_rule)
self.assertEqual(start_date.user_cardinality, '1')
class SecurityTC(CubicWebTC):
......
......@@ -177,6 +177,12 @@ RTYPE_CARDS = {
RTYPE_CARD = {
'seda_custodial_history_item': '*',
}
DEFAULT_USER_CARDINALITY = {
'SEDAStartDate': '1',
}
for rule_type in RULE_TYPES:
etype = 'SEDASeq{0}RuleRule'.format(rule_type.capitalize())
DEFAULT_USER_CARDINALITY[etype] = '1'
_CARD_TO_CARDS = {
'1': ['1'],
......@@ -433,8 +439,9 @@ from cubes.seda.schema import seda_profile_element
if mapping.cards:
cards = mapping.cards
annotable = len(cards) > 1
default_card = DEFAULT_USER_CARDINALITY.get(mapping.etype, cards[0])
code = '''\
@seda_profile_element(cardinalities={cards}, default_cardinality='{cards[0]}',
@seda_profile_element(cardinalities={cards}, default_cardinality='{default_card}',
annotable={annotable})
'''.format(**locals())
else:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment