Getter convenience method for tokens

This commit is contained in:
2022-03-12 00:01:40 -05:00
parent 0485e9d64c
commit 5d928c486f
2 changed files with 19 additions and 1 deletions

View File

@@ -24,4 +24,22 @@ class CustomerToken < ActiveRecord::Base
CustomerToken.where("expires_at < ?", Time.now).destroy_all CustomerToken.where("expires_at < ?", Time.now).destroy_all
end end
def expired?
self.expires_at < Time.now
end
# Getter convenience method for tokens
def self.get_token(issue)
# reuse existing tokens
token = find_by_issue_id issue.id
unless token.nil?
return token unless token.expired?
# remove expired tokens
token.destroy
end
# TODO add setting in pluging settings page
return create(:expires_at => Time.now + 1.month, :issue_id => issue.id)
end
end end

View File

@@ -99,7 +99,7 @@ module IssuePatch
# Create a shareable link for a customer # Create a shareable link for a customer
def share_token def share_token
CustomerToken.create(:expires_at => Time.now + 1.month, :issue_id => id) CustomerToken.get_token self
end end
end end