FIX: Do not allow encrypted PMs to be converted (#60)

FIX: Do not allow encrypted PMs to be converted (#60)

diff --git a/lib/topic_guardian_extensions.rb b/lib/topic_guardian_extensions.rb
new file mode 100644
index 0000000..1280375
--- /dev/null
+++ b/lib/topic_guardian_extensions.rb
@@ -0,0 +1,7 @@
+# frozen_string_literal: true
+
+module TopicGuardianExtension
+  def can_convert_topic?(topic)
+    super && !topic.is_encrypted?
+  end
+end
diff --git a/plugin.rb b/plugin.rb
index f550f78..d3eb509 100644
--- a/plugin.rb
+++ b/plugin.rb
@@ -20,22 +20,23 @@ after_initialize do
   end
 
   load File.expand_path('../app/controllers/encrypt_controller.rb', __FILE__)
+  load File.expand_path('../app/jobs/scheduled/encrypt_consistency.rb', __FILE__)
+  load File.expand_path('../app/jobs/scheduled/encrypted_post_timer_evaluator.rb', __FILE__)
+  load File.expand_path('../app/mailers/user_notifications_extensions.rb', __FILE__)
   load File.expand_path('../app/models/encrypted_post_timer.rb', __FILE__)
-  load File.expand_path('../app/models/encrypted_topics_user.rb', __FILE__)
   load File.expand_path('../app/models/encrypted_topics_data.rb', __FILE__)
+  load File.expand_path('../app/models/encrypted_topics_user.rb', __FILE__)
   load File.expand_path('../app/models/user_encryption_key.rb', __FILE__)
-  load File.expand_path('../app/jobs/scheduled/encrypt_consistency.rb', __FILE__)
-  load File.expand_path('../app/jobs/scheduled/encrypted_post_timer_evaluator.rb', __FILE__)
+  load File.expand_path('../lib/email_sender_extensions.rb', __FILE__)
   load File.expand_path('../lib/encrypted_post_creator.rb', __FILE__)
   load File.expand_path('../lib/openssl.rb', __FILE__)
+  load File.expand_path('../lib/post_actions_controller_extensions.rb', __FILE__)
   load File.expand_path('../lib/post_extensions.rb', __FILE__)
   load File.expand_path('../lib/topic_extensions.rb', __FILE__)
+  load File.expand_path('../lib/topic_guardian_extensions.rb', __FILE__)
+  load File.expand_path('../lib/topic_view_serializer_extension.rb', __FILE__)
   load File.expand_path('../lib/topics_controller_extensions.rb', __FILE__)
-  load File.expand_path('../lib/post_actions_controller_extensions.rb', __FILE__)
   load File.expand_path('../lib/user_extensions.rb', __FILE__)
-  load File.expand_path('../lib/email_sender_extensions.rb', __FILE__)
-  load File.expand_path('../lib/topic_view_serializer_extension.rb', __FILE__)
-  load File.expand_path('../app/mailers/user_notifications_extensions.rb', __FILE__)
 
   class DiscourseEncrypt::Engine < Rails::Engine
     engine_name DiscourseEncrypt::PLUGIN_NAME
@@ -56,14 +57,15 @@ after_initialize do
   end
 
   reloadable_patch do |plugin|
+    Email::Sender.class_eval         { prepend EmailSenderExtensions }
     Post.class_eval                  { prepend PostExtensions }
+    PostActionsController.class_eval { prepend PostActionsControllerExtensions }
     Topic.class_eval                 { prepend TopicExtensions }
+    TopicGuardian.class_eval         { prepend TopicGuardianExtension }
     TopicsController.class_eval      { prepend TopicsControllerExtensions }
-    PostActionsController.class_eval { prepend PostActionsControllerExtensions }
+    TopicViewSerializer.class_eval   { prepend TopicViewSerializerExtension }
     User.class_eval                  { prepend UserExtensions }
-    Email::Sender.class_eval         { prepend EmailSenderExtensions }
     UserNotifications.class_eval     { prepend UserNotificationsExtensions }
-    TopicViewSerializer.class_eval   { prepend TopicViewSerializerExtension }
   end
 
   # Send plugin-specific topic data to client via serializers.

GitHub sha: e4a4aab0

This commit appears in #60 which was approved by CvX. It was merged by udan11.