setup backend for reply preview for rce
refs VICE-1970 flag=react_discussions_post Test Plan: -specs should pass Change-Id: I475030bfd11ce31ccd435d32bb48b4cef80742e2 Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/272026 Tested-by: Service Cloud Jenkins <svc.cloudjenkins@instructure.com> Reviewed-by: Rob Orton <rob@instructure.com> QA-Review: Rob Orton <rob@instructure.com> Product-Review: Rob Orton <rob@instructure.com>
This commit is contained in:
parent
b5c11dcba7
commit
bfa5ae8d24
|
@ -25,6 +25,7 @@ class Mutations::CreateDiscussionEntry < Mutations::BaseMutation
|
|||
argument :message, String, required: true
|
||||
argument :parent_entry_id, ID, required: false, prepare: GraphQLHelpers.relay_or_legacy_id_prepare_func('DiscussionEntry')
|
||||
argument :file_id, ID, required: false, prepare: GraphQLHelpers.relay_or_legacy_id_prepare_func('Attachment')
|
||||
argument :include_reply_preview, Boolean, required: false
|
||||
|
||||
field :discussion_entry, Types::DiscussionEntryType, null: true
|
||||
def resolve(input:)
|
||||
|
@ -37,6 +38,7 @@ class Mutations::CreateDiscussionEntry < Mutations::BaseMutation
|
|||
if input[:parent_entry_id]
|
||||
parent_entry = topic.discussion_entries.find(input[:parent_entry_id])
|
||||
entry.parent_entry = parent_entry
|
||||
entry.include_reply_preview = input[:include_reply_preview].present? if parent_entry.root_entry_id.present?
|
||||
end
|
||||
|
||||
if input[:file_id]
|
||||
|
@ -45,6 +47,7 @@ class Mutations::CreateDiscussionEntry < Mutations::BaseMutation
|
|||
|
||||
entry.attachment = attachment
|
||||
end
|
||||
|
||||
entry.save!
|
||||
|
||||
{discussion_entry: entry}
|
||||
|
|
|
@ -25,6 +25,7 @@ class Mutations::UpdateDiscussionEntry < Mutations::BaseMutation
|
|||
argument :message, String, required: false
|
||||
argument :remove_attachment, Boolean, required: false
|
||||
argument :file_id, ID, required: false, prepare: GraphQLHelpers.relay_or_legacy_id_prepare_func('Attachment')
|
||||
argument :include_reply_preview, Boolean, required: false
|
||||
|
||||
field :discussion_entry, Types::DiscussionEntryType, null: true
|
||||
def resolve(input:)
|
||||
|
@ -40,6 +41,12 @@ class Mutations::UpdateDiscussionEntry < Mutations::BaseMutation
|
|||
entry.attachment_id = nil if input[:remove_attachment]
|
||||
end
|
||||
|
||||
unless input[:include_reply_preview].nil?
|
||||
if entry.parent_entry && entry.parent_entry.id != entry.root_entry_id
|
||||
entry.include_reply_preview = input[:include_reply_preview]
|
||||
end
|
||||
end
|
||||
|
||||
unless input[:file_id].nil?
|
||||
attachment = Attachment.find(input[:file_id])
|
||||
raise ActiveRecord::RecordNotFound unless attachment.user == current_user
|
||||
|
|
|
@ -49,7 +49,6 @@ class DiscussionEntry < ActiveRecord::Base
|
|||
before_create :infer_root_entry_id
|
||||
before_create :populate_legacy
|
||||
before_create :set_root_account_id
|
||||
before_save :process_reply_preview
|
||||
after_save :update_discussion
|
||||
after_save :context_module_action_later
|
||||
after_create :create_participants
|
||||
|
@ -87,18 +86,6 @@ class DiscussionEntry < ActiveRecord::Base
|
|||
User.where("EXISTS (?)", mentions.distinct.select('user_id')).to_a
|
||||
end
|
||||
|
||||
def process_reply_preview
|
||||
reply_preview = Nokogiri::HTML.fragment(message).search('[data-discussion-reply-preview]')
|
||||
if reply_preview.present?
|
||||
self.include_reply_preview = true
|
||||
new_message = Nokogiri::HTML.fragment(message)
|
||||
new_message.search('[data-discussion-reply-preview]').remove
|
||||
self.message = new_message.to_html
|
||||
else
|
||||
self.include_reply_preview = false
|
||||
end
|
||||
end
|
||||
|
||||
def course_broadcast_data
|
||||
discussion_topic.context&.broadcast_data
|
||||
end
|
||||
|
|
|
@ -32,7 +32,8 @@ RSpec.describe Mutations::CreateDiscussionEntry do
|
|||
discussion_topic_id: nil,
|
||||
message: nil,
|
||||
parent_entry_id: nil,
|
||||
file_id: nil
|
||||
file_id: nil,
|
||||
include_reply_preview: nil
|
||||
)
|
||||
<<~GQL
|
||||
mutation {
|
||||
|
@ -41,7 +42,8 @@ RSpec.describe Mutations::CreateDiscussionEntry do
|
|||
message: "#{message}"
|
||||
#{"parentEntryId: #{parent_entry_id}" unless parent_entry_id.nil?}
|
||||
#{"fileId: #{file_id}" unless file_id.nil?}
|
||||
}) {
|
||||
#{"includeReplyPreview: #{include_reply_preview}" unless include_reply_preview.nil?}
|
||||
}) {
|
||||
discussionEntry {
|
||||
_id
|
||||
message
|
||||
|
@ -106,6 +108,7 @@ RSpec.describe Mutations::CreateDiscussionEntry do
|
|||
expect(result.dig('data', 'createDiscussionEntry', 'discussionEntry', 'message')).to eq entry.message
|
||||
expect(result.dig('data', 'createDiscussionEntry', 'discussionEntry', 'parent', '_id')).to eq parent_entry.id.to_s
|
||||
expect(entry.root_entry_id).to eq root_entry.id
|
||||
expect(entry.include_reply_preview?).to be false
|
||||
end
|
||||
|
||||
it 'adds an attachment when creating a discussion entry' do
|
||||
|
@ -120,6 +123,46 @@ RSpec.describe Mutations::CreateDiscussionEntry do
|
|||
expect(entry.reload.attachment_id).to eq attachment.id
|
||||
end
|
||||
|
||||
context 'include reply preview' do
|
||||
it 'cannot be a root entry' do
|
||||
result = run_mutation(discussion_topic_id: @topic.id, message: 'Howdy Hey', include_reply_preview: true)
|
||||
expect(result.dig('errors')).to be nil
|
||||
expect(result.dig('data', 'createDiscussionEntry', 'errors')).to be nil
|
||||
|
||||
entry = @topic.discussion_entries.last
|
||||
expect(entry.include_reply_preview?).to be false
|
||||
end
|
||||
|
||||
it 'cannot be a reply to a root entry' do
|
||||
root_entry = @topic.discussion_entries.create!(message: 'parent entry', user: @teacher, discussion_topic: @topic)
|
||||
result = run_mutation(discussion_topic_id: @topic.id, message: 'Howdy Hey', include_reply_preview: true, parent_entry_id: root_entry.id)
|
||||
|
||||
expect(result.dig('errors')).to be nil
|
||||
expect(result.dig('data', 'createDiscussionEntry', 'errors')).to be nil
|
||||
|
||||
entry = @topic.discussion_entries.last
|
||||
expect(entry.include_reply_preview?).to be false
|
||||
end
|
||||
|
||||
it 'does set on reply to a child reply' do
|
||||
root_entry = @topic.discussion_entries.create!(message: 'root entry', user: @teacher, discussion_topic: @topic)
|
||||
parent_entry = @topic.discussion_entries.create!(message: 'parent entry', user: @teacher, discussion_topic: @topic, parent_entry: root_entry)
|
||||
result = run_mutation(discussion_topic_id: @topic.id, message: 'child entry', parent_entry_id: parent_entry.id, include_reply_preview: true)
|
||||
|
||||
entry = @topic.discussion_entries.last
|
||||
expect(entry.include_reply_preview?).to be true
|
||||
end
|
||||
|
||||
it 'allows creating with include reply preview as false' do
|
||||
root_entry = @topic.discussion_entries.create!(message: 'root entry', user: @teacher, discussion_topic: @topic)
|
||||
parent_entry = @topic.discussion_entries.create!(message: 'parent entry', user: @teacher, discussion_topic: @topic, parent_entry: root_entry)
|
||||
result = run_mutation(discussion_topic_id: @topic.id, message: 'child entry', parent_entry_id: parent_entry.id, include_reply_preview: false)
|
||||
|
||||
entry = @topic.discussion_entries.last
|
||||
expect(entry.include_reply_preview?).to be false
|
||||
end
|
||||
end
|
||||
|
||||
context 'errors' do
|
||||
it 'if given a bad discussion topic id' do
|
||||
result = run_mutation(discussion_topic_id: @topic.id + 1337, message: 'this should fail')
|
||||
|
|
|
@ -28,13 +28,15 @@ RSpec.describe Mutations::UpdateDiscussionEntry do
|
|||
discussion_topic_model({context: @course})
|
||||
@attachment = attachment_with_context(@student)
|
||||
@entry = @topic.discussion_entries.create!(message: 'Howdy', user: @student, attachment: @attachment)
|
||||
@topic.update!(discussion_type: 'threaded')
|
||||
end
|
||||
|
||||
def mutation_str(
|
||||
discussion_entry_id: nil,
|
||||
message: nil,
|
||||
remove_attachment: nil,
|
||||
file_id: nil
|
||||
file_id: nil,
|
||||
include_reply_preview: nil
|
||||
)
|
||||
<<~GQL
|
||||
mutation {
|
||||
|
@ -43,6 +45,7 @@ RSpec.describe Mutations::UpdateDiscussionEntry do
|
|||
#{"message: \"#{message}\"" unless message.nil?}
|
||||
#{"removeAttachment: #{remove_attachment}" unless remove_attachment.nil?}
|
||||
#{"fileId: #{file_id}" unless file_id.nil?}
|
||||
#{"includeReplyPreview: #{include_reply_preview}" unless include_reply_preview.nil?}
|
||||
}) {
|
||||
discussionEntry {
|
||||
_id
|
||||
|
@ -97,6 +100,44 @@ RSpec.describe Mutations::UpdateDiscussionEntry do
|
|||
expect(@entry.reload.attachment_id).to eq attachment.id
|
||||
end
|
||||
|
||||
context 'include reply preview' do
|
||||
it 'cannot be true on a root entry' do
|
||||
result = run_mutation(discussion_entry_id: @entry.id, include_reply_preview: true)
|
||||
expect(result.dig('errors')).to be nil
|
||||
expect(result.dig('data', 'updateDiscussionEntry', 'errors')).to be nil
|
||||
expect(@entry.reload.include_reply_preview).to be false
|
||||
end
|
||||
|
||||
it 'cannot be true on a reply to a root entry' do
|
||||
parent_entry = @topic.discussion_entries.create!(message: 'I am the parent reply', user: @student, attachment: @attachment)
|
||||
entry = @topic.discussion_entries.create!(message: 'I am the child reply', user: @student, attachment: @attachment, parent_id: parent_entry.id, include_reply_preview: false, root_entry_id: parent_entry.id)
|
||||
result = run_mutation(discussion_entry_id: entry.id, include_reply_preview: true)
|
||||
expect(result.dig('errors')).to be nil
|
||||
expect(result.dig('data', 'updateDiscussionEntry', 'errors')).to be nil
|
||||
expect(entry.reload.include_reply_preview).to be false
|
||||
end
|
||||
|
||||
it 'does set on reply to a child reply' do
|
||||
parent_entry = @topic.discussion_entries.create!(message: 'I am the parent reply', user: @student, attachment: @attachment)
|
||||
child_reply = @topic.discussion_entries.create!(message: 'I am the child reply', user: @student, attachment: @attachment, parent_id: parent_entry.id)
|
||||
entry = @topic.discussion_entries.create!(message: 'Howdy', user: @student, attachment: @attachment, parent_id: child_reply.id, include_reply_preview: false)
|
||||
result = run_mutation(discussion_entry_id: entry.id, include_reply_preview: true)
|
||||
expect(result.dig('errors')).to be nil
|
||||
expect(result.dig('data', 'updateDiscussion
|
||||
Entry', 'errors')).to be nil
|
||||
expect(entry.reload.include_reply_preview).to be true
|
||||
end
|
||||
|
||||
it 'allows removing reply preview' do
|
||||
parent_entry = @topic.discussion_entries.create!(message: 'I am the parent reply', user: @student, attachment: @attachment)
|
||||
child_reply = @topic.discussion_entries.create!(message: 'I am the child reply', user: @student, attachment: @attachment, parent_id: parent_entry.id)
|
||||
entry = @topic.discussion_entries.create!(message: 'Howdy', user: @student, attachment: @attachment, parent_id: child_reply.id, include_reply_preview: true)
|
||||
expect(entry.reload.include_reply_preview).to be true
|
||||
result = run_mutation(discussion_entry_id: entry.id, include_reply_preview: false)
|
||||
expect(entry.reload.include_reply_preview).to be false
|
||||
end
|
||||
end
|
||||
|
||||
context 'errors' do
|
||||
it 'if given a bad discussion entry id' do
|
||||
result = run_mutation(discussion_entry_id: @entry.id + 1337, message: 'should fail')
|
||||
|
|
|
@ -150,11 +150,6 @@ describe DiscussionEntry do
|
|||
|
||||
let(:student) { student_in_course(active_all: true) }
|
||||
|
||||
it "should mark include_reply_preview as true" do
|
||||
expect(@entry.include_reply_preview).to be true
|
||||
expect(@entry.message).to eql("<p>only this should stay</p>")
|
||||
end
|
||||
|
||||
it "should mark include_reply_preview as false" do
|
||||
@entry.update({message: "<p>not a reply preview anymore</p>"})
|
||||
@entry.save!
|
||||
|
|
Loading…
Reference in New Issue