Suspend API Not Working

This is related to API not returning suspended fields properly - #6 by eviltrout. Tagging @eviltrout since they seem to own this codebase.

Now it seems the issue is that the suspend API is not working properly. Here’s the code that we’ve been using for several months:

client.put('admin/users/' + user.id + '/suspend?' + 
  queryString.stringify({
    api_username: passwords.discourse.username,
    api_key: passwords.discourse.key
  }), {
    duration: 99999,
    reason: 'No longer in CS 125.'
  }, function (err, res, body) {
    should.not.exist(err);
    res.statusCode.should.equal(200);
    return callback();
});   

Again, this worked fairly recently. But now when we run it: (a) the suspended count shown on the user page goes up by one, but (b) the user is actually not suspended correctly. They don’t show as suspended in the UI, and return as active the next time we pull the users list.

Does it work when you suspend the user using the UI?

If it does, then look at the request made when you click the button.
If it doesn’t, then it’s a :bug:.

I understand that you can reverse the API. But this call is documented. So either the documentation is wrong, or it’s not working as expected.

Again: this worked quite recently.

1 Like

It seems like there was an update to the suspend dialog. I can now pull down an option that says forever vs. the 9999 days use, as well as an email reason for the suspension. I don’t remember seeing that before, but I could be wrong as I only suspend people when they leave the company (so far). I would expect that the API would need to change, probably the doc hasn’t caught up to it.

Suspend was improved recently to provide more options, so it is very possible that the documentation is out of date.

5 Likes

OK, thanks for all the help. It threw me off a bit that the new suspend UI is using a form, rather than posting JSON, but posting the form contents seems to work fine.

2 Likes

@jomaxro is it able to have the ‘forever’ option via api as well?

http://docs.discourse.org/#tag/Admin%2Fpaths%2F~1admin~1users~1{id}~1suspend%2Fput

what would we need to put into the request?

{
  "suspend_until": "string",
  "reason": "string"
}

I would assume it’s possible, but I’m not an API expert. @eviltrout did the recent suspend improvements, he should be able to confirm.

To do it forever, just pass a date about 1000 years into the future. If it’s that far away we display “Forever”.

4 Likes

I like to think medical advances will someday lengthen lifespan. Pessimist that I am, I don’t hold hope that I’ll see a day of the year 2291 (five nines, 99999 days)

1 Like

Is there a specific format for the date?

Seconds since Jan 1st? yyyyMMDDhhssmm?

Do we assume its UTC time?

I am able to suspend a user, but it seems to always be in the past. I am assuming the date I am trying to pass is wrong.

1 Like

You can use just yyyy-MM-DD format for suspend_until.

So ‘2018-07-22’ would suspend them for one month (from today).

If you need something more granular (hours and minutes) you can use this format:

2018-07-22+08:00-06:00
4 Likes