hooks/integrity.py
branchstable
changeset 5994 97c55baefa0c
parent 5877 0c7b7b76a84f
child 6142 8bc6eac1fac1
child 6375 df4fd2a1b0e7
equal deleted inserted replaced
5976:00b1b6b906cf 5994:97c55baefa0c
    25 
    25 
    26 from yams.schema import role_name
    26 from yams.schema import role_name
    27 
    27 
    28 from cubicweb import ValidationError
    28 from cubicweb import ValidationError
    29 from cubicweb.schema import RQLConstraint, RQLUniqueConstraint
    29 from cubicweb.schema import RQLConstraint, RQLUniqueConstraint
    30 from cubicweb.selectors import implements
    30 from cubicweb.selectors import is_instance
    31 from cubicweb.uilib import soup2xhtml
    31 from cubicweb.uilib import soup2xhtml
    32 from cubicweb.server import hook
    32 from cubicweb.server import hook
    33 from cubicweb.server.hook import set_operation
    33 from cubicweb.server.hook import set_operation
    34 
    34 
    35 # special relations that don't have to be checked for integrity, usually
    35 # special relations that don't have to be checked for integrity, usually
   251 
   251 
   252 class DontRemoveOwnersGroupHook(IntegrityHook):
   252 class DontRemoveOwnersGroupHook(IntegrityHook):
   253     """delete the composed of a composite relation when this relation is deleted
   253     """delete the composed of a composite relation when this relation is deleted
   254     """
   254     """
   255     __regid__ = 'checkownersgroup'
   255     __regid__ = 'checkownersgroup'
   256     __select__ = IntegrityHook.__select__ & implements('CWGroup')
   256     __select__ = IntegrityHook.__select__ & is_instance('CWGroup')
   257     events = ('before_delete_entity', 'before_update_entity')
   257     events = ('before_delete_entity', 'before_update_entity')
   258 
   258 
   259     def __call__(self):
   259     def __call__(self):
   260         if self.event == 'before_delete_entity' and self.entity.name == 'owners':
   260         if self.event == 'before_delete_entity' and self.entity.name == 'owners':
   261             msg = self._cw._('can\'t be deleted')
   261             msg = self._cw._('can\'t be deleted')
   291 
   291 
   292 
   292 
   293 class StripCWUserLoginHook(IntegrityHook):
   293 class StripCWUserLoginHook(IntegrityHook):
   294     """ensure user logins are stripped"""
   294     """ensure user logins are stripped"""
   295     __regid__ = 'stripuserlogin'
   295     __regid__ = 'stripuserlogin'
   296     __select__ = IntegrityHook.__select__ & implements('CWUser')
   296     __select__ = IntegrityHook.__select__ & is_instance('CWUser')
   297     events = ('before_add_entity', 'before_update_entity',)
   297     events = ('before_add_entity', 'before_update_entity',)
   298 
   298 
   299     def __call__(self):
   299     def __call__(self):
   300         user = self.entity
   300         user = self.entity
   301         if 'login' in user.edited_attributes and user.login:
   301         if 'login' in user.edited_attributes and user.login: