Scripted setting of default_trust_level not working: results in "1" vs expected setting

We script the installation of Discourse in support of a series of internal community sites in which we want all users to default to trust level 3. However, the following approach doesn’t work for the default_trust_level setting. We set many other site settings in this manner successfully including default_invitee_trust_level, but using this approach results in a “1” for the default_trust_level.

We’re on: v1.6.0.beta2 +102

    - exec:
        cmd:
          - su discourse -c 'RAILS_ENV=production /var/www/discourse/bin/rails r "SiteSetting.default_trust_level='"'3'"' "'
          - su discourse -c 'RAILS_ENV=production /var/www/discourse/bin/rails r "SiteSetting.default_invitee_trust_level='"'3'"' "'

Result:

This should work. perhaps

 - su discourse -c 'RAILS_ENV=production /var/www/discourse/bin/rails r "SiteSetting.default_trust_level=3"'
1 Like

Thanks for the streamlining tip, but that wasn’t the cause of the issue. The default is still stuck at 1.

I was skeptical about the tip making a difference given that we have many other examples that are successfully using the overly verbose syntax. (Although the quoting is needed for strings that have spaces).

I might dig into the code to see if I can locate the cause of the issue.

Ahh perhaps this is the bootstrapping mode @techAPJ added?

Perhaps set: bootstrap mode min users to 0 as well.

@techAPJ bootstrap mode should not be amending any settings that are not in default state.

3 Likes

Okay, fixed via:

https://github.com/discourse/discourse/commit/9427e0c732195a5d74a54020b5c3b3259c6db10a

3 Likes

Awesome. That fixed the issue I originally reported.

3 Likes

Just to confirm, if someone sets it to 1, will it be reverted to 0 when bootstrap kicks out

1 Like

Yes, when the bootstrap kicks out it will change the setting back to default (0) only if the value matches bootstrap setting value (1). Here is the relevant logic:

SiteSetting.set_and_log('default_trust_level', TrustLevel[0]) if SiteSetting.send('default_trust_level') == TrustLevel[1]
SiteSetting.set_and_log('default_email_digest_frequency', 10080) if SiteSetting.send('default_email_digest_frequency') == 1440        

If the user changed default_trust_level to 3 then it will not be reverted to original value.

3 Likes