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

DEV: Implement wizard replacement validation in Topic Creation

Dieser Commit ist enthalten in:
jumagura 2023-09-18 17:35:38 -04:00
Ursprung 9ab4ca21c8
Commit f2d1437cff
3 geänderte Dateien mit 27 neuen und 0 gelöschten Zeilen

Datei anzeigen

@ -55,6 +55,8 @@ en:
liquid_syntax_error: "Liquid syntax error in %{attribute}: %{message}"
subscription: "%{type} %{property} usage is not supported on your subscription"
not_permitted_for_guests: "%{object_id} is not permitted when guests can access the wizard"
error_messages:
wizard_replacing_composer: "A wizard is set to replace the composer in this category. You cannot create a topic here."
site_settings:
custom_wizard_enabled: "Enable custom wizards."

Datei anzeigen

@ -0,0 +1,23 @@
# frozen_string_literal: true
module CustomWizardTopicExtension
extend ActiveSupport::Concern
included { before_validation :check_wizard_replacement, on: :create }
def check_wizard_replacement
if wizard_replacing_composer?(self.category_id)
self.errors.add(
:base,
I18n.t('wizard.error_messages.wizard_replacing_composer')
)
end
end
def wizard_replacing_composer?(category_id)
return false unless category_id
category = Category.find(category_id)
category.custom_fields['create_topic_wizard'].present?
end
end

Datei anzeigen

@ -91,6 +91,7 @@ after_initialize do
../lib/custom_wizard/extensions/invites_controller.rb
../lib/custom_wizard/extensions/users_controller.rb
../lib/custom_wizard/extensions/guardian.rb
../lib/custom_wizard/extensions/topic_extension.rb
../lib/custom_wizard/extensions/custom_field/preloader.rb
../lib/custom_wizard/extensions/custom_field/serializer.rb
../lib/custom_wizard/extensions/custom_field/extension.rb
@ -200,6 +201,7 @@ after_initialize do
::InvitesController.prepend InvitesControllerCustomWizard
::UsersController.prepend CustomWizardUsersController
::Guardian.prepend CustomWizardGuardian
::Topic.include CustomWizardTopicExtension
full_path = "#{Rails.root}/plugins/discourse-custom-wizard/assets/stylesheets/wizard/wizard_custom.scss"
if Stylesheet::Importer.respond_to?(:plugin_assets)