def _test_online_users(self, username1, username2): """ Tests the confirm_as_online, get_online_usernames and get_online_members methods """ portal = self.portal # First clear the UAD server = utils.getConnection(self.portal) server._v_user_access_dict = {} online_users = utils.get_online_usernames(portal) self.assertEquals(online_users, []) online_members = utils.get_online_members(portal) self.assertEquals(online_members, []) self.logout() resp = json.loads(server.confirmAsOnline(None)) self.assertEquals(resp['status'], config.ERROR) self.login(name=username1) server = utils.getConnection(self.portal) resp = json.loads(server.confirmAsOnline(username1)) self.assertEquals(resp['status'], config.SUCCESS) online_users = utils.get_online_usernames(portal) self.assertEquals(online_users, [username1]) # get_online_members ignores the currently logged in user. # So, if username1 is currently logged in and also online (according to # get_online_users), get_online_members will still return an empty # list. online_members = utils.get_online_members(portal) self.assertEquals(online_members, []) self.logout() self.login(name=username2) server = utils.getConnection(self.portal) resp = json.loads(server.confirmAsOnline(username2)) self.assertEquals(resp['status'], config.SUCCESS) online_users = utils.get_online_usernames(portal) online_users.sort() self.assertEquals(online_users, [username1, username2]) # Again, the logged in username2 is ignored member1 = self.mtool.getMemberById(username1) online_members = utils.get_online_members(portal) self.assertEquals(online_members, [member1]) self.logout() # Now the logged in username1 is ignored self.login(name=username1) member2 = self.mtool.getMemberById(username2) online_members = utils.get_online_members(portal) self.assertEquals(online_members, [member2])
def render_chat_box(self, chat_id, box_id, tzoffset): """ """ if chat_id == 'actionbar_babble_online_contacts': online_users = utils.get_online_members(self.context) template = ViewPageTemplateFile('templates/onlinecontacts.pt') return template(self, online_users=online_users, chat_id=chat_id, box_id=box_id) elif chat_id == 'actionbar_babble_chat_rooms': chatrooms = utils.get_chat_rooms(self.context) template = ViewPageTemplateFile('templates/chatrooms.pt') return template(self, chatrooms=chatrooms, chat_id=chat_id, box_id=box_id) else: return super(BabbleChatBox, self).render_chat_box(chat_id, box_id, tzoffset)
def get_online_members(self): return utils.get_online_members(self.context)