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

(Christopher Kampmeier) #1

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:
          - 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'"' "'


(Sam Saffron) #2

This should work. perhaps

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

(Christopher Kampmeier) #3

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.

(Sam Saffron) #4

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.

(Arpit Jalan) #5

Okay, fixed via:

(Christopher Kampmeier) #6

Awesome. That fixed the issue I originally reported.

(Régis Hanol) #7

(Sam Saffron) #8

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

(Arpit Jalan) #9

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.