Don't generate new customer view token every time

This commit is contained in:
2022-03-07 07:52:17 -05:00
parent 7b5b673ebf
commit 30b704c90f
4 changed files with 25 additions and 5 deletions

View File

@@ -134,6 +134,23 @@ class CustomersController < ApplicationController
end
end
# creates new customer view tokens, removes expired tokens & redirects to newly created customer view with new token.
def share
Thread.new do
logger.debug "Removing expired customer tokens"
CustomerToken.remove_expired_tokens
ActiveRecord::Base.connection.close
end
begin
issue = Issue.find_by_id(params[:id])
redirect_to "#{Redmine::Utils::relative_url_root}/customers/view/#{issue.share_token.token}"
rescue
render_404
end
end
# displays an issue for a customer with a provided security CustomerToken
def view

View File

@@ -11,7 +11,6 @@
class CustomerToken < ActiveRecord::Base
unloadable
has_many :issues
#attr_accessible :token, :expires_at, :issue_id
validates_presence_of :expires_at, :issue_id
before_create :generate_token
@@ -20,4 +19,9 @@ class CustomerToken < ActiveRecord::Base
def generate_token
self.token = SecureRandom.base64(15).tr('+/=lIO0', OAUTH_CONSUMER_SECRET)
end
def remove_expired_tokens
CustomerToken.where("expires_at < ?", Time.now).destroy_all
end
end