FIX: Ensure topic is encrypted before deleting TopicAllowedUser.

FIX: Ensure topic is encrypted before deleting TopicAllowedUser.

Follow-up to c002f064a6c126f276e4909e2cb533b5e2c11e50.

diff --git a/plugin.rb b/plugin.rb
index e3050d9..94b16e9 100644
--- a/plugin.rb
+++ b/plugin.rb
@@ -209,7 +209,7 @@ after_initialize do
 
   # Delete TopicAllowedUser records for users who do not have the key.
   on(:post_created) do |post, opts, user|
-    if post&.is_encrypted? && !DiscourseEncrypt::Store.get("key_#{post.topic_id}_#{user.id}").present?
+    if post&.topic&.is_encrypted? && !DiscourseEncrypt::Store.get("key_#{post.topic_id}_#{user.id}").present?
       TopicAllowedUser.find_by(user_id: user.id, topic_id: post.topic_id).delete
     end
   end

GitHub sha: b9b2b23e