class Workflow(EntityType): __permissions__ = PUB_SYSTEM_ENTITY_PERMS name = String(required=True, indexed=True, internationalizable=True, maxsize=256) description = RichString( default_format='text/rest', description=_('semantic description of this workflow')) workflow_of = SubjectRelation( 'CWEType', cardinality='+*', description=_('entity types which may use this workflow'), constraints=[RQLConstraint('O final FALSE')]) initial_state = SubjectRelation( 'State', cardinality='?*', constraints=[ RQLConstraint('O state_of S', msg=_('state doesn\'t belong to this workflow')) ], description=_('initial state for this workflow'))
class CWRelation(EntityType): """define a non final relation: link a non final relation type from a non final entity to a non final entity type. used to build the instance schema """ __permissions__ = PUB_SYSTEM_ENTITY_PERMS relation_type = SubjectRelation('CWRType', cardinality='1*', constraints=[RQLConstraint('O final FALSE')], composite='object') from_entity = SubjectRelation('CWEType', cardinality='1*', constraints=[RQLConstraint('O final FALSE')], composite='object') to_entity = SubjectRelation('CWEType', cardinality='1*', constraints=[RQLConstraint('O final FALSE')], composite='object') constrained_by = SubjectRelation('CWConstraint', cardinality='*1', composite='subject') cardinality = String(maxsize=2, internationalizable=True, vocabulary=CARDINALITY_VOCAB, description=_('subject/object cardinality')) ordernum = Int(description=_('control subject entity\'s relations order'), default=0) composite = String(description=_('is the subject/object entity of the relation ' 'composed of the other ? This implies that when ' 'the composite is deleted, composants are also ' 'deleted.'), vocabulary=('', _('subject'), _('object')), maxsize=8, default=None) description = RichString(internationalizable=True, description=_('semantic description of this relation'))
class SubWorkflowExitPoint(EntityType): """define how we get out from a sub-workflow""" subworkflow_state = SubjectRelation( 'State', cardinality='1*', constraints=[ RQLConstraint( 'T subworkflow_exit S, T subworkflow WF, O state_of WF', msg=_('exit state must be a subworkflow state')) ], description=_('subworkflow state')) destination_state = SubjectRelation( 'State', cardinality='?*', constraints=[ RQLConstraint( 'T subworkflow_exit S, T transition_of WF, O state_of WF', msg= _('destination state must be in the same workflow as our parent transition' )) ], description=_( 'destination state. No destination state means that transition ' 'should go back to the state from which we\'ve entered the ' 'subworkflow.'))
class CWAttribute(EntityType): """define a final relation: link a final relation type from a non final entity to a final entity type. used to build the instance schema """ __permissions__ = PUB_SYSTEM_ENTITY_PERMS relation_type = SubjectRelation('CWRType', cardinality='1*', constraints=[RQLConstraint('O final TRUE')], composite='object') from_entity = SubjectRelation('CWEType', cardinality='1*', constraints=[RQLConstraint('O final FALSE')], composite='object') to_entity = SubjectRelation('CWEType', cardinality='1*', constraints=[RQLConstraint('O final TRUE')], composite='object') constrained_by = SubjectRelation('CWConstraint', cardinality='*1', composite='subject') cardinality = String(maxsize=2, internationalizable=True, vocabulary=[_('?1'), _('11')], description=_('subject/object cardinality')) ordernum = Int(description=('control subject entity\'s relations order'), default=0) formula = String(maxsize=2048) indexed = Boolean(description=_('create an index for quick search on this attribute')) fulltextindexed = Boolean(description=_('index this attribute\'s value in the plain text index')) internationalizable = Boolean(description=_('is this attribute\'s value translatable')) defaultval = Bytes(description=_('default value as gziped pickled python object')) extra_props = Bytes(description=_('additional type specific properties')) description = RichString(internationalizable=True, description=_('semantic description of this attribute'))
class Personne(EntityType): nom = String(required=True) prenom = String() type = String() travaille = SubjectRelation('Societe') evaluee = SubjectRelation(('Note', 'Personne')) connait = SubjectRelation( 'Personne', symmetric=True, constraints=[ RQLConstraint('NOT S identity O'), # conflicting constraints, see cw_unrelated_rql tests in # unittest_entity.py RQLVocabularyConstraint('NOT (S connait P, P nom "toto")'), RQLVocabularyConstraint('S travaille P, P nom "tutu"') ]) actionnaire = SubjectRelation( 'Societe', cardinality='??', constraints=[RQLConstraint('NOT EXISTS(O contrat_exclusif S)')]) dirige = SubjectRelation('Societe', cardinality='??', constraints=[RQLConstraint('S actionnaire O')]) associe = SubjectRelation( 'Personne', cardinality='?*', constraints=[RQLConstraint('S actionnaire SOC, O actionnaire SOC')])
def test_user_constraint(self): cstr = RQLConstraint('U identity O') with self.admin_access.repo_cnx() as cnx: anoneid = cnx.execute('Any X WHERE X login "anon"')[0][0] self.assertRaises(ValidationError, cstr.repo_check, cnx, 1, 'rel', anoneid) self.assertEqual(cstr.repo_check(cnx, 1, cnx.user.eid), None) # no validation error, constraint checked
class State(EntityType): """used to associate simple states to an entity type and/or to define workflows """ __permissions__ = PUB_SYSTEM_ENTITY_PERMS __unique_together__ = [('name', 'state_of')] name = String(required=True, indexed=True, internationalizable=True, maxsize=256) description = RichString( default_format='text/rest', description=_('semantic description of this state')) # XXX should be on BaseTransition w/ AND/OR selectors when we will # implements #345274 allowed_transition = SubjectRelation( 'BaseTransition', cardinality='**', constraints=[ RQLConstraint( 'S state_of WF, O transition_of WF', msg=_( 'state and transition don\'t belong the the same workflow') ) ], description=_('allowed transitions from this state')) state_of = SubjectRelation( 'Workflow', cardinality='1*', composite='object', inlined=True, description=_('workflow to which this state belongs'))
class CWUser(WorkflowableEntityType): """define a CubicWeb user""" __permissions__ = { 'read': ('managers', 'users', ERQLExpression('X identity U')), 'add': ('managers', ), 'delete': ('managers', ), 'update': ( 'managers', ERQLExpression('X identity U, NOT U in_group G, G name "guests"'), ), } login = String( required=True, unique=True, maxsize=64, description=_('unique identifier used to connect to the application')) upassword = Password( required=True) # password is a reserved word for mysql firstname = String(maxsize=64) surname = String(maxsize=64) last_login_time = TZDatetime(description=_('last connection date')) in_group = SubjectRelation( 'CWGroup', cardinality='+*', constraints=[RQLConstraint('NOT O name "owners"')], description=_('groups grant permissions to the user'))
class Personne(EntityType): nom = String(required=True) prenom = String() enfant = SubjectRelation('Personne', inlined=True, cardinality='?*') connait = SubjectRelation('Personne', symmetric=True, constraints=[RQLConstraint('NOT S identity O')]) photo = Bytes()
class custom_workflow(RelationType): """allow to set a specific workflow for an entity""" __permissions__ = PUB_SYSTEM_REL_PERMS cardinality = '?*' constraints = [ RQLConstraint('S is ET, O workflow_of ET', msg=_('workflow isn\'t a workflow for this type')) ] object = 'Workflow'
class CWUniqueTogetherConstraint(EntityType): """defines a sql-level multicolumn unique index""" __permissions__ = PUB_SYSTEM_ENTITY_PERMS name = String(required=True, unique=True, maxsize=64) constraint_of = SubjectRelation('CWEType', cardinality='1*', composite='object', inlined=True) relations = SubjectRelation('CWRType', cardinality='+*', constraints=[RQLConstraint( 'S constraint_of ET, RDEF relation_type O, RDEF from_entity ET, ' 'O final TRUE OR (O final FALSE AND O inlined TRUE)')])
class default_workflow(RelationType): """default workflow for an entity type""" __permissions__ = PUB_SYSTEM_REL_PERMS subject = 'CWEType' object = 'Workflow' cardinality = '?*' constraints = [ RQLConstraint('S final FALSE, O workflow_of S', msg=_('workflow isn\'t a workflow for this type')) ]
class in_state(RelationType): """indicate the current state of an entity""" __permissions__ = RO_REL_PERMS # not inlined intentionnally since when using ldap sources, user'state # has to be stored outside the CWUser table inlined = False cardinality = '1*' constraints = [ RQLConstraint('S is ET, O state_of WF, WF workflow_of ET', msg=_('state doesn\'t apply to this entity\'s type')) ] object = 'State'
class Transition(BaseTransition): """use to define a transition from one or multiple states to a destination states in workflow's definitions. Transition without destination state will go back to the state from which we arrived to the current state. """ __specializes_schema__ = True destination_state = SubjectRelation( 'State', cardinality='?*', constraints=[ RQLConstraint( 'S transition_of WF, O state_of WF', msg=_( 'state and transition don\'t belong the the same workflow') ) ], description=_('destination state for this transition'))
class WorkflowTransition(BaseTransition): """special transition allowing to go through a sub-workflow""" __specializes_schema__ = True subworkflow = SubjectRelation( 'Workflow', cardinality='1*', constraints=[ RQLConstraint( 'S transition_of WF, WF workflow_of ET, O workflow_of ET', msg= _('subworkflow isn\'t a workflow for the same types as the transition\'s workflow' )) ]) # XXX use exit_of and inline it subworkflow_exit = SubjectRelation('SubWorkflowExitPoint', cardinality='*1', composite='subject')
class primary_email(RelationDefinition): """the prefered email""" __permissions__ = { 'read': ( 'managers', 'users', 'guests', ), 'add': ( 'managers', RRQLExpression('U has_update_permission S'), ), 'delete': ( 'managers', RRQLExpression('U has_update_permission S'), ), } subject = "CWUser" object = "EmailAddress" cardinality = '??' constraints = [RQLConstraint('S use_email O')]
class Note(Para): __specializes_schema__ = True __permissions__ = {'read': ('managers', 'users', 'guests',), 'update': ('managers', 'owners',), 'delete': ('managers', ), 'add': ('managers', ERQLExpression('X ecrit_part PE, U in_group G, ' 'PE require_permission P, P name "add_note", ' 'P require_group G'),)} whatever = Int(default=0) # keep it before `date` for unittest_migraction.test_add_attribute_int yesno = Boolean(default=False) date = Datetime() type = String(maxsize=1) unique_id = String(maxsize=1, required=True, unique=True) mydate = Date(default='TODAY') oldstyledefaultdate = Date(default='2013/01/01') newstyledefaultdate = Date(default=dt.date(2013, 1, 1)) shortpara = String(maxsize=11, default='hop', vocabulary=['hop', 'hop hop', 'hop hop hop']) ecrit_par = SubjectRelation('Personne', constraints=[RQLConstraint('S concerne A, O concerne A')]) attachment = SubjectRelation('File')