FIX: Do not raise error if topic not exist

FIX: Do not raise error if topic not exist

From bb44fd469cb2f0444a3e4641ade319fe1c655814 Mon Sep 17 00:00:00 2001
From: Vinoth Kannan <vinothkannan@vinkas.com>
Date: Fri, 21 Sep 2018 09:52:21 +0530
Subject: [PATCH] FIX: Do not raise error if topic not exist


diff --git a/plugin.rb b/plugin.rb
index 2fc49f5..aab4aed 100644
--- a/plugin.rb
+++ b/plugin.rb
@@ -26,7 +26,7 @@ after_initialize do
   DiscourseEvent.on(:before_staff_flag_action) do |args|
     if SiteSetting.assign_locks_flags?
 
-      if custom_fields = args[:post].topic.custom_fields
+      if custom_fields = args[:post].topic&.custom_fields
         if assigned_to_id = custom_fields[TopicAssigner::ASSIGNED_TO_ID]
           unless assigned_to_id.to_i == args[:user].id
             raise Discourse::InvalidAccess.new(

GitHub

@vinothkannans We should add a test case here :wink:

I will add it. I though it was very minor fix :smile:

It was added in SPEC: Do not raise error if topic not exist · discourse/discourse-assign@004cf71 · GitHub

2 Likes