0
0
Fork 1
Spiegel von https://github.com/paviliondev/discourse-custom-wizard.git synchronisiert 2024-11-09 11:52:54 +01:00

Ensure submission users are serialized properly

Dieser Commit ist enthalten in:
Angus McLeod 2023-03-15 13:33:07 +01:00
Ursprung 20e7b492ea
Commit a4e49e7bbc
4 geänderte Dateien mit 23 neuen und 9 gelöschten Zeilen

Datei anzeigen

@ -10,7 +10,7 @@ class CustomWizard::SubmissionSerializer < ApplicationSerializer
end
def user
::BasicUserSerializer.new(object.wizard.user).as_json
::BasicUserSerializer.new(object.wizard.user, root: false).as_json
end
def fields

Datei anzeigen

@ -120,15 +120,21 @@ class CustomWizard::Submission
end
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[:key] = wizard.actor_id if wizard.actor_id
params[:key] = list_actor_id if list_actor_id
query = PluginStoreRow.where(params)
result = OpenStruct.new(submissions: [], total: nil)
query.each do |record|
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|
wizard.user = submission_user if submission_user.present?
result.submissions.push(new(wizard, data))
end
end

Datei anzeigen

@ -1,7 +1,7 @@
# frozen_string_literal: true
# name: discourse-custom-wizard
# about: Forms for Discourse. Better onboarding, structured posting, data enrichment, automated actions and much more.
# version: 2.2.7
# version: 2.2.8
# authors: Angus McLeod, Faizaan Gagan, Robert Barrow, Keegan George, Kaitlin Maddever
# url: https://github.com/paviliondev/discourse-custom-wizard
# contact_emails: development@pavilion.tech

Datei anzeigen

@ -3,7 +3,8 @@
require_relative '../../plugin_helper'
describe CustomWizard::SubmissionSerializer do
fab!(:user) { Fabricate(:user) }
fab!(:user1) { Fabricate(:user) }
fab!(:user2) { Fabricate(:user) }
let(:template_json) {
JSON.parse(File.open(
@ -13,29 +14,36 @@ describe CustomWizard::SubmissionSerializer do
before do
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,
step_1_field_1: "I am user submission",
submitted_at: Time.now.iso8601
).save
@list = CustomWizard::Submission.list(wizard, page: 0)
end
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(
@list.submissions,
list.submissions,
each_serializer: described_class
).as_json
expect(json_array.length).to eq(1)
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)
end
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(
@list.submissions,
list.submissions,
each_serializer: described_class
).as_json