0
0
Fork 1
Spiegel von https://github.com/paviliondev/discourse-custom-wizard.git synchronisiert 2024-11-10 12:22:54 +01:00
discourse-custom-wizard/serializers/wizard_serializer.rb

103 Zeilen
1,7 KiB
Ruby

2019-12-05 09:05:21 +01:00
module CustomWizardWizardSerializerExtension
2019-12-06 10:05:19 +01:00
extend ActiveSupport::Concern
included do
attributes :id,
:name,
:background,
:completed,
:required,
:min_trust,
:permitted,
:user,
:categories,
:uncategorized_category_id
end
2019-12-05 09:05:21 +01:00
def id
object.id
end
def include_id?
object.respond_to?(:id)
end
def name
object.name
end
def include_name?
object.respond_to?(:name)
end
def background
object.background
end
def include_background?
object.respond_to?(:background)
end
def completed
object.completed?
end
def include_completed?
object.completed? &&
(!object.respond_to?(:multiple_submissions) || !object.multiple_submissions) &&
!scope.is_admin?
end
def min_trust
object.min_trust
end
def include_min_trust?
object.respond_to?(:min_trust)
end
def permitted
object.permitted?
end
def include_permitted?
object.respond_to?(:permitted?)
end
def include_start?
object.start && include_steps?
end
def include_steps?
!include_completed?
end
def required
object.required
end
def include_required?
object.respond_to?(:required)
end
def user
object.user
end
def categories
begin
site = ::Site.new(scope)
::ActiveModel::ArraySerializer.new(site.categories, each_serializer: BasicCategorySerializer)
rescue => e
puts "HERE IS THE ERROR: #{e.inspect}"
end
end
def uncategorized_category_id
SiteSetting.uncategorized_category_id
end
end
class WizardSerializer
prepend CustomWizardWizardSerializerExtension if SiteSetting.custom_wizard_enabled
end