* Start refactoring articles update * Articles update refactoring * Added a couple of tests for Articles::Updater * Reorganized code in Articles::Updater and ::Attributes a bit * A couple of more tests for Articles::Attributes * Reverted changed in the articles_controller * Edited_at in Articles::Attributes * Use Articles::Updater in ArticlesController * Tests for notifications when published/unpublished an article * Removed old code * Return result object from Articles::Updater * Don't reset articles collection when no series was passed * Fixed sending notifications when published an article the first time * Fix articles collection when updating * Fix setting attributes for articles update * Spec for articles update via api failure * More tests for Articles::Updater * More specs for articles updating * Pass article instead of article_id to articles updater to avoid loading an article twice * Remove the redundant check in the articles_controller * Articles::Attributes refactoring
37 lines
1 KiB
Ruby
37 lines
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].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
|
|
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
|