Spiegel von
https://github.com/paviliondev/discourse-custom-wizard.git
synchronisiert 2024-11-25 18:50:27 +01:00
Merge branch 'main' into pro-release
Dieser Commit ist enthalten in:
Commit
248e785086
10 geänderte Dateien mit 126 neuen und 6 gelöschten Zeilen
|
@ -88,6 +88,7 @@ class CustomWizard::AdminWizardController < CustomWizard::AdminController
|
||||||
:title,
|
:title,
|
||||||
:key,
|
:key,
|
||||||
:banner,
|
:banner,
|
||||||
|
:banner_upload_id,
|
||||||
:raw_description,
|
:raw_description,
|
||||||
:required_data_message,
|
:required_data_message,
|
||||||
:force_final,
|
:force_final,
|
||||||
|
@ -99,6 +100,7 @@ class CustomWizard::AdminWizardController < CustomWizard::AdminController
|
||||||
:index,
|
:index,
|
||||||
:label,
|
:label,
|
||||||
:image,
|
:image,
|
||||||
|
:image_upload_id,
|
||||||
:description,
|
:description,
|
||||||
:required,
|
:required,
|
||||||
:key,
|
:key,
|
||||||
|
|
|
@ -143,11 +143,17 @@ export default Component.extend(UndoChanges, {
|
||||||
|
|
||||||
actions: {
|
actions: {
|
||||||
imageUploadDone(upload) {
|
imageUploadDone(upload) {
|
||||||
this.set("field.image", upload.url);
|
this.setProperties({
|
||||||
|
"field.image": upload.url,
|
||||||
|
"field.image_upload_id": upload.id,
|
||||||
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
imageUploadDeleted() {
|
imageUploadDeleted() {
|
||||||
this.set("field.image", null);
|
this.setProperties({
|
||||||
|
"field.image": null,
|
||||||
|
"field.image_upload_id": null,
|
||||||
|
});
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
|
@ -24,11 +24,17 @@ export default Component.extend({
|
||||||
|
|
||||||
actions: {
|
actions: {
|
||||||
bannerUploadDone(upload) {
|
bannerUploadDone(upload) {
|
||||||
this.set("step.banner", upload.url);
|
this.setProperties({
|
||||||
|
"step.banner": upload.url,
|
||||||
|
"step.banner_upload_id": upload.id,
|
||||||
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
bannerUploadDeleted() {
|
bannerUploadDeleted() {
|
||||||
this.set("step.banner", null);
|
this.setProperties({
|
||||||
|
"step.banner": null,
|
||||||
|
"step.banner_upload_id": null,
|
||||||
|
});
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
|
@ -41,6 +41,7 @@ const step = {
|
||||||
index: null,
|
index: null,
|
||||||
title: null,
|
title: null,
|
||||||
banner: null,
|
banner: null,
|
||||||
|
banner_upload_id: null,
|
||||||
raw_description: null,
|
raw_description: null,
|
||||||
required_data: null,
|
required_data: null,
|
||||||
required_data_message: null,
|
required_data_message: null,
|
||||||
|
@ -65,6 +66,7 @@ const field = {
|
||||||
index: null,
|
index: null,
|
||||||
label: null,
|
label: null,
|
||||||
image: null,
|
image: null,
|
||||||
|
image_upload_id: null,
|
||||||
description: null,
|
description: null,
|
||||||
property: null,
|
property: null,
|
||||||
required: null,
|
required: null,
|
||||||
|
|
|
@ -44,7 +44,7 @@
|
||||||
imageUrl=field.image
|
imageUrl=field.image
|
||||||
onUploadDone=(action "imageUploadDone")
|
onUploadDone=(action "imageUploadDone")
|
||||||
onUploadDeleted=(action "imageUploadDeleted")
|
onUploadDeleted=(action "imageUploadDeleted")
|
||||||
type="wizard-step"
|
type="wizard-field-image"
|
||||||
class="no-repeat contain-image"
|
class="no-repeat contain-image"
|
||||||
id=(concat "wizard-field-" field.id "-image-upload")}}
|
id=(concat "wizard-field-" field.id "-image-upload")}}
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
imageUrl=step.banner
|
imageUrl=step.banner
|
||||||
onUploadDone=(action "bannerUploadDone")
|
onUploadDone=(action "bannerUploadDone")
|
||||||
onUploadDeleted=(action "bannerUploadDeleted")
|
onUploadDeleted=(action "bannerUploadDeleted")
|
||||||
type="wizard-banner"
|
type="wizard-step-banner"
|
||||||
class="no-repeat contain-image"
|
class="no-repeat contain-image"
|
||||||
id=(concat "wizard-step-" step.id "-banner-upload")}}
|
id=(concat "wizard-step-" step.id "-banner-upload")}}
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -11,6 +11,7 @@ class CustomWizard::Field
|
||||||
:label,
|
:label,
|
||||||
:description,
|
:description,
|
||||||
:image,
|
:image,
|
||||||
|
:image_upload_id,
|
||||||
:validations,
|
:validations,
|
||||||
:min_length,
|
:min_length,
|
||||||
:max_length,
|
:max_length,
|
||||||
|
|
|
@ -15,6 +15,7 @@ class CustomWizard::Step
|
||||||
:next,
|
:next,
|
||||||
:previous,
|
:previous,
|
||||||
:banner,
|
:banner,
|
||||||
|
:banner_upload_id,
|
||||||
:disabled,
|
:disabled,
|
||||||
:description_vars,
|
:description_vars,
|
||||||
:last_step,
|
:last_step,
|
||||||
|
|
|
@ -29,6 +29,7 @@ class CustomWizard::Template
|
||||||
ActiveRecord::Base.transaction do
|
ActiveRecord::Base.transaction do
|
||||||
schedule_save_jobs unless opts[:skip_jobs]
|
schedule_save_jobs unless opts[:skip_jobs]
|
||||||
PluginStore.set(CustomWizard::PLUGIN_NAME, @data[:id], @data)
|
PluginStore.set(CustomWizard::PLUGIN_NAME, @data[:id], @data)
|
||||||
|
ensure_wizard_upload_references!
|
||||||
end
|
end
|
||||||
|
|
||||||
self.class.clear_cache_keys
|
self.class.clear_cache_keys
|
||||||
|
@ -52,11 +53,16 @@ class CustomWizard::Template
|
||||||
PluginStore.get(CustomWizard::PLUGIN_NAME, wizard_id)
|
PluginStore.get(CustomWizard::PLUGIN_NAME, wizard_id)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.find_record(wizard_id)
|
||||||
|
PluginStoreRow.find_by(plugin_name: CustomWizard::PLUGIN_NAME, key: wizard_id)
|
||||||
|
end
|
||||||
|
|
||||||
def self.remove(wizard_id)
|
def self.remove(wizard_id)
|
||||||
wizard = CustomWizard::Wizard.create(wizard_id)
|
wizard = CustomWizard::Wizard.create(wizard_id)
|
||||||
return false if !wizard
|
return false if !wizard
|
||||||
|
|
||||||
ActiveRecord::Base.transaction do
|
ActiveRecord::Base.transaction do
|
||||||
|
ensure_wizard_upload_references!(wizard_id)
|
||||||
PluginStore.remove(CustomWizard::PLUGIN_NAME, wizard.id)
|
PluginStore.remove(CustomWizard::PLUGIN_NAME, wizard.id)
|
||||||
clear_user_wizard_redirect(wizard_id, after_time: !!wizard.after_time)
|
clear_user_wizard_redirect(wizard_id, after_time: !!wizard.after_time)
|
||||||
end
|
end
|
||||||
|
@ -123,6 +129,18 @@ class CustomWizard::Template
|
||||||
CustomWizard::Cache.new(AFTER_TIME_CACHE_KEY).delete
|
CustomWizard::Cache.new(AFTER_TIME_CACHE_KEY).delete
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.ensure_wizard_upload_references!(wizard_id, wizard_upload_ids = [])
|
||||||
|
wizard_record = find_record(wizard_id)
|
||||||
|
|
||||||
|
if wizard_record
|
||||||
|
UploadReference.ensure_exist!(
|
||||||
|
upload_ids: wizard_upload_ids,
|
||||||
|
target_type: "PluginStoreRow",
|
||||||
|
target_id: wizard_record.id
|
||||||
|
)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def normalize_data
|
def normalize_data
|
||||||
|
@ -176,4 +194,19 @@ class CustomWizard::Template
|
||||||
object.delete(:index)
|
object.delete(:index)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def ensure_wizard_upload_references!
|
||||||
|
upload_ids = []
|
||||||
|
|
||||||
|
@data[:steps].each do |step|
|
||||||
|
upload_ids << step[:banner_upload_id] if step[:banner_upload_id]
|
||||||
|
|
||||||
|
step[:fields].each do |field|
|
||||||
|
upload_ids << field[:image_upload_id] if field[:image_upload_id]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
upload_ids = upload_ids.select { |upload_id| Upload.exists?(upload_id) }
|
||||||
|
self.class.ensure_wizard_upload_references!(@data[:id], upload_ids)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -4,6 +4,7 @@ describe CustomWizard::Template do
|
||||||
fab!(:user) { Fabricate(:user) }
|
fab!(:user) { Fabricate(:user) }
|
||||||
let(:template_json) { get_wizard_fixture("wizard") }
|
let(:template_json) { get_wizard_fixture("wizard") }
|
||||||
let(:permitted_json) { get_wizard_fixture("wizard/permitted") }
|
let(:permitted_json) { get_wizard_fixture("wizard/permitted") }
|
||||||
|
fab!(:upload) { Fabricate(:upload) }
|
||||||
|
|
||||||
before do
|
before do
|
||||||
CustomWizard::Template.save(template_json, skip_jobs: true)
|
CustomWizard::Template.save(template_json, skip_jobs: true)
|
||||||
|
@ -45,6 +46,74 @@ describe CustomWizard::Template do
|
||||||
).to eq(true)
|
).to eq(true)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "upload references" do
|
||||||
|
it "are added if a wizard has a step banner" do
|
||||||
|
template_json['steps'][0]['banner'] = upload.url
|
||||||
|
template_json['steps'][0]['banner_upload_id'] = upload.id
|
||||||
|
CustomWizard::Template.save(template_json, skip_jobs: true)
|
||||||
|
wizard_record = CustomWizard::Template.find_record(template_json["id"])
|
||||||
|
expect(
|
||||||
|
UploadReference.exists?(
|
||||||
|
upload_id: upload.id,
|
||||||
|
target_type: "PluginStoreRow",
|
||||||
|
target_id: wizard_record.id
|
||||||
|
)
|
||||||
|
).to eq(true)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "are added if a wizard has a field image" do
|
||||||
|
template_json['steps'][0]["fields"][0]['image'] = upload.url
|
||||||
|
template_json['steps'][0]["fields"][0]['image_upload_id'] = upload.id
|
||||||
|
CustomWizard::Template.save(template_json, skip_jobs: true)
|
||||||
|
wizard_record = CustomWizard::Template.find_record(template_json["id"])
|
||||||
|
expect(
|
||||||
|
UploadReference.exists?(
|
||||||
|
upload_id: upload.id,
|
||||||
|
target_type: "PluginStoreRow",
|
||||||
|
target_id: wizard_record.id
|
||||||
|
)
|
||||||
|
).to eq(true)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "are removed if a wizard step banner is removed" do
|
||||||
|
template_json['steps'][0]['banner'] = upload.url
|
||||||
|
template_json['steps'][0]['banner_upload_id'] = upload.id
|
||||||
|
CustomWizard::Template.save(template_json, skip_jobs: true)
|
||||||
|
|
||||||
|
template_json['steps'][0]['banner'] = nil
|
||||||
|
template_json['steps'][0]['banner_upload_id'] = nil
|
||||||
|
CustomWizard::Template.save(template_json, skip_jobs: true)
|
||||||
|
wizard_record = CustomWizard::Template.find_record(template_json["id"])
|
||||||
|
expect(
|
||||||
|
UploadReference.exists?(target_type: "PluginStoreRow")
|
||||||
|
).to eq(false)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "are removed if a wizard field image is removed" do
|
||||||
|
template_json['steps'][0]["fields"][0]['image'] = upload.url
|
||||||
|
template_json['steps'][0]["fields"][0]['image_upload_id'] = upload.id
|
||||||
|
CustomWizard::Template.save(template_json, skip_jobs: true)
|
||||||
|
|
||||||
|
template_json['steps'][0]["fields"][0]['image'] = nil
|
||||||
|
template_json['steps'][0]["fields"][0]['image_upload_id'] = nil
|
||||||
|
CustomWizard::Template.save(template_json, skip_jobs: true)
|
||||||
|
wizard_record = CustomWizard::Template.find_record(template_json["id"])
|
||||||
|
expect(
|
||||||
|
UploadReference.exists?(target_type: "PluginStoreRow")
|
||||||
|
).to eq(false)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "are removed if a wizard is removed" do
|
||||||
|
template_json['steps'][0]["fields"][0]['image'] = upload.url
|
||||||
|
template_json['steps'][0]["fields"][0]['image_upload_id'] = upload.id
|
||||||
|
CustomWizard::Template.save(template_json, skip_jobs: true)
|
||||||
|
CustomWizard::Template.remove(template_json["id"])
|
||||||
|
expect(
|
||||||
|
UploadReference.exists?(target_type: "PluginStoreRow")
|
||||||
|
).to eq(false)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
context "wizard template list" do
|
context "wizard template list" do
|
||||||
before do
|
before do
|
||||||
enable_subscription('standard')
|
enable_subscription('standard')
|
||||||
|
|
Laden …
In neuem Issue referenzieren