Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions config/locales/server.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,28 @@ en:
error_messages:
wizard_replacing_composer: "Category not allowed for topic creation."

system_messages:
custom_wizard_revise_queued_topic:
title: "Feedback on your topic"
subject_template: 'Feedback on new topic titled "%{topic_title}"'
text_body_template: |
Hi %{username},

We've reviewed your new topic titled "%{topic_title}" and have some feedback for you.

Reason: %{reason}

Feedback: %{feedback}

Your answers have been saved: [open the "%{wizard_name}" wizard](%{wizard_url}), make the suggested changes and submit it again. You don't need to fill it in from scratch.

Thanks,
%{site_name} Moderators

site_settings:
custom_wizard_enabled: "Enable custom wizards."
wizard_redirect_exclude_paths: "Routes excluded from wizard redirects."
wizard_recognised_image_upload_formats: "File types which will result in upload displaying an image preview"
wizard_apis_enabled: "Enable API features (experimental)."
wizard_critical_notices_on_dashboard: "Show critical notices about the custom wizard plugin on the admin dashboard."
custom_wizard_reopen_on_revise: 'When a moderator chooses "Revise" on a queued wizard topic, reopen the wizard prefilled with the author''s answers instead of sending them the raw post. The wizard must save submissions and allow multiple submissions.'
19 changes: 19 additions & 0 deletions config/locales/server.it.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,28 @@ it:
error_messages:
wizard_replacing_composer: "Categoria non consentita per la creazione di argomenti."

system_messages:
custom_wizard_revise_queued_topic:
title: "Feedback sul tuo argomento"
subject_template: 'Feedback sul nuovo argomento intitolato "%{topic_title}"'
text_body_template: |
Ciao %{username},

Abbiamo esaminato il tuo nuovo argomento intitolato "%{topic_title}" e abbiamo un feedback per te.

Motivo: %{reason}

Feedback: %{feedback}

Le tue risposte sono state salvate: [apri il wizard "%{wizard_name}"](%{wizard_url}), apporta le modifiche suggerite e invialo di nuovo. Non devi compilarlo da capo.

Grazie,
I moderatori di %{site_name}

site_settings:
custom_wizard_enabled: "Abilita i wizard personalizzati."
wizard_redirect_exclude_paths: "Percorsi esclusi dai reindirizzamenti dei wizard."
wizard_recognised_image_upload_formats: "Tipi di file per cui il caricamento mostra l'anteprima dell'immagine"
wizard_apis_enabled: "Abilita le funzioni API (sperimentale)."
wizard_critical_notices_on_dashboard: "Mostra nella dashboard di amministrazione gli avvisi critici sul plugin Custom Wizard."
custom_wizard_reopen_on_revise: 'Quando un moderatore sceglie "Revisione" su un argomento del wizard in coda, riapri il wizard precompilato con le risposte dell''autore invece di inviargli il post grezzo. Il wizard deve salvare gli invii e consentire invii multipli.'
2 changes: 2 additions & 0 deletions config/settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ plugins:
wizard_important_notices_on_dashboard:
client: true
default: true
custom_wizard_reopen_on_revise:
default: false
wizard_subscription_product_key:
hidden: true
default: ''
2 changes: 2 additions & 0 deletions lib/custom_wizard/action.rb
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,8 @@ def queue_topic(params, reason)
topic: params.dig(:topic_opts, :custom_fields),
post: params[:custom_fields],
},
# Lets a moderator's "revise" reopen this wizard (see CustomWizardReviewableQueuedPost).
wizard_id: @wizard.id,
),
)

Expand Down
46 changes: 46 additions & 0 deletions lib/custom_wizard/extensions/reviewable_queued_post.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# frozen_string_literal: true

# When a moderator asks the author to revise a queued wizard topic, core sends the raw post
# and asks the author to post it again with the composer, which loses the wizard's structure.
# If enabled, reopen the wizard prefilled with the author's answers and link to it instead.
module CustomWizardReviewableQueuedPost
def perform_revise_and_reject_post(performed_by, args)
draft = custom_wizard_revision_draft
return super if draft.blank?

wizard = draft.wizard

SystemMessage.create(
target_created_by,
:custom_wizard_revise_queued_topic,
**Dsa::AppealInstructions.message_options,
topic_title: payload["title"],
reason: args[:revise_custom_reason].presence || args[:revise_reason],
feedback: args[:revise_feedback],
wizard_name: wizard.name,
wizard_url: "#{Discourse.base_url}/w/#{wizard.id.dasherize}",
)

StaffActionLogger.new(performed_by).log_post_rejected(self, DateTime.now) if performed_by.staff?
create_result(:success, :rejected)
end

private

def custom_wizard_revision_draft
return if !SiteSetting.custom_wizard_enabled || !SiteSetting.custom_wizard_reopen_on_revise
return if topic.present? || target_created_by.blank?

wizard_id = payload["wizard_id"]
submission_id = payload.dig("wizard_custom_fields", "topic", "wizard_submission_id")
return if wizard_id.blank? || submission_id.blank?

CustomWizard::Submission.reopen(target_created_by, wizard_id, submission_id)
rescue StandardError => e
Discourse.warn_exception(
e,
message: "Custom Wizard: failed to reopen wizard for reviewable #{id}",
)
nil
end
end
22 changes: 22 additions & 0 deletions lib/custom_wizard/submission.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,28 @@ def remove
end
end

# Copies the answers of a submitted wizard into a new draft, so the wizard opens prefilled
# and the user can correct and resubmit it. Returns the draft, or nil if the wizard can't be
# reopened for the user, or if the user already has a draft with answers, which is never
# overwritten.
def self.reopen(user, wizard_id, submission_id)
wizard = CustomWizard::Wizard.create(wizard_id, user)
return if !wizard&.save_submissions || !wizard.can_access?

submissions = list(wizard).submissions
drafts = submissions.reject(&:submitted?)
return if drafts.any? { |draft| draft.fields.present? }

original = submissions.find { |submission| submission.id == submission_id }
return if original.blank?

drafts.each(&:remove)

draft = new(wizard, original.fields.slice(*wizard.field_ids))
draft.save
draft
end

def self.cleanup_incomplete_submissions(wizard)
all_submissions = list(wizard)
sorted_submissions =
Expand Down
4 changes: 3 additions & 1 deletion plugin.rb
Original file line number Diff line number Diff line change
@@ -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.18.18
# version: 2.18.19
# authors: Angus McLeod, Faizaan Gagan, Robert Barrow, Keegan George, Kaitlin Maddever, Marcos Gutierrez
# url: https://github.com/paviliondev/discourse-custom-wizard
# contact_emails: development@pavilion.tech
Expand Down Expand Up @@ -92,6 +92,7 @@
require_relative "lib/custom_wizard/extensions/invites_controller.rb"
require_relative "lib/custom_wizard/extensions/users_controller.rb"
require_relative "lib/custom_wizard/extensions/guardian.rb"
require_relative "lib/custom_wizard/extensions/reviewable_queued_post.rb"
require_relative "lib/custom_wizard/extensions/custom_field/preloader.rb"
require_relative "lib/custom_wizard/extensions/custom_field/serializer.rb"
require_relative "lib/custom_wizard/extensions/custom_field/extension.rb"
Expand Down Expand Up @@ -183,6 +184,7 @@
::InvitesController.prepend InvitesControllerCustomWizard
::UsersController.prepend CustomWizardUsersController
::Guardian.prepend CustomWizardGuardian
::ReviewableQueuedPost.prepend CustomWizardReviewableQueuedPost

full_path =
"#{Rails.root}/plugins/discourse-custom-wizard/assets/stylesheets/wizard/wizard_custom.scss"
Expand Down
Loading
Loading