Skip to content
Snippets Groups Projects
Commit 06d045dd authored by pabois's avatar pabois
Browse files

auto set favorites for website manager

parent 1ea1bc7a
No related branches found
No related tags found
No related merge requests found
......@@ -3,6 +3,7 @@ module User::WithFavorites
included do
has_many :favorites, dependent: :destroy
after_save :autoset_favorites
end
def add_favorite(about)
......@@ -22,4 +23,12 @@ module User::WithFavorites
def favorites_for(about)
favorites.where(about_id: about.id, about_type: about.class.polymorphic_name)
end
def autoset_favorites
if saved_change_to_role? && website_manager? && favorites.none?
websites_to_manage.each do |website|
add_favorite(website)
end
end
end
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment