docbrown/app/services/articles/attributes.rb
Anna Buianova 6ef1968377
Made published_at immutable after an article has been published once (#18384)
* Don't change published_at for articles that have already been published (even if unpublished later)

* Removed unused code related to changing published_at

* Added specs for updating published_from_feed articles, fixed specs

* Removed old validation

* Added specs for article validation published_from_feed

* Added and reorganized specs for the Article model (setting published_at)

* Remove the commented code, added a spec

* Added specs for unpublishing

* Removed unused update_published_at from article attributes spec

* Fixed nullifying published_at seconds when republishing from rich editor
2022-08-30 11:32:06 +03:00

38 lines
1.1 KiB
Ruby

module Articles
class Attributes
ATTRIBUTES = %i[archived body_markdown canonical_url description
edited_at main_image organization_id user_id published
title video_thumbnail_url published_at].freeze
attr_reader :attributes, :article_user
def initialize(attributes, article_user)
@attributes = attributes
@article_user = article_user
end
def for_update(update_edited_at: false)
hash = attributes.slice(*ATTRIBUTES)
# don't reset the collection when no series was passed
hash[:collection] = collection if attributes.key?(:series)
hash[:tag_list] = tag_list
hash[:edited_at] = Time.current if update_edited_at
hash[:published_at] = hash[:published_at].to_datetime if hash[:published_at]
hash
end
private
def collection
Collection.find_series(attributes[:series], article_user) if attributes[:series].present?
end
def tag_list
if attributes[:tag_list]
attributes[:tag_list]
elsif attributes[:tags]
attributes[:tags].join(", ")
end
end
end
end