Rocket.Chat.Apps-engine icon indicating copy to clipboard operation
Rocket.Chat.Apps-engine copied to clipboard

Default BOOLEAN packageValue isn't setting value on first install

Open wreiske opened this issue 5 years ago • 1 comments

I noticed that you have to define value:true otherwise the checkbox will show checked, but there won't be a true value in the settings object.

This is when you first install a new app.

await configuration.settings.provideSetting({
      id: 'test_boolean',
      type: SettingType.BOOLEAN,
      packageValue: true,
      required: true,
      public: false,
      i18nLabel: 'test_boolean',
      i18nDescription: 'test_boolean_description',
    });
const settings = await read.getEnvironmentReader().getSettings();
const testBoolean = await settings.getById('test_boolean');

testBoolean does not contain a "value". So if(testBoolean.value) will return false.


Now,

await configuration.settings.provideSetting({
      id: 'test_boolean',
      type: SettingType.BOOLEAN,
      packageValue: true,
      required: true,
      value: true,
      public: false,
      i18nLabel: 'test_boolean',
      i18nDescription: 'test_boolean_description',
    });
const settings = await read.getEnvironmentReader().getSettings();
const testBoolean = await settings.getById('test_boolean');

testBoolean contains a "value". So if(testBoolean.value) will return true.

wreiske avatar Nov 23 '19 05:11 wreiske

Hi, @wreiske!

Thank you for detailedly pointing this issue. The behavior you described is expected since the packageValue attribute is used as the settings object's value if value is not defined (as described here in our documentation). Thus, it is possible to capture the settings object's value with the same behavior as you have noticed in your checkbox using the getValueById method instead of the getById method (followed by the direct access to the value attribute, as you have done). Hence, the checkbox would show checked because it'd use the packageValue attribute when value is undefined.

May this issue be closed?

matheusbsilva137 avatar Jan 14 '21 17:01 matheusbsilva137