Skip to content

Commit

Permalink
FIX: Suspend API to require suspend_until and reason params
Browse files Browse the repository at this point in the history
These fields are required when using the UI and if `suspend_until`
params isn't used the user never is actually suspended so we should
require these fields when suspending a user.
  • Loading branch information
oblakeerickson committed Aug 27, 2020
1 parent 95179a5 commit 02833e1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
2 changes: 2 additions & 0 deletions app/controllers/admin/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ def penalty_history

def suspend
guardian.ensure_can_suspend!(@user)
params.require([:suspend_until, :reason])

@user.suspended_till = params[:suspend_until]
@user.suspended_at = DateTime.now

Expand Down
16 changes: 16 additions & 0 deletions spec/requests/admin/users_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,22 @@
expect(log.details).to match(/because I said so/)
end

it "requires suspend_until and reason" do
expect(user).not_to be_suspended
put "/admin/users/#{user.id}/suspend.json", params: {}
expect(response.status).to eq(400)
user.reload
expect(user).not_to be_suspended

expect(user).not_to be_suspended
put "/admin/users/#{user.id}/suspend.json", params: {
suspend_until: 5.hours.from_now
}
expect(response.status).to eq(400)
user.reload
expect(user).not_to be_suspended
end

context "with an associated post" do
it "can have an associated post" do
put "/admin/users/#{user.id}/suspend.json", params: suspend_params
Expand Down

0 comments on commit 02833e1

Please sign in to comment.