0
0
Fork 1
Spiegel von https://github.com/paviliondev/discourse-custom-wizard.git synchronisiert 2024-11-09 20:02:54 +01:00
Dieser Commit ist enthalten in:
jumagura 2023-03-20 17:50:27 -04:00
Commit c6c4e31ba9
7 geänderte Dateien mit 67 neuen und 28 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,16 +120,23 @@ 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|
result.submissions.push(new(wizard, data))
_wizard = wizard.clone
_wizard.user = submission_user if submission_user.present?
result.submissions.push(new(_wizard, data))
end
end
end

Datei anzeigen

@ -84,7 +84,7 @@ class CustomWizard::TemplateValidator
def validate_guests(object, type)
guests_permitted = @data[:permitted] && @data[:permitted].any? do |m|
m["output"].include?(CustomWizard::Wizard::GUEST_GROUP_ID)
m["output"]&.include?(CustomWizard::Wizard::GUEST_GROUP_ID)
end
return unless guests_permitted

Datei anzeigen

@ -1,15 +1,15 @@
# 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.3.0
# version: 2.2.12
# authors: Angus McLeod, Faizaan Gagan, Robert Barrow, Keegan George, Kaitlin Maddever
# url: https://github.com/paviliondev/discourse-custom-wizard
# contact_emails: development@pavilion.tech
# subscription_url: https://coop.pavilion.tech
gem 'liquid', '5.0.1', require: true
register_asset 'stylesheets/common/admin.scss'
register_asset 'stylesheets/common/wizard.scss'
gem "liquid", "5.0.1", require: true
register_asset "stylesheets/common/admin.scss"
register_asset "stylesheets/common/wizard.scss"
enabled_site_setting :custom_wizard_enabled
@ -111,7 +111,7 @@ after_initialize do
Liquid::Template.register_filter(::CustomWizard::LiquidFilter::FirstNonEmpty)
add_to_class(:topic, :wizard_submission_id) do
custom_fields['wizard_submission_id']
custom_fields["wizard_submission_id"]
end
add_class_method(:wizard, :user_requires_completion?) do |user|
@ -123,7 +123,6 @@ after_initialize do
if user &&
user.first_seen_at.blank? &&
wizard = CustomWizard::Wizard.after_signup(user)
if !wizard.completed?
custom_redirect = true
CustomWizard::Wizard.set_user_redirect(wizard.id, user)
@ -134,8 +133,8 @@ after_initialize do
end
add_to_class(:user, :redirect_to_wizard) do
if custom_fields['redirect_to_wizard'].present?
custom_fields['redirect_to_wizard']
if custom_fields["redirect_to_wizard"].present?
custom_fields["redirect_to_wizard"]
else
nil
end
@ -160,10 +159,10 @@ after_initialize do
end
add_to_class(:application_controller, :redirect_to_wizard_if_required) do
@excluded_routes ||= SiteSetting.wizard_redirect_exclude_paths.split('|') + ['/w/']
@excluded_routes ||= SiteSetting.wizard_redirect_exclude_paths.split("|") + ["/w/"]
url = request.referer || request.original_url
excluded_route = @excluded_routes.any? { |str| /#{str}/ =~ url }
not_api = request.format === 'text/html'
not_api = request.format === "text/html"
if not_api && !excluded_route
wizard_id = current_user.redirect_to_wizard
@ -203,7 +202,7 @@ after_initialize do
full_path = "#{Rails.root}/plugins/discourse-custom-wizard/assets/stylesheets/wizard/wizard_custom.scss"
if Stylesheet::Importer.respond_to?(:plugin_assets)
Stylesheet::Importer.plugin_assets['wizard_custom'] = Set[full_path]
Stylesheet::Importer.plugin_assets["wizard_custom"] = Set[full_path]
else
# legacy method, Discourse 2.7.0.beta5 and below
DiscoursePluginRegistry.register_asset(full_path, {}, "wizard_custom")

Datei anzeigen

@ -9,6 +9,7 @@ describe CustomWizard::TemplateValidator do
let(:composer_preview) { get_wizard_fixture("field/composer_preview") }
let(:guests_permitted) { get_wizard_fixture("wizard/guests_permitted") }
let(:upload_field) { get_wizard_fixture("field/upload") }
let(:validation_condition) { get_wizard_fixture("condition/validation_condition") }
let(:valid_liquid_template) {
<<-LIQUID.strip
@ -182,6 +183,13 @@ describe CustomWizard::TemplateValidator do
CustomWizard::TemplateValidator.new(template).perform
).to eq(true)
end
it "validates settings with validation conditions" do
template[:permitted] = validation_condition["condition"]
expect(
CustomWizard::TemplateValidator.new(template).perform
).to eq(true)
end
end
context "steps" do

Datei anzeigen

@ -0,0 +1,17 @@
{
"condition": [
{
"type": "validation",
"pairs": [
{
"index": 0,
"key": "trust_level",
"key_type": "user_field",
"value": "2",
"value_type": "text",
"connector": "greater_or_equal"
}
]
}
]
}

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,36 +14,43 @@ describe CustomWizard::SubmissionSerializer do
before do
CustomWizard::Template.save(template_json, skip_jobs: true)
wizard = CustomWizard::Wizard.create(template_json["id"], user)
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)
wizard = CustomWizard::Wizard.create(template_json["id"], user1)
CustomWizard::Submission.new(wizard, step_1_field_1: "I am user1 submission", submitted_at: Time.now.iso8601).save
wizard = CustomWizard::Wizard.create(template_json["id"], user2)
CustomWizard::Submission.new(wizard, step_1_field_1: "I am user2 submission", submitted_at: Time.now.iso8601).save
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.length).to eq(2)
expect(json_array[0][:id].present?).to eq(true)
expect(json_array[0][:user].present?).to eq(true)
expect(json_array[0][:submitted_at].present?).to eq(true)
expect(json_array[0][:user]).to eq(BasicUserSerializer.new(user2, root: false).as_json)
expect(json_array[1][:user]).to eq(BasicUserSerializer.new(user1, root: false).as_json)
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
expect(json_array.length).to eq(1)
expect(json_array.length).to eq(2)
expect(json_array[0][:fields].as_json).to eq({
"step_1_field_1": {
"value": "I am user submission",
"value": "I am user2 submission",
"type": "text",
"label": "Text"
}