Exemplo n.º 1
0
    def delete_acl_in_channel_for_action(self, channel_id: str, acl_type: str, action: str) -> None:
        if not self.channel_exists(channel_id):
            raise NoSuchChannelException(channel_id)

        if action not in ApiActions.all_api_actions:
            raise InvalidApiActionException(action)

        key = '%s|%s' % (action, acl_type)
        self.redis.hdel(RedisKeys.channel_acl(channel_id), key)
Exemplo n.º 2
0
    def get_all_acls_channel(self, channel_id: str) -> dict:
        self.get_channel_name(channel_id)

        acls = self.redis.hgetall(RedisKeys.channel_acl(channel_id))
        acls_cleaned = dict()

        for acl_key, acl_value in acls.items():
            acl_action, acl_type = str(acl_key, 'utf-8').split('|', 1)
            if acl_action not in acls_cleaned:
                acls_cleaned[acl_action] = dict()
            acls_cleaned[acl_action][acl_type] = str(acl_value, 'utf-8')

        return acls_cleaned
Exemplo n.º 3
0
    def add_acls_in_channel_for_action(self, channel_id: str, action: str, acls: dict) -> None:
        if not self.channel_exists(channel_id):
            raise NoSuchChannelException(channel_id)

        if action not in ApiActions.all_api_actions:
            raise InvalidApiActionException(action)

        new_acls = dict()
        acl_configs = environ.env.config.get(ConfigKeys.ACL)

        for acl_type, acl_value in acls.items():
            if acl_type not in acl_configs['available']['acls']:
                raise InvalidAclTypeException(acl_type)

            acl_configs['validation'][acl_type]['value'].validate_new_acl(acl_value)
            key = '%s|%s' % (action, acl_type)
            new_acls[key] = acl_value

        if len(new_acls) == 0:
            return
        self.redis.hmset(RedisKeys.channel_acl(channel_id), new_acls)
Exemplo n.º 4
0
 def remove_channel(self, channel_id: str) -> None:
     self.redis.hdel(RedisKeys.channels(), channel_id)
     self.redis.hdel(RedisKeys.banned_users_channel(channel_id))
     self.redis.hdel(RedisKeys.channel_acl(channel_id))
Exemplo n.º 5
0
 def set_channel_acl(self, acls: dict, channel_id=CHANNEL_ID):
     for api_action, acls_items in acls.items():
         for acl_type, acl_value in acls_items.items():
             r_key = '%s|%s' % (api_action, acl_type)
             environ.env.storage.redis.hset(
                 RedisKeys.channel_acl(channel_id), r_key, acl_value)