hooks/security.py
changeset 4835 13b0b96d7982
parent 4577 049d92fc8614
child 4970 1f3d8946ea84
equal deleted inserted replaced
4834:b718626a0e60 4835:13b0b96d7982
     7 :license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses
     7 :license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses
     8 """
     8 """
     9 __docformat__ = "restructuredtext en"
     9 __docformat__ = "restructuredtext en"
    10 
    10 
    11 from cubicweb import Unauthorized
    11 from cubicweb import Unauthorized
       
    12 from cubicweb.selectors import objectify_selector, lltrace
    12 from cubicweb.server import BEFORE_ADD_RELATIONS, ON_COMMIT_ADD_RELATIONS, hook
    13 from cubicweb.server import BEFORE_ADD_RELATIONS, ON_COMMIT_ADD_RELATIONS, hook
    13 
    14 
    14 
    15 
    15 def check_entity_attributes(session, entity, editedattrs=None):
    16 def check_entity_attributes(session, entity, editedattrs=None):
    16     eid = entity.eid
    17     eid = entity.eid
    51 
    52 
    52     def commit_event(self):
    53     def commit_event(self):
    53         pass
    54         pass
    54 
    55 
    55 
    56 
       
    57 @objectify_selector
       
    58 @lltrace
       
    59 def write_security_enabled(cls, req, **kwargs):
       
    60     if req is None or not req.write_security:
       
    61         return 0
       
    62     return 1
       
    63 
    56 class SecurityHook(hook.Hook):
    64 class SecurityHook(hook.Hook):
    57     __abstract__ = True
    65     __abstract__ = True
    58     category = 'security'
    66     category = 'security'
    59     __select__ = hook.Hook.__select__ & hook.regular_session()
    67     __select__ = hook.Hook.__select__ & write_security_enabled()
    60 
    68 
    61 
    69 
    62 class AfterAddEntitySecurityHook(SecurityHook):
    70 class AfterAddEntitySecurityHook(SecurityHook):
    63     __regid__ = 'securityafteraddentity'
    71     __regid__ = 'securityafteraddentity'
    64     events = ('after_add_entity',)
    72     events = ('after_add_entity',)