2019-04-30 08:27:42 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2020-10-09 21:52:48 +08:00
|
|
|
Fabricator(:user_api_key) do
|
|
|
|
user
|
2024-11-09 01:05:03 +08:00
|
|
|
|
|
|
|
after_create do |key, transients|
|
|
|
|
if key.client.blank?
|
|
|
|
client = Fabricate(:user_api_key_client)
|
|
|
|
key.user_api_key_client_id = client.id
|
|
|
|
key.save!
|
|
|
|
end
|
|
|
|
end
|
2020-10-09 21:52:48 +08:00
|
|
|
end
|
|
|
|
|
2020-09-29 17:57:48 +08:00
|
|
|
Fabricator(:user_api_key_scope)
|
|
|
|
|
2024-11-20 04:28:04 +08:00
|
|
|
Fabricator(:user_api_key_client_scope)
|
|
|
|
|
2024-11-09 01:05:03 +08:00
|
|
|
Fabricator(:user_api_key_client) do
|
2024-11-20 04:28:04 +08:00
|
|
|
transient :scopes
|
|
|
|
|
2024-11-09 01:05:03 +08:00
|
|
|
client_id { SecureRandom.hex }
|
|
|
|
application_name "some app"
|
2024-11-20 04:28:04 +08:00
|
|
|
|
|
|
|
after_create do |client, transients|
|
|
|
|
if transients[:scopes].present?
|
|
|
|
[*transients[:scopes]].each { |scope| client.scopes.create!(name: scope) }
|
|
|
|
end
|
|
|
|
end
|
2024-11-09 01:05:03 +08:00
|
|
|
end
|
|
|
|
|
2016-09-02 14:57:41 +08:00
|
|
|
Fabricator(:readonly_user_api_key, from: :user_api_key) do
|
2020-09-29 17:57:48 +08:00
|
|
|
scopes { [Fabricate.build(:user_api_key_scope, name: "read")] }
|
2016-09-02 14:57:41 +08:00
|
|
|
end
|
2020-10-09 00:38:54 +08:00
|
|
|
|
|
|
|
Fabricator(:bookmarks_calendar_user_api_key, from: :user_api_key) do
|
|
|
|
scopes { [Fabricate.build(:user_api_key_scope, name: "bookmarks_calendar")] }
|
|
|
|
end
|