def readContextUser(self, msg):
     ctx = self._findContext(msg)
     userId = self.extractUserId(msg)
     if userId == '':
         userData = {
             'id': '',
             'userId': '',
             'userName': '',
             'userEmail': '',
             'prefs': {}
         }
     else:
         user = UserData.read(userId)
         if not user:
             ctxId = msg.getContextValue(CONTEXT_USER_CONTEXT, None)
             user = UserData.readByLogin(userId, None, ctxId)
         if user is None:
             raise ProcessingExcept("No user found found in context")
         userData = {
             'id': user.getId(),
             'userId': user.getUserID(),
             'userName': user.getUserName(),
             'userEmail': user.getEmail(),
             'prefs': user.getPrefs(ctx.getName())
         }
     return self.makeResponse(msg, userData, INFORM_ACT)
 def readContextUserKeys(self, msg):
     ctx = self._findContext(msg)
     userId = self.extractUserId(msg)
     if userId == '':
         return self.makeResponse(msg, [], INFORM_ACT) #Anonymous
     else:
         usr = UserData.read(userId)
         if not usr:
             ctxId = msg.getContextValue(CONTEXT_USER_CONTEXT, None)
             usr = UserData.readByLogin(userId, None, ctxId)
         if not usr:
             raise ProcessingExcept("Could not find user " + userId)
         return self.makeResponse(msg, usr.getPrefs(ctx.getName()), INFORM_ACT)
 def hasUserInContext(self, msg):
     ctx = self._findContext(msg, False)
     userId = self.extractUserId(msg)
     user = UserData.read(userId)
     if not user:
         ctxId = msg.getContextValue(CONTEXT_USER_CONTEXT, None)
         user = UserData.readByLogin(userId, None, ctxId)
     if user is None:
         return False
     elif ctx is not None and (user.getId() not in ctx.getUsers()):
         return False
     else:
         return True
 def hasUserInContext(self, msg):
     ctx = self._findContext(msg, False)
     userId = self.extractUserId(msg)
     user = UserData.read(userId)
     if not user:
         ctxId = msg.getContextValue(CONTEXT_USER_CONTEXT, None)
         user = UserData.readByLogin(userId, None, ctxId)
     if user is None:
         return False
     elif ctx is not None and (user.getId() not in ctx.getUsers()):
         return False
     else:
         return True
Exemple #5
0
 def readContextUserKeys(self, msg):
     ctx = self._findContext(msg)
     userId = self.extractUserId(msg)
     if userId == '':
         return self.makeResponse(msg, [], INFORM_ACT) #Anonymous
     else:
         usr = UserData.read(userId)
         if not usr:
             ctxId = msg.getContextValue(CONTEXT_USER_CONTEXT, None)
             usr = UserData.readByLogin(userId, None, ctxId)
         if not usr:
             raise ProcessingExcept("Could not find user " + userId)
         return self.makeResponse(msg, usr.getPrefs(ctx.getName()), INFORM_ACT)
 def readContextUserVal(self, msg):
     ctx = self._findContext(msg)
     key = msg.getObject()
     if not key:
         raise ProcessingExcept("No user context pref key found")
     userId = self.extractUserId(msg)
     if userId == '':
         return self.makeResponse(msg, '', INFORM_ACT) #Anonymous  
     usr = UserData.read(userId)
     if not usr:
         ctxId = msg.getContextValue(CONTEXT_USER_CONTEXT, None)
         usr = UserData.readByLogin(userId, None, ctxId)
     if not usr:
         raise ProcessingExcept("Could not find user " + userId)
     value = usr.getPrefValue(ctx.getName(), key)
     return self.makeResponse(msg, value, INFORM_ACT)
 def readContextUserVal(self, msg):
     ctx = self._findContext(msg)
     key = msg.getObject()
     if not key:
         raise ProcessingExcept("No user context pref key found")
     userId = self.extractUserId(msg)
     if userId == '':
         return self.makeResponse(msg, '', INFORM_ACT)  #Anonymous
     usr = UserData.read(userId)
     if not usr:
         ctxId = msg.getContextValue(CONTEXT_USER_CONTEXT, None)
         usr = UserData.readByLogin(userId, None, ctxId)
     if not usr:
         raise ProcessingExcept("Could not find user " + userId)
     value = usr.getPrefValue(ctx.getName(), key)
     return self.makeResponse(msg, value, INFORM_ACT)
 def writeContextUserVal(self, msg):
     ctx = self._findContext(msg)
     key = msg.getObject()
     if not key:
         raise ProcessingExcept("No user context pref key found")
     userId = self.extractUserId(msg)
     #NOPE - writing for an anonymous user is an error
     if not userId or len(userId) == 0:
         raise ProcessingExcept("No user ID specified")
     usr = UserData.read(userId)
     if not usr:
         ctxId = msg.getContextValue(CONTEXT_USER_CONTEXT, None)
         usr = UserData.readByLogin(userId, None, ctxId)
     if not usr:
         raise ProcessingExcept("Could not find user " + userId)
         #usr = UserData.onLogin(userId)
         #ctx.addUser(userId)
         #ctx.save()
     value = msg.getResult()
     usr.setPrefValue(ctx.getName(), key, value)
     usr.save()
     return self.makeResponse(msg, True, CONFIRM_ACT)
 def readContextUser(self, msg):
     ctx = self._findContext(msg)
     userId = self.extractUserId(msg)
     if userId == '':
         userData = {'id': '',
                     'userId': '',
                     'userName': '',
                     'userEmail': '',
                     'prefs': {}}
     else:
         user = UserData.read(userId)
         if not user:
             ctxId = msg.getContextValue(CONTEXT_USER_CONTEXT, None)
             user = UserData.readByLogin(userId, None, ctxId)
         if user is None:
             raise ProcessingExcept("No user found found in context")
         userData = {'id': user.getId(),
                     'userId': user.getUserID(),
                     'userName': user.getUserName(),
                     'userEmail': user.getEmail(),
                     'prefs': user.getPrefs(ctx.getName())}
     return self.makeResponse(msg, userData, INFORM_ACT)
 def writeContextUserVal(self, msg):
     ctx = self._findContext(msg)
     key = msg.getObject()
     if not key:
         raise ProcessingExcept("No user context pref key found")
     userId = self.extractUserId(msg)
     #NOPE - writing for an anonymous user is an error
     if not userId or len(userId) == 0:
         raise ProcessingExcept("No user ID specified")
     usr = UserData.read(userId)
     if not usr:
         ctxId = msg.getContextValue(CONTEXT_USER_CONTEXT, None)
         usr = UserData.readByLogin(userId, None, ctxId)
     if not usr:
         raise ProcessingExcept("Could not find user " + userId)
         #usr = UserData.onLogin(userId)
         #ctx.addUser(userId)
         #ctx.save()
     value = msg.getResult()
     usr.setPrefValue(ctx.getName(), key, value)
     usr.save()
     return self.makeResponse(msg, True, CONFIRM_ACT)