Class: Collavre::Tools::CreativeImportService

Inherits:
Object
  • Object
show all
Extended by:
T::Sig, ToolMeta
Defined in:
app/services/collavre/tools/creative_import_service.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.requires_approval?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'app/services/collavre/tools/creative_import_service.rb', line 20

def self.requires_approval?
  true
end

Instance Method Details

#call(markdown:, parent_id:) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'app/services/collavre/tools/creative_import_service.rb', line 28

def call(markdown:, parent_id:)
  raise "Current.user is required" unless Current.user

  parent = Creative.find_by(id: parent_id)
  return { error: "Parent Creative not found", id: parent_id } unless parent
  return { error: "No write permission on parent Creative", id: parent_id } unless parent.has_permission?(Current.user, :write)

  created = MarkdownImporter.import(markdown, parent: parent, user: Current.user)

  {
    success: true,
    parent_id: parent_id,
    created_count: created.size,
    tree: created.map { |c| { id: c.id, description: c.description.to_s.truncate(100), parent_id: c.parent_id } }
  }
end