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

75 Zeilen
1,5 KiB
Ruby

# frozen_string_literal: true
2020-04-13 14:17:22 +02:00
class CustomWizard::WizardSerializer < CustomWizard::BasicWizardSerializer
2021-03-11 07:30:15 +01:00
2020-04-13 14:17:22 +02:00
attributes :start,
:background,
:submission_last_updated_at,
2020-04-13 14:17:22 +02:00
:theme_id,
:completed,
:required,
:permitted,
:uncategorized_category_id,
2021-09-14 05:33:16 +02:00
:categories,
2022-01-27 10:51:24 +01:00
:subscribed,
:resume_on_revisit
2021-03-11 07:30:15 +01:00
2020-04-13 14:17:22 +02:00
has_many :steps, serializer: ::CustomWizard::StepSerializer, embed: :objects
has_one :user, serializer: ::BasicUserSerializer, embed: :objects
2020-03-21 18:30:11 +01:00
has_many :groups, serializer: ::BasicGroupSerializer, embed: :objects
def completed
object.completed?
end
def include_completed?
object.completed? &&
(!object.respond_to?(:multiple_submissions) || !object.multiple_submissions) &&
!scope.is_admin?
end
def permitted
object.permitted?
end
2021-03-11 07:30:15 +01:00
2020-04-13 14:17:22 +02:00
def start
object.start
2020-04-13 14:17:22 +02:00
end
def include_start?
2021-03-12 08:38:50 +01:00
include_steps? && object.start.present?
end
def submission_last_updated_at
object.current_submission.updated_at
end
def include_steps?
!include_completed?
end
2021-03-11 07:30:15 +01:00
def include_categories?
object.needs_categories
end
2021-03-11 07:30:15 +01:00
2020-03-21 18:30:11 +01:00
def include_groups?
object.needs_groups
end
2021-03-11 07:30:15 +01:00
def uncategorized_category_id
SiteSetting.uncategorized_category_id
end
2021-03-11 07:30:15 +01:00
def include_uncategorized_category_id?
object.needs_categories
end
def categories
object.categories.map { |c| c.to_h }
end
2021-09-14 05:33:16 +02:00
2021-09-24 11:58:42 +02:00
def subscribed
CustomWizard::Subscription.subscribed?
2021-09-14 05:33:16 +02:00
end
2021-03-11 07:30:15 +01:00
end