Suspend all users apart from admin users for development copy

I’m looking at the steps to take to create a development copy of a busy Discourse site that can be used for training and testing by administrators but which won’t send any emails to non-administrators.

Am I correct in understanding that if all non-administrators are suspended then this would have the result I’m after?

And if this would work can anyone point me in the right direction for how to do this using the rails console?

You could do something like:

UPDATE users
SET silenced_till = '3019-02-01 13:00:00,'
SET suspended_till = '3019-02-01 13:00:00'
WHERE <your criteria>
RETURNING id, username_lower
2 Likes

There is a site setting that will disable mail for non admins. Another thing that I do is to just configure the site with invalid email credentials.

5 Likes

Thanks, I don’t have a huge amount of experience of using the rails console so I’m afraid I didn’t get past that first line:

[1] pry(main)> UPDATE users
NameError: undefined local variable or method `users' for main:Object
Did you mean?  user_mask
from (pry):1:in `__pry__'

Any suggestions?

For the criteria would it be something like this to only edit non-admins?

WHERE not(admin: true)

Yes, I have used the option to disable all outgoing emails in the past but the plan for this site is to have a test version of a site that can send out and receive emails but only admins can use it.

That is a SQL statement, you need to use psql. If you are not familiar with SQL, please exercise caution as you can really hose your setup.

Your steps would be something like:

cd /var/discourse
./launcher enter app
sudo postgres
psql
\c discourse
now execute SQL
\q when done
1 Like

Perhaps you missed that there is a new “staff only” setting for “disable emails”.

1 Like

Cheers, I know my way around MySQL…

FWIW that should be:

su - postgres

Or:

sudo -iu postgres

So I worked out how to select admin users:

discourse=# SELECT FROM users WHERE admin='t';
--
(6 rows)

And then tried:

discourse=# UPDATE users
discourse-# SET silenced_till = '3019-02-01 13:00:00,'
discourse-# SET suspended_till = '3019-02-01 13:00:00'
discourse-# WHERE admin='f'
discourse-# RETURNING id, username_lower;
ERROR:  syntax error at or near "SET"
LINE 3: SET suspended_till = '3019-02-01 13:00:00'
        ^

However this works:

discourse=# UPDATE users
discourse-# SET silenced_till = '3019-02-01 13:00:00', suspended_till = '3019-02-01 13:00:00'
discourse-# WHERE admin='f'
discourse-# RETURNING id, username_lower;

Thanks for your help with this @slackmoehrle :slight_smile: .

Ahh! Yes, I had missed that, this is perfect, thanks.

1 Like

To sum up the above in case anyone else ever wants to do this, to disable all non-admin users:

./launcher enter app
su - postgres
psql
\c discourse
UPDATE users SET silenced_till='3019-02-01 13:00:00', suspended_till='3019-02-01 13:00:00' WHERE admin='f';
\q
exit
exit
1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.