FIX: do not assign to same when already assigned
This commit is contained in:
parent
cd6f61683e
commit
a2e7fc4cac
|
@ -62,6 +62,10 @@ module DiscourseAssign
|
|||
|
||||
raise Discourse::NotFound unless assign_to
|
||||
|
||||
if topic.custom_fields && topic.custom_fields['assigned_to_id'] == assign_to.id.to_s
|
||||
return render json: { failed: 'Already assigned to the user' }, status: 400
|
||||
end
|
||||
|
||||
assigner = TopicAssigner.new(topic, current_user)
|
||||
|
||||
# perhaps?
|
||||
|
|
|
@ -0,0 +1,39 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.describe DiscourseAssign::AssignController do
|
||||
|
||||
let(:user) { Fabricate(:admin) }
|
||||
let(:post) { Fabricate(:post) }
|
||||
let(:user2) { Fabricate(:active_user) }
|
||||
|
||||
context 'assign' do
|
||||
|
||||
it 'assigns topic to a user' do
|
||||
sign_in(user)
|
||||
|
||||
put '/assign/assign', params: {
|
||||
topic_id: post.topic_id, username: user2.username
|
||||
}
|
||||
|
||||
expect(response.status).to eq(200)
|
||||
end
|
||||
|
||||
it 'fails to assign topic to the user if its already assigned to the same user' do
|
||||
sign_in(user)
|
||||
|
||||
put '/assign/assign.json', params: {
|
||||
topic_id: post.topic_id, username: user2.username
|
||||
}
|
||||
|
||||
expect(response.status).to eq(200)
|
||||
|
||||
put '/assign/assign.json', params: {
|
||||
topic_id: post.topic_id, username: user2.username
|
||||
}
|
||||
|
||||
expect(response.status).to eq(400)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
Loading…
Reference in New Issue