def create_admin_room(self) -> str: admin_room_id = self.get_admin_room() if admin_room_id is not None: return admin_room_id try: self.create_user('0', 'Admin') except UserExistsException: pass channel_id = str(uuid()) room_id = str(uuid()) self.create_channel('Admins', channel_id, '0') self.redis.set(RedisKeys.admin_room(), room_id) self.redis.hset(RedisKeys.room_name_for_id(), room_id, 'Admins') self.redis.hset(RedisKeys.rooms(channel_id), room_id, 'Admins') self.redis.hset(RedisKeys.channel_for_rooms(), room_id, channel_id) self.redis.sadd(RedisKeys.non_ephemeral_rooms(), room_id) acls = { RoleKeys.ADMIN: '', RoleKeys.SUPER_USER: '' } samechannel = { 'samechannel': '' } self.add_acls_in_channel_for_action(channel_id, ApiActions.LIST, acls) self.add_acls_in_channel_for_action(channel_id, ApiActions.JOIN, acls) self.add_acls_in_room_for_action(room_id, ApiActions.JOIN, acls) self.add_acls_in_room_for_action(room_id, ApiActions.LIST, acls) self.add_acls_in_room_for_action(room_id, ApiActions.CROSSROOM, samechannel) return room_id
def get_admin_room(self) -> str: key = RedisKeys.admin_room() value = self.cache.get(key) if value is not None: return value room_id = self.redis.get(key) if room_id is None or len(str(room_id, 'utf-8').strip()) == 0: return None room_id = str(room_id, 'utf-8') self.cache.set(key, room_id, ttl=EIGHT_HOURS_IN_SECONDS) return room_id
def set_admin_room(self, room_id: str) -> None: key = RedisKeys.admin_room() self.redis.set(key, room_id) self.cache.set(key, room_id, ttl=EIGHT_HOURS_IN_SECONDS)
def remove_admin_room(self) -> None: key = RedisKeys.admin_room() self.redis.delete(key) self.cache.delete(key)
def test_get_admin_room_after_expired(self): self.cache.set_admin_room(CacheRedisTest.ROOM_ID) self.assertEqual(CacheRedisTest.ROOM_ID, self.cache.get_admin_room()) key = RedisKeys.admin_room() self.cache._del(key) self.assertEqual(CacheRedisTest.ROOM_ID, self.cache.get_admin_room())
def get_admin_room(self) -> str: room_id = self.redis.get(RedisKeys.admin_room()) if room_id is None or len(str(room_id, 'utf-8').strip()) == 0: return None return str(room_id, 'utf-8')
def set_admin_room(self, room_uuid: str) -> None: self.redis.set(RedisKeys.admin_room(), room_uuid)
def unset_admin_room(self, room_uuid: str) -> None: self.redis.delete(RedisKeys.admin_room())