hooks/syncsession.py
branchstable
changeset 7879 9aae456abab5
parent 7398 26695dd703d8
child 8190 2a3c1b787688
equal deleted inserted replaced
7874:be04706eacc9 7879:9aae456abab5
    38 
    38 
    39 # user/groups synchronisation #################################################
    39 # user/groups synchronisation #################################################
    40 
    40 
    41 class _GroupOperation(hook.Operation):
    41 class _GroupOperation(hook.Operation):
    42     """base class for group operation"""
    42     """base class for group operation"""
    43     geid = None
    43     cnxuser = None # make pylint happy
       
    44 
    44     def __init__(self, session, *args, **kwargs):
    45     def __init__(self, session, *args, **kwargs):
    45         """override to get the group name before actual groups manipulation:
    46         """override to get the group name before actual groups manipulation:
    46 
    47 
    47         we may temporarily loose right access during a commit event, so
    48         we may temporarily loose right access during a commit event, so
    48         no query should be emitted while comitting
    49         no query should be emitted while comitting
    53         self.group = result[0][0]
    54         self.group = result[0][0]
    54 
    55 
    55 
    56 
    56 class _DeleteGroupOp(_GroupOperation):
    57 class _DeleteGroupOp(_GroupOperation):
    57     """synchronize user when a in_group relation has been deleted"""
    58     """synchronize user when a in_group relation has been deleted"""
       
    59 
    58     def postcommit_event(self):
    60     def postcommit_event(self):
    59         """the observed connections set has been commited"""
    61         """the observed connections set has been commited"""
    60         groups = self.cnxuser.groups
    62         groups = self.cnxuser.groups
    61         try:
    63         try:
    62             groups.remove(self.group)
    64             groups.remove(self.group)
   115             _DelUserOp(self._cw, session.id)
   117             _DelUserOp(self._cw, session.id)
   116 
   118 
   117 
   119 
   118 # CWProperty hooks #############################################################
   120 # CWProperty hooks #############################################################
   119 
   121 
   120 
       
   121 class _DelCWPropertyOp(hook.Operation):
   122 class _DelCWPropertyOp(hook.Operation):
   122     """a user's custom properties has been deleted"""
   123     """a user's custom properties has been deleted"""
       
   124     cwpropdict = key = None # make pylint happy
   123 
   125 
   124     def postcommit_event(self):
   126     def postcommit_event(self):
   125         """the observed connections set has been commited"""
   127         """the observed connections set has been commited"""
   126         try:
   128         try:
   127             del self.cwpropdict[self.key]
   129             del self.cwpropdict[self.key]
   129             self.error('%s has no associated value', self.key)
   131             self.error('%s has no associated value', self.key)
   130 
   132 
   131 
   133 
   132 class _ChangeCWPropertyOp(hook.Operation):
   134 class _ChangeCWPropertyOp(hook.Operation):
   133     """a user's custom properties has been added/changed"""
   135     """a user's custom properties has been added/changed"""
       
   136     cwpropdict = key = value = None # make pylint happy
   134 
   137 
   135     def postcommit_event(self):
   138     def postcommit_event(self):
   136         """the observed connections set has been commited"""
   139         """the observed connections set has been commited"""
   137         self.cwpropdict[self.key] = self.value
   140         self.cwpropdict[self.key] = self.value
   138 
   141 
   139 
   142 
   140 class _AddCWPropertyOp(hook.Operation):
   143 class _AddCWPropertyOp(hook.Operation):
   141     """a user's custom properties has been added/changed"""
   144     """a user's custom properties has been added/changed"""
       
   145     cwprop = None # make pylint happy
   142 
   146 
   143     def postcommit_event(self):
   147     def postcommit_event(self):
   144         """the observed connections set has been commited"""
   148         """the observed connections set has been commited"""
   145         cwprop = self.cwprop
   149         cwprop = self.cwprop
   146         if not cwprop.for_user:
   150         if not cwprop.for_user: