class Eco::API::UseCases::DefaultCases::ToCsvDetailedCase < Eco::API::UseCases::DefaultCases::ToCsvCase name "to-csv-detailed" type :export private def to_row(person) entry = to_entry_type(person) data = entry.values_at(*keys(entry)) data << person.subordinates data << person_supervisor(person) data += user_abilities(person) data += user_permissions_custom(person) if options.dig(:export, :options, :permissions_custom) account = person.account data << account&.landing_page_id data += user_preferences(person) data end def person_supervisor(person) session.micro.with_supervisor(person.supervisor_id, people) do |supervisor| return supervisor ? supervisor.name : "" end end def user_abilities(person) account_abilities = (person.account && person.account.permissions_merged) || {} abilities.map {|key| account_abilities[key] || "no access"} end def user_permissions_custom(person) account_abilities = (person.account && person.account.permissions_custom) || {} abilities.map {|key| account_abilities[key] || "no access"} end def user_preferences(person) user_preferences = (person.account && person.account.preferences&.doc) || {} preferences.map {|key| user_preferences[key] || false} end def spot_header super do |header| header << "Subordinates" header << "Supervisor Name" header += abilities_header header += abilities_header("custom") if options.dig(:export, :options, :permissions_custom) header << "Landing Page" header += preferences header end end def keys(entry) super(entry) + ["freemium"] end def login_providers session.login_providers end def abilities @abilities ||= session.presets_factory.keys end def abilities_header(prefix = nil) abilities.map do |key| prefix ? "#{prefix}_#{key}" : key end end def preferences @preferences ||= [ "show_sidebar", "show_shortcuts", "show_coming_soon", "show_recently_visited_forms", "show_tasks", "show_task_bubbles", "kiosk_enabled" ] end end