Add user as reactable (#5893)

* Add user as reactable

* Make title method public

* Use constants for reactable_type and status
This commit is contained in:
Andy Zhao 2020-02-04 22:25:56 -05:00 committed by GitHub
parent bae7ee8b73
commit be6aaf750c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 6 deletions

View file

@ -2,6 +2,8 @@ class Reaction < ApplicationRecord
include AlgoliaSearch
CATEGORIES = %w[like readinglist unicorn thinking hands thumbsdown vomit].freeze
REACTABLE_TYPES = %w[Comment Article User].freeze
STATUSES = %w[valid invalid confirmed archived].freeze
belongs_to :reactable, polymorphic: true
belongs_to :user
@ -13,8 +15,8 @@ class Reaction < ApplicationRecord
counter_culture :user
validates :category, inclusion: { in: CATEGORIES }
validates :reactable_type, inclusion: { in: %w[Comment Article] }
validates :status, inclusion: { in: %w[valid invalid confirmed archived] }
validates :reactable_type, inclusion: { in: REACTABLE_TYPES }
validates :status, inclusion: { in: STATUSES }
validates :user_id, uniqueness: { scope: %i[reactable_id reactable_type category] }
validate :permissions

View file

@ -478,6 +478,10 @@ class User < ApplicationRecord
email_follower_notifications
end
def title
name
end
private
def index_id
@ -603,10 +607,6 @@ class User < ApplicationRecord
errors.add(:mastodon_url, "is not an allowed Mastodon instance")
end
def title
name
end
def tag_list
"" # Unused but necessary for search index
end