How to disable access without emailing user

AI-generated summary

Disabling Access without Emailing User

The original poster, ryantm, is looking for a way to disable access to specific users on their employee forum without sending them an email notification. Currently, when an account is suspended, an email is sent to the user, even if the “Email message” field is left blank.

ryantm provided a workaround using the Rails console, but was hoping to find a solution through the Web UI. Richie suggested editing the user’s email to a non-existent domain before suspending them, but ryantm noted that this would require verification.

omarfilip mentioned that emailing used to be optional, but testing revealed that an email is still sent even when the message field is blank. ryantm created a pull request to fix this issue, which has since been merged by eviltrout.

Hi.

My forum is on version 2.7.0.beta6.

I maintain an employee forum where we want to disable access to specific users without emailing them. The way we have been disabling access is by suspending their account. When we suspend their account the user receives an email containing the reason for suspension. We’d really rather not bother the person with an email.

I’ve tried first deactivating a test account before suspending it, but an email is still sent.

Note: when I suspend a user, I am not filing in the “Email message” field with anything.

Is there a way I can disable access to Discourse without emailing the user?

- Ryan

Here’s some code that will do it at the rails console:

./launcher enter app 
rails c
username = "user-to-suspend-username"
admin_username = "admin-username"
reason = "suspend reason"
till = Time.at(33174889200)
u = User.find_by_username(username)
puts "couldn't find user named #{username}" unless u
if u and !u.suspended?
  u.suspended_till = till
  u.suspended_at = DateTime.now

  User.transaction do
    u.save!
    admin = User.find_by_username(admin_username)
    StaffActionLogger.new(admin).log_user_suspend(
      u,
      reason
    )
  end
  u.logged_out
end

If the person is no longer an employee, how are they still able to access their corporate email account? :thinking:

You could always edit the user first, change their email to no@email.some.random.nonexistent.domain

And then suspend them.

It uses personal emails.

I know how to do that at the Rails console, but is there a way to do that in Web UI? I see the option to edit their email in their profile, but it looks like it requires the email to be verified before it takes effect.

Wasn’t the emailing optional before?

All the documentation makes it look that way! But, it sends an email even if you leave the message part blank.

Will send an email with this message when present

Optionally, provide more information about the suspension and it will be emailed to the user

You’re right, I just tested that. And deactivating the user’s email doesn’t prevent the email from going out either. I could have sworn that no email was sent unless the optional message was added in past versions.

I’ve started a pull request to bring behavior in line with documentation:

https://github.com/discourse/discourse/pull/12666

This fix has been merged by @eviltrout :tada: