Handle authentication errors when appending data
This catches exceptions that can happen when an authentication is expired or removed by the user on google's side.
This commit is contained in:
@@ -11,6 +11,14 @@ class Form < ApplicationRecord
|
||||
|
||||
validates_presence_of :title
|
||||
|
||||
def deactivate!(reason = nil)
|
||||
self.user.deactivate!(reason)
|
||||
end
|
||||
|
||||
def active?
|
||||
self.user.active?
|
||||
end
|
||||
|
||||
def google_spreadsheet_url
|
||||
"https://docs.google.com/spreadsheets/d/#{google_spreadsheet_id}/edit" if google_spreadsheet_id.present?
|
||||
end
|
||||
|
||||
@@ -25,6 +25,15 @@ class User < ApplicationRecord
|
||||
end
|
||||
end
|
||||
|
||||
def deactivate!(reason = nil)
|
||||
# currently we only use deactivate if we get an authentication exception appending data to a spreadsheet
|
||||
authentications.last&.update(expires_at: Time.current)
|
||||
end
|
||||
|
||||
def active?
|
||||
authentications.last.present? && !authentications.last.expired?
|
||||
end
|
||||
|
||||
def google_authorization
|
||||
authentications.last.google_authorization
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user