1
0
Fork 0

Merge pull request #229 from paviliondev/fix_user_in_submissions

Ensure submission users are serialized properly
Dieser Commit ist enthalten in:
Robert 2023-03-16 11:37:11 +00:00 committet von GitHub
Commit 5eca78f172
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 4AEE18F83AFDEB23
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.9
# version: 2.2.10
# 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