RocketChat / Rocket.Chat.Apps-engine

The Rocket.Chat Apps engine and definitions.

Home Page:https://rocketchat.github.io/Rocket.Chat.Apps-engine/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[BUG] IServerSettingRead getValueById fn not working as expected for BOOLEAN/STRING Setting

Shailesh351 opened this issue · comments

public async getValueById(id: string): Promise<any> {
        const set = await this.settingBridge.getOneById(id, this.appId);

        if (typeof set === 'undefined') {
            throw new Error(`No Server Setting found, or it is unaccessible, by the id of "${id}".`);
        }

        return set.value || set.packageValue;
    }

This is how getValueById function gets value.

The issue is with the BOOLEAN settings. When packageValue (default value) is set to true and value (current value) if false,
It returns true because of OR ||.

Similar issue when setting value is '' for STRING Setting.

Expected behaviour

It should return false in the above case.

Possible Solution

public async getValueById(id: string): Promise < any > {
	const set = await this.settingBridge.getOneById(id, this.appId);

	if (typeof set === 'undefined') {
		throw new Error(`No Server Setting found, or it is unaccessible, by the id of "${id}".`);
	}

	if (set.value === undefined || set.value === null) {
		return set.packageValue;
	}

	return set.value;
}