Merge pull request #229 from paviliondev/fix_user_in_submissions
Ensure submission users are serialized properly
Dieser Commit ist enthalten in:
Commit
5eca78f172
4 geänderte Dateien mit 23 neuen und 9 gelöschten Zeilen
|
@ -10,7 +10,7 @@ class CustomWizard::SubmissionSerializer < ApplicationSerializer
|
||||||
end
|
end
|
||||||
|
|
||||||
def user
|
def user
|
||||||
::BasicUserSerializer.new(object.wizard.user).as_json
|
::BasicUserSerializer.new(object.wizard.user, root: false).as_json
|
||||||
end
|
end
|
||||||
|
|
||||||
def fields
|
def fields
|
||||||
|
|
|
@ -120,15 +120,21 @@ class CustomWizard::Submission
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.list(wizard, order_by: nil, page: nil)
|
def self.list(wizard, order_by: nil, page: nil)
|
||||||
|
list_actor_id = wizard.actor_id
|
||||||
|
list_user = wizard.user if wizard.user.present?
|
||||||
|
|
||||||
params = { plugin_name: "#{wizard.id}_#{KEY}" }
|
params = { plugin_name: "#{wizard.id}_#{KEY}" }
|
||||||
params[:key] = wizard.actor_id if wizard.actor_id
|
params[:key] = list_actor_id if list_actor_id
|
||||||
|
|
||||||
query = PluginStoreRow.where(params)
|
query = PluginStoreRow.where(params)
|
||||||
result = OpenStruct.new(submissions: [], total: nil)
|
result = OpenStruct.new(submissions: [], total: nil)
|
||||||
|
|
||||||
query.each do |record|
|
query.each do |record|
|
||||||
if (submission_data = ::JSON.parse(record.value)).any?
|
if (submission_data = ::JSON.parse(record.value)).any?
|
||||||
|
submission_user = list_user || User.find_by(id: record.key.to_i)
|
||||||
|
|
||||||
submission_data.each do |data|
|
submission_data.each do |data|
|
||||||
|
wizard.user = submission_user if submission_user.present?
|
||||||
result.submissions.push(new(wizard, data))
|
result.submissions.push(new(wizard, data))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
# name: discourse-custom-wizard
|
# name: discourse-custom-wizard
|
||||||
# about: Forms for Discourse. Better onboarding, structured posting, data enrichment, automated actions and much more.
|
# about: Forms for Discourse. Better onboarding, structured posting, data enrichment, automated actions and much more.
|
||||||
# version: 2.2.9
|
# version: 2.2.10
|
||||||
# authors: Angus McLeod, Faizaan Gagan, Robert Barrow, Keegan George, Kaitlin Maddever
|
# authors: Angus McLeod, Faizaan Gagan, Robert Barrow, Keegan George, Kaitlin Maddever
|
||||||
# url: https://github.com/paviliondev/discourse-custom-wizard
|
# url: https://github.com/paviliondev/discourse-custom-wizard
|
||||||
# contact_emails: development@pavilion.tech
|
# contact_emails: development@pavilion.tech
|
||||||
|
|
|
@ -3,7 +3,8 @@
|
||||||
require_relative '../../plugin_helper'
|
require_relative '../../plugin_helper'
|
||||||
|
|
||||||
describe CustomWizard::SubmissionSerializer do
|
describe CustomWizard::SubmissionSerializer do
|
||||||
fab!(:user) { Fabricate(:user) }
|
fab!(:user1) { Fabricate(:user) }
|
||||||
|
fab!(:user2) { Fabricate(:user) }
|
||||||
|
|
||||||
let(:template_json) {
|
let(:template_json) {
|
||||||
JSON.parse(File.open(
|
JSON.parse(File.open(
|
||||||
|
@ -13,29 +14,36 @@ describe CustomWizard::SubmissionSerializer do
|
||||||
|
|
||||||
before do
|
before do
|
||||||
CustomWizard::Template.save(template_json, skip_jobs: true)
|
CustomWizard::Template.save(template_json, skip_jobs: true)
|
||||||
wizard = CustomWizard::Wizard.create(template_json["id"], user)
|
wizard = CustomWizard::Wizard.create(template_json["id"], user1)
|
||||||
CustomWizard::Submission.new(wizard,
|
CustomWizard::Submission.new(wizard,
|
||||||
step_1_field_1: "I am user submission",
|
step_1_field_1: "I am user submission",
|
||||||
submitted_at: Time.now.iso8601
|
submitted_at: Time.now.iso8601
|
||||||
).save
|
).save
|
||||||
@list = CustomWizard::Submission.list(wizard, page: 0)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should return submission attributes' do
|
it 'should return submission attributes' do
|
||||||
|
wizard = CustomWizard::Wizard.create(template_json["id"])
|
||||||
|
list = CustomWizard::Submission.list(wizard, page: 0)
|
||||||
|
|
||||||
json_array = ActiveModel::ArraySerializer.new(
|
json_array = ActiveModel::ArraySerializer.new(
|
||||||
@list.submissions,
|
list.submissions,
|
||||||
each_serializer: described_class
|
each_serializer: described_class
|
||||||
).as_json
|
).as_json
|
||||||
|
|
||||||
expect(json_array.length).to eq(1)
|
expect(json_array.length).to eq(1)
|
||||||
expect(json_array[0][:id].present?).to eq(true)
|
expect(json_array[0][:id].present?).to eq(true)
|
||||||
expect(json_array[0][:user].present?).to eq(true)
|
expect(json_array[0][:user]).to eq(
|
||||||
|
BasicUserSerializer.new(user1, root: false).as_json
|
||||||
|
)
|
||||||
expect(json_array[0][:submitted_at].present?).to eq(true)
|
expect(json_array[0][:submitted_at].present?).to eq(true)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should return field values, types and labels" do
|
it "should return field values, types and labels" do
|
||||||
|
wizard = CustomWizard::Wizard.create(template_json["id"])
|
||||||
|
list = CustomWizard::Submission.list(wizard, page: 0)
|
||||||
|
|
||||||
json_array = ActiveModel::ArraySerializer.new(
|
json_array = ActiveModel::ArraySerializer.new(
|
||||||
@list.submissions,
|
list.submissions,
|
||||||
each_serializer: described_class
|
each_serializer: described_class
|
||||||
).as_json
|
).as_json
|
||||||
|
|
||||||
|
|
Laden …
In neuem Issue referenzieren