mirror of
https://github.com/discourse/discourse.git
synced 2025-09-10 08:38:11 +08:00
FEATURE: Topic slow mode. (#10904)
Adds a new slow mode for topics that are heating up. Users will have to wait for a period of time before being able to post again. We store this interval inside the topics table and track the last time a user posted using the last_posted_at datetime in the TopicUser relation.
This commit is contained in:
parent
4669e60ce5
commit
21c53ed249
27 changed files with 460 additions and 6 deletions
|
@ -3047,6 +3047,58 @@ RSpec.describe TopicsController do
|
|||
end
|
||||
end
|
||||
|
||||
describe '#set_slow_mode' do
|
||||
context 'when not logged in' do
|
||||
it 'returns a forbidden response' do
|
||||
put "/t/#{topic.id}/slow_mode.json", params: {
|
||||
seconds: '3600'
|
||||
}
|
||||
|
||||
expect(response.status).to eq(403)
|
||||
end
|
||||
end
|
||||
|
||||
context 'logged in as an admin' do
|
||||
it 'allows admins to set the slow mode interval' do
|
||||
sign_in(admin)
|
||||
|
||||
put "/t/#{topic.id}/slow_mode.json", params: {
|
||||
seconds: '3600'
|
||||
}
|
||||
|
||||
topic.reload
|
||||
expect(response.status).to eq(200)
|
||||
expect(topic.slow_mode_seconds).to eq(3600)
|
||||
end
|
||||
end
|
||||
|
||||
context 'logged in as a regular user' do
|
||||
it 'does nothing if the user is not TL4' do
|
||||
user.update!(trust_level: TrustLevel[3])
|
||||
sign_in(user)
|
||||
|
||||
put "/t/#{topic.id}/slow_mode.json", params: {
|
||||
seconds: '3600'
|
||||
}
|
||||
|
||||
expect(response.status).to eq(403)
|
||||
end
|
||||
|
||||
it 'allows TL4 users to set the slow mode interval' do
|
||||
user.update!(trust_level: TrustLevel[4])
|
||||
sign_in(user)
|
||||
|
||||
put "/t/#{topic.id}/slow_mode.json", params: {
|
||||
seconds: '3600'
|
||||
}
|
||||
|
||||
topic.reload
|
||||
expect(response.status).to eq(200)
|
||||
expect(topic.slow_mode_seconds).to eq(3600)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#invite' do
|
||||
describe 'when not logged in' do
|
||||
it "should return the right response" do
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue