@streed is the literal best

This commit is contained in:
Andrew Brown 2019-07-07 12:50:17 -05:00
parent 69b5ab66ea
commit 059fc67ba2

View File

@ -2,8 +2,10 @@ class PageUnlockPromoCode < ApplicationRecord
has_many :promotions
has_many :users, -> { distinct }, through: :promotions
def unlocked_page_types
page_types.split('|') & Rails.application.config.content_types[:all].map(&:name)
serialize :page_types, Array
def whitelisted_page_types
page_types & Rails.application.config.content_types[:all].map(&:name)
end
@ -19,7 +21,7 @@ class PageUnlockPromoCode < ApplicationRecord
# 1 use left, but this seems not worth it to fix
update(uses_remaining: uses_remaining - 1)
unlocked_page_types.each do |page_type|
whitelisted_page_types.each do |page_type|
promotions.create(
user: user,
content_type: page_type,