docbrown/app/services/articles/unpublish.rb
Fernando Valverde b8abbda72e
Unpublish post service class + V1 API endpoint (#18031)
* Unpublish post service + API

* Apply PR feedback

* Use module_function on service class
2022-07-08 09:08:55 -06:00

17 lines
428 B
Ruby

module Articles
module Unpublish
module_function
def call(user, article)
attributes = {}
if article.has_frontmatter?
body_markdown = article.body_markdown.sub(/\npublished:\s*true\s*\n/, "\npublished: false\n")
attributes[:body_markdown] = body_markdown
else
attributes[:published] = false
end
Articles::Updater.call(user, article, attributes)
end
end
end