mirror of
https://github.com/rickbarrette/redmine_qbo.git
synced 2025-11-08 17:04:23 -05:00
Getter convenience method for tokens
This commit is contained in:
@@ -24,4 +24,22 @@ class CustomerToken < ActiveRecord::Base
|
||||
CustomerToken.where("expires_at < ?", Time.now).destroy_all
|
||||
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
|
||||
|
||||
@@ -99,7 +99,7 @@ module IssuePatch
|
||||
|
||||
# Create a shareable link for a customer
|
||||
def share_token
|
||||
CustomerToken.create(:expires_at => Time.now + 1.month, :issue_id => id)
|
||||
CustomerToken.get_token self
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user