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:
2020-04-09 11:51:54 +02:00
parent 10d80c6548
commit 94966a9933
3 changed files with 31 additions and 2 deletions

View File

@@ -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

View File

@@ -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