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
|