Save edit key for parties with no user ID

This commit is contained in:
Justin Edmund 2023-01-31 00:55:17 -08:00
parent cce33ebf08
commit e45dabf39a

View file

@ -62,6 +62,7 @@ class Party < ApplicationRecord
has_many :favorites
before_create :set_shortcode
before_save :set_edit_key
##### Amoeba configuration
amoeba do
@ -100,6 +101,12 @@ class Party < ApplicationRecord
self.shortcode = random_string
end
def set_edit_key
if !self.user
self.edit_key = Digest::SHA1.hexdigest([Time.now, rand].join)
end
end
def random_string
num_chars = 6
o = [('a'..'z'), ('A'..'Z'), (0..9)].map(&:to_a).flatten