Suspend API Not Working


(Geoffrey Challen) #1

This is related to API not returning suspended fields properly. 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.


(Régis Hanol) #2

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:.


(Geoffrey Challen) #3

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.


(Andy Logan) #4

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.


(Joshua Rosenfeld) #5

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


(Geoffrey Challen) #6

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.


#7

@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"
}

(Joshua Rosenfeld) #8

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.


(Robin Ward) #9

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


(Mittineague) #10

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)