hooks/integrity.py
changeset 4075 e710f4052bd6
parent 4027 02273e65e1c2
child 4181 c79135c217df
equal deleted inserted replaced
4074:9cce43f52c61 4075:e710f4052bd6
     8 """
     8 """
     9 __docformat__ = "restructuredtext en"
     9 __docformat__ = "restructuredtext en"
    10 
    10 
    11 from cubicweb import ValidationError
    11 from cubicweb import ValidationError
    12 from cubicweb.schema import RQLConstraint, RQLUniqueConstraint
    12 from cubicweb.schema import RQLConstraint, RQLUniqueConstraint
    13 from cubicweb.selectors import entity_implements
    13 from cubicweb.selectors import implements
    14 from cubicweb.uilib import soup2xhtml
    14 from cubicweb.uilib import soup2xhtml
    15 from cubicweb.server import hook
    15 from cubicweb.server import hook
    16 
    16 
    17 # special relations that don't have to be checked for integrity, usually
    17 # special relations that don't have to be checked for integrity, usually
    18 # because they are handled internally by hooks (so we trust ourselves)
    18 # because they are handled internally by hooks (so we trust ourselves)
   235 
   235 
   236 class DontRemoveOwnersGroupHook(IntegrityHook):
   236 class DontRemoveOwnersGroupHook(IntegrityHook):
   237     """delete the composed of a composite relation when this relation is deleted
   237     """delete the composed of a composite relation when this relation is deleted
   238     """
   238     """
   239     __regid__ = 'checkownersgroup'
   239     __regid__ = 'checkownersgroup'
   240     __select__ = IntegrityHook.__select__ & entity_implements('CWGroup')
   240     __select__ = IntegrityHook.__select__ & implements('CWGroup')
   241     events = ('before_delete_entity', 'before_update_entity')
   241     events = ('before_delete_entity', 'before_update_entity')
   242 
   242 
   243     def __call__(self):
   243     def __call__(self):
   244         if self.event == 'before_delete_entity' and self.entity.name == 'owners':
   244         if self.event == 'before_delete_entity' and self.entity.name == 'owners':
   245             raise ValidationError(self.entity.eid, {None: self._cw._('can\'t be deleted')})
   245             raise ValidationError(self.entity.eid, {None: self._cw._('can\'t be deleted')})
   271 
   271 
   272 
   272 
   273 class StripCWUserLoginHook(IntegrityHook):
   273 class StripCWUserLoginHook(IntegrityHook):
   274     """ensure user logins are stripped"""
   274     """ensure user logins are stripped"""
   275     __regid__ = 'stripuserlogin'
   275     __regid__ = 'stripuserlogin'
   276     __select__ = IntegrityHook.__select__ & entity_implements('CWUser')
   276     __select__ = IntegrityHook.__select__ & implements('CWUser')
   277     events = ('before_add_entity', 'before_update_entity',)
   277     events = ('before_add_entity', 'before_update_entity',)
   278 
   278 
   279     def __call__(self):
   279     def __call__(self):
   280         user = self.entity
   280         user = self.entity
   281         if 'login' in user.edited_attributes and user.login:
   281         if 'login' in user.edited_attributes and user.login: