docbrown/app/services/articles/attributes.rb
Joshua Wehner 6fe9d7d7a6
Allow org admins to add members as co-authors (#20008)
* Basics might be working?

* Stop propagating button clicks in autocomplete pills

* Better blank slate

* Better location to stop propagation

* Remove author_id from org co-authors

* Move UserStore and try testing it

* Remove extraneous comments

* OH... that's what that does!

* Very basic testing

* Re-organize javascripts

* Rename & re-org for testing

* Cleanup

* More tests

* Remove unnecessary nesting

* Coninuing to try to bump coverage

* Include /packs/ in code coverage metric

* Try tweaking jest coverage more?

We probably can't collect coverage from all of packs/* (because coverage is too low) but maybe we can try to opt-in for newer areas as we go?

* Relocate JS tests, for build & coverage

* User ID exception on search, not fetch

* Remove commented-out console.log

---------

Co-authored-by: Mac Siri <krairit.siri@gmail.com>
2023-09-15 08:12:41 -04: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 co_author_ids_list].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