Feature: Access tokens for API access (#604)

Co-authored-by: Pranav Raj Sreepuram <pranavrajs@gmail.com>
This commit is contained in:
Sojan Jose
2020-03-11 00:02:15 +05:30
committed by GitHub
parent 19ab0fe108
commit a5b1e2b650
29 changed files with 517 additions and 270 deletions

View File

@@ -0,0 +1,23 @@
class CreateAccessTokens < ActiveRecord::Migration[6.0]
def change
create_table :access_tokens do |t|
t.references :owner, polymorphic: true, index: true
t.string :token, index: { unique: true }
t.timestamps
end
remove_column :agent_bots, :auth_token, :string
[::User, ::AgentBot].each do |access_tokenable|
generate_access_tokens(access_tokenable)
end
end
def generate_access_tokens(access_tokenable)
access_tokenable.find_in_batches do |record_batch|
record_batch.each do |record|
record.create_access_token if record.access_token.blank?
end
end
end
end

View File

@@ -0,0 +1,10 @@
class AddAccountIdToAgentBotInboxes < ActiveRecord::Migration[6.0]
def change
add_column :agent_bot_inboxes, :account_id, :integer, index: true
AgentBotInbox.all.each do |agent_bot_inbox|
agent_bot_inbox.account_id = agent_bot_inbox.inbox.account_id
agent_bot_inbox.save!
end
end
end