예제 #1
0
파일: redis.py 프로젝트: labrook/dino
 def get_super_users(self) -> dict:
     users = self.redis.hgetall(RedisKeys.global_roles())
     super_users = dict()
     for user_id in users.keys():
         user_id = str(user_id, 'utf-8')
         super_users[user_id] = self.get_user_name(user_id)
     return super_users
예제 #2
0
파일: redis.py 프로젝트: labrook/dino
    def get_user_roles(self, user_id: str) -> dict:
        output = {
            'global': list(),
            'channel': dict(),
            'room': dict()
        }

        checked_channels = set()
        rooms = self.redis.hgetall(RedisKeys.rooms_for_user(user_id))

        global_roles = self.redis.hget(RedisKeys.global_roles(), user_id)
        if global_roles is not None:
            global_roles = str(global_roles, 'utf-8')
            output['global'] = [a for a in global_roles.split(',')]

        for room_id, _ in rooms.items():
            room_id = str(room_id, 'utf-8')
            channel_id = self.channel_for_room(room_id)
            room_roles = self.redis.hget(RedisKeys.room_roles(room_id), user_id)

            if channel_id not in checked_channels:
                checked_channels.add(channel_id)
                channel_roles = self.redis.hget(RedisKeys.channel_roles(channel_id), user_id)
                if channel_roles is not None:
                    channel_roles = str(channel_roles, 'utf-8')
                    output['channel'][channel_id] = [a for a in channel_roles.split(',')]

            if room_roles is not None:
                room_roles = str(room_roles, 'utf-8')
                output['room'][room_id] = [a for a in room_roles.split(',')]
        return output
예제 #3
0
파일: redis.py 프로젝트: labrook/dino
 def _add_global_role(self, user_id: str, role: str):
     key = RedisKeys.global_roles()
     roles = self.redis.hget(key, user_id)
     if roles is None:
         roles = role
     else:
         roles = set(str(roles, 'utf-8').split(','))
         roles.add(role)
         roles = ','.join(roles)
     self.redis.hset(key, user_id, roles)
예제 #4
0
파일: redis.py 프로젝트: labrook/dino
    def _remove_global_role(self, user_id: str, role: str):
        key = RedisKeys.global_roles()
        roles = self.redis.hget(key, user_id)
        if roles is None:
            return

        roles = set(str(roles, 'utf-8').split(','))
        if role not in roles:
            return

        roles.remove(role)
        roles = ','.join(roles)
        self.redis.hset(key, user_id, roles)
예제 #5
0
파일: redis.py 프로젝트: labrook/dino
 def _has_global_role(self, user_id: str, role: str) -> bool:
     roles = self.redis.hget(RedisKeys.global_roles(), user_id)
     if roles is None:
         return False
     return role in str(roles, 'utf-8').split(',')