mirror of
https://github.com/rickbarrette/redmine_qbo.git
synced 2026-11-18 02:20:37 -05:00
Clear out expired customer share links
CustomerToken.purge_expired deletes share links that have expired or whose issue was deleted. It runs whenever a new link is made, so they don't pile up, and from rake redmine_qbo:purge_customer_tokens for a manual or scheduled run. Expired links were only ignored before. Also drops Issue's belongs_to :customer_token: issues have no such column, so the association could only raise. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
0d143e6eb1
commit
30c1f5181e
4 files changed
+63
-2
No files matched your search
@@ -21,7 +21,8 @@ class CustomerToken < ApplicationRecord
|
||||
|
||||
TOKEN_EXPIRATION = 1.month
|
||||
|
||||
# Get or create a token for the given issue
|
||||
# Get or create a token for the given issue. Making a new one also clears out the share links that have expired
|
||||
# or whose issue was deleted, so they don't pile up.
|
||||
def self.get_token(issue)
|
||||
return unless issue
|
||||
return unless User.current.allowed_to?(:view_issues, issue.project)
|
||||
@@ -29,9 +30,17 @@ class CustomerToken < ApplicationRecord
|
||||
token = active.find_by(issue_id: issue.id)
|
||||
return token if token
|
||||
|
||||
purge_expired
|
||||
create!(issue: issue)
|
||||
end
|
||||
|
||||
# Deletes the share links that have expired or whose issue no longer exists; returns how many
|
||||
def self.purge_expired
|
||||
where('expires_at <= ?', Time.current)
|
||||
.or(where.not(issue_id: Issue.select(:id)))
|
||||
.delete_all
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# Generate a unique token for the customer
|
||||
|
||||
Reference in new issue
Block a user