mirror of
https://github.com/indentlabs/notebook.git
synced 2025-10-26 11:19:22 +00:00
this seems easier than expected
This commit is contained in:
parent
ff8ef968b4
commit
e9ad3eff91
@ -6,16 +6,13 @@ class PageUnlockPromoCode < ApplicationRecord
|
||||
page_types.split('|') & Rails.application.config.content_types[:all].map(&:name)
|
||||
end
|
||||
|
||||
def already_activated_users
|
||||
promotions.select(:user_id)
|
||||
end
|
||||
|
||||
def activate!(user)
|
||||
return false unless uses_remaining > 0
|
||||
|
||||
# Make sure this user hasn't activated this promo code before
|
||||
return false unless user.present?
|
||||
# return if users.where(id: user.id).any?
|
||||
return false if users.pluck(:id).include?(user.id)
|
||||
|
||||
# Activate!
|
||||
# technically two requests at the same time could still double-activate at
|
||||
|
||||
@ -25,6 +25,7 @@ class User < ApplicationRecord
|
||||
end
|
||||
has_many :promotions
|
||||
|
||||
|
||||
has_many :image_uploads
|
||||
|
||||
has_one :referral_code, dependent: :destroy
|
||||
@ -133,6 +134,7 @@ class User < ApplicationRecord
|
||||
"https://www.gravatar.com/avatar/#{email_md5}?d=identicon&s=#{size}".html_safe
|
||||
end
|
||||
|
||||
# TODO these (3) can probably all be scopes on the related object, no?
|
||||
def active_subscriptions
|
||||
subscriptions
|
||||
.where('start_date < ?', Time.now)
|
||||
@ -144,6 +146,10 @@ class User < ApplicationRecord
|
||||
BillingPlan.where(id: billing_plan_ids).uniq
|
||||
end
|
||||
|
||||
def active_promotions
|
||||
promotions.active
|
||||
end
|
||||
|
||||
def initialize_stripe_customer
|
||||
if self.stripe_customer_id.nil?
|
||||
customer_data = Stripe::Customer.create(email: self.email)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user