How to change a site setting via the Console

So while investigating
https://meta.discourse.org/t/logout-menu-item/32731/21?u=cpradio

I enabled SSO, then logged out (yikes!), and now I can’t log back in, as it wants me to use SSO to do so :frowning:

How can I disable the enable_sso site setting so I can get back into my local environment?

in your /discourse

bundle exec rails c
SiteSetting.enable_sso = false

:wink:

3 Likes

Ah, I did it a different route, but yours is easier. :smile:

I ended up doing

s = SiteSetting.find_by(name: 'enable_sso')  
s.value = 'f'  
s.save!  

I was just about to post that here and saw your response. Thanks! Now I can at least constantly get back to a good state between tests :smile: (or maybe I should setup an actual SSO…)

2 Likes

For future reference, visit /u/admin-login

3 Likes

Yeah just use /users/admin-login

I did

SiteSetting.enable_sso = false

But I ended up with this login form:

How can I log-in please?

Looks like you have no login methods available.

Do SiteSetting.enable_local_logins = true .

2 Likes

Yes!

Thank you very much!

After running : “bundle exec rails c”
I’m getting an error : “Could not locate Gemfile”

How to fix it?

Are you running this from inside your container (./launcher enter app)?

2 Likes

No I wasn’t :blush: since its wasn’t mentioned. Sorry a lot of things to learn yet :alien:

1 Like

So I did these commands:

cd /var/discourse
./launcher enter app

then
bundle exec rails c

and I’ve got the following errors:

URGENT: FATAL: Peer authentication failed for user “discourse”
Failed to initialize site default
/var/www/discourse/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.7.1/lib/active_record/connection_adapters/postgresql_adapter.rb:651:in initialize': FATAL: Peer authentication failed for user "discourse" (PG::ConnectionBad) from /var/www/discourse/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.7.1/lib/active_record/connection_adapters/postgresql_adapter.rb:651:innew’
from /var/www/discourse/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.7.1/lib/active_record/connection_adapters/postgresql_adapter.rb:651:in `connect’


… many folders list

I did ./launcher rebuild app and tried again. The same errors!


After I’d pissed of these problems. I did restored my droplet from a previous snapshot I had and started from scratch.

I did enabled FORCE_HTTPS without a problem.

Can we change the discourse language in bundle exec rails c console?
How can we change the language of our site to english?

changing language can be done in database in site_settings column.
just search the current language and replace new language:
below code change language from Farsi to english:
UPDATE site_setting SET value = 'en' where value = 'fa_IR'
I have typed this code after typing : rails db

1 Like

I had a problem with the force_https option (couldn’t login after enabling it). I fixed it by doing:

cd /var/discourse/
./launcher enter app
rails c
[1] pry(main)> SiteSetting.force_https = false
=> false
3 Likes

I believe a setting regex needs updating, and want to test with a new value, but when I go SiteSetting.key = value it blocks me because of the regex. Is there a way to force update a value even if it doesn’t match the setting’s regex?

Edit: this worked, though be very careful!

cd /var/discourse/
./launcher enter app
rails db
discourse=> update site_settings set value='newvalue' where name='settingname';

And then exit out, and restart the app:

./launcher stop app
./launcher start app

./launcher restart app is slightly faster to restart the app :wink:

2 Likes

Just in case, here’s a shell script oneliner not requiring to restart Discourse: bundle exec rails runner "SiteSetting.set('enable_sso', false)". It works just like it would from Discourse Admin UI.

5 Likes