# 暂停除管理员用户外的所有用户以进行开发副本操作

**URL:** https://meta.discourse.org/t/suspend-all-users-apart-from-admin-users-for-development-copy/113317
**Category:** Support
**Created:** [2019年四月3日 07:58 UTC](https://meta.discourse.org/t/suspend-all-users-apart-from-admin-users-for-development-copy/113317 "2019-04-03T07:58:17Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![chrisc](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/chrisc/32/119982_2.png) [@chrisc](https://meta.discourse.org/u/chrisc)
#### Post date: [2019年四月3日 07:58 UTC](https://meta.discourse.org/t/suspend-all-users-apart-from-admin-users-for-development-copy/113317/1 "2019-04-03T07:58:17Z")

</div>

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](https://meta.discourse.org/t/description-of-various-user-states-in-discourse/35171) 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?

---

<div class="post-metadata">

### Author: ![slackmoehrle](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/slackmoehrle/32/82215_2.png) [@slackmoehrle](https://meta.discourse.org/u/slackmoehrle)
#### Post date: [2019年四月3日 09:31 UTC](https://meta.discourse.org/t/suspend-all-users-apart-from-admin-users-for-development-copy/113317/2 "2019-04-03T09:31:54Z")

</div>

You could do something like:

```sql
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

```

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [2019年四月3日 13:21 UTC](https://meta.discourse.org/t/suspend-all-users-apart-from-admin-users-for-development-copy/113317/3 "2019-04-03T13:21:30Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![chrisc](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/chrisc/32/119982_2.png) [@chrisc](https://meta.discourse.org/u/chrisc)
#### Post date: [2019年四月4日 11:03 UTC](https://meta.discourse.org/t/suspend-all-users-apart-from-admin-users-for-development-copy/113317/4 "2019-04-04T11:03:03Z")

</div>

> [@slackmoehrle](#):
>
> You could do something like:
> 
> ```plaintext
> UPDATE users
> 
> ```

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:

```plaintext
[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?

```plaintext
WHERE not(admin: true)

```

> [@pfaffman](#):
>
> 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.

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.

---

<div class="post-metadata">

### Author: ![slackmoehrle](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/slackmoehrle/32/82215_2.png) [@slackmoehrle](https://meta.discourse.org/u/slackmoehrle)
#### Post date: [2019年四月4日 11:24 UTC](https://meta.discourse.org/t/suspend-all-users-apart-from-admin-users-for-development-copy/113317/5 "2019-04-04T11:24:25Z")

</div>

> [@chrisc](#):
>
> Thanks, I don’t have a huge amount of experience of using the rails console

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:

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

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [2019年四月4日 11:46 UTC](https://meta.discourse.org/t/suspend-all-users-apart-from-admin-users-for-development-copy/113317/6 "2019-04-04T11:46:35Z")

</div>

> [@chrisc](#):
>
> 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.

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

---

<div class="post-metadata">

### Author: ![chrisc](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/chrisc/32/119982_2.png) [@chrisc](https://meta.discourse.org/u/chrisc)
#### Post date: [2019年四月4日 11:51 UTC](https://meta.discourse.org/t/suspend-all-users-apart-from-admin-users-for-development-copy/113317/7 "2019-04-04T11:51:52Z")

</div>

Cheers, I know my way around MySQL…

> [@slackmoehrle](#):
>
> sudo postgres

FWIW that should be:

```bash
su - postgres

```

Or:

```bash
sudo -iu postgres

```

So I worked out how to select admin users:

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

```

And then tried:

```plaintext
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:

```plaintext
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 🙂 .

> [@pfaffman](#):
>
> Perhaps you missed that there is a new “staff only” setting for “disable emails”.

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

---

<div class="post-metadata">

### Author: ![chrisc](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/chrisc/32/119982_2.png) [@chrisc](https://meta.discourse.org/u/chrisc)
#### Post date: [2019年四月4日 13:48 UTC](https://meta.discourse.org/t/suspend-all-users-apart-from-admin-users-for-development-copy/113317/8 "2019-04-04T13:48:58Z")

</div>

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

```plaintext
./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

```

---

<div class="post-metadata">

### Author: ![system](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/system/32/443519_2.png) [@system](https://meta.discourse.org/u/system)
#### Post date: [2019年五月4日 13:49 UTC](https://meta.discourse.org/t/suspend-all-users-apart-from-admin-users-for-development-copy/113317/9 "2019-05-04T13:49:05Z")

</div>

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