This is useful if you have multiple programs and want to give them different API keys, or if you want to rotate keys for a single program.
20 lines
371 B
Ruby
20 lines
371 B
Ruby
class ApiKey < ApplicationRecord
|
|
belongs_to :user
|
|
validates_uniqueness_of :key
|
|
has_secure_token :key
|
|
|
|
def self.visible(user)
|
|
if user.is_owner?
|
|
all
|
|
else
|
|
where(user: user)
|
|
end
|
|
end
|
|
|
|
def self.search(params)
|
|
q = search_attributes(params, :id, :created_at, :updated_at, :key, :user)
|
|
q = q.apply_default_order(params)
|
|
q
|
|
end
|
|
end
|