From e45dabf39acda0328559a34596b70d9af5c51914 Mon Sep 17 00:00:00 2001 From: Justin Edmund Date: Tue, 31 Jan 2023 00:55:17 -0800 Subject: [PATCH] Save edit key for parties with no user ID --- app/models/party.rb | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/app/models/party.rb b/app/models/party.rb index 6e52a5d..a988c27 100644 --- a/app/models/party.rb +++ b/app/models/party.rb @@ -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