user upgrades: add index action.

This commit is contained in:
evazion
2020-12-25 01:21:54 -06:00
parent 2d50ba6fd5
commit e030a07816
5 changed files with 98 additions and 1 deletions

View File

@@ -14,6 +14,9 @@ class UserUpgrade < ApplicationRecord
complete: 20
}
scope :gifted, -> { where("recipient_id != purchaser_id") }
scope :self_upgrade, -> { where("recipient_id = purchaser_id") }
def self.enabled?
stripe_secret_key.present? && stripe_publishable_key.present? && stripe_webhook_secret.present?
end
@@ -89,6 +92,27 @@ class UserUpgrade < ApplicationRecord
recipient != purchaser
end
def self.visible(user)
if user.is_owner?
all
else
where(recipient: user).or(where(purchaser: user))
end
end
def self.search(params)
q = search_attributes(params, :id, :created_at, :updated_at, :upgrade_type, :status, :stripe_id, :recipient, :purchaser)
if params[:is_gifted].to_s.truthy?
q = q.gifted
elsif params[:is_gifted].to_s.falsy?
q = q.self_upgrade
end
q = q.apply_default_order(params)
q
end
concerning :UpgradeMethods do
def process_upgrade!(payment_status)
recipient.with_lock do