Revert "FIX: even admin does not see/like encrypted posts (#20)" (#22)

Revert “FIX: even admin does not see/like encrypted posts (#20)” (#22)

This reverts commit e414c993159a02ded6012da74c845b1877f936ce.

diff --git a/lib/post_actions_controller_extensions.rb b/lib/post_actions_controller_extensions.rb
deleted file mode 100644
index 531f41a..0000000
--- a/lib/post_actions_controller_extensions.rb
+++ /dev/null
@@ -1,11 +0,0 @@
-# frozen_string_literal: true
-
-module PostActionsControllerExtensions
-  def create
-    if SiteSetting.encrypt_enabled?
-      raise Discourse::NotFound if @post.blank?
-      raise Discourse::InvalidAccess if !guardian.is_user_a_member_of_encrypted_conversation?(@post.topic)
-    end
-    super
-  end
-end
diff --git a/lib/topics_controller_extensions.rb b/lib/topics_controller_extensions.rb
index b4d56bc..a5e282d 100644
--- a/lib/topics_controller_extensions.rb
+++ b/lib/topics_controller_extensions.rb
@@ -1,14 +1,6 @@
 # frozen_string_literal: true
 
 module TopicsControllerExtensions
-  def show
-    if SiteSetting.encrypt_enabled?
-      topic = Topic.find_by(id: params[:topic_id])
-      raise Discourse::InvalidAccess if !guardian.is_user_a_member_of_encrypted_conversation?(topic)
-    end
-    super
-  end
-
   def update
     @topic ||= Topic.find_by(id: params[:topic_id])
 
diff --git a/plugin.rb b/plugin.rb
index 56e92af..3a73a0b 100644
--- a/plugin.rb
+++ b/plugin.rb
@@ -29,7 +29,6 @@ after_initialize do
   load File.expand_path('../lib/post_extensions.rb', __FILE__)
   load File.expand_path('../lib/topic_extensions.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('../app/mailers/user_notifications_extensions.rb', __FILE__)
@@ -52,13 +51,12 @@ after_initialize do
   end
 
   reloadable_patch do |plugin|
-    Post.class_eval                  { prepend PostExtensions }
-    Topic.class_eval                 { prepend TopicExtensions }
-    TopicsController.class_eval      { prepend TopicsControllerExtensions }
-    PostActionsController.class_eval { prepend PostActionsControllerExtensions }
-    User.class_eval                  { prepend UserExtensions }
-    Email::Sender.class_eval         { prepend EmailSenderExtensions }
-    UserNotifications.class_eval     { prepend UserNotificationsExtensions }
+    Post.class_eval              { prepend PostExtensions }
+    Topic.class_eval             { prepend TopicExtensions }
+    TopicsController.class_eval  { prepend TopicsControllerExtensions }
+    User.class_eval              { prepend UserExtensions }
+    Email::Sender.class_eval     { prepend EmailSenderExtensions }
+    UserNotifications.class_eval { prepend UserNotificationsExtensions }
   end
 
   # Send plugin-specific topic data to client via serializers.
@@ -164,15 +162,6 @@ after_initialize do
     object.user_encryption_key&.encrypt_private
   end
 
-  add_to_class(:guardian, :is_user_a_member_of_encrypted_conversation?) do |topic|
-    return false unless topic
-    if SiteSetting.encrypt_enabled? && topic.is_encrypted?
-      authenticated? && topic.all_allowed_users.where(id: @user.id).exists?
-    else
-      true
-    end
-  end
-
   #
   # Hide cooked content.
   #
diff --git a/spec/requests/topics_controller_spec.rb b/spec/requests/topics_controller_spec.rb
index dd9633d..c30350a 100644
--- a/spec/requests/topics_controller_spec.rb
+++ b/spec/requests/topics_controller_spec.rb
@@ -6,12 +6,9 @@ describe TopicsController do
   let(:topic) { Fabricate(:encrypt_topic) }
   let(:user) { Fabricate(:user) }
   let(:group) { Fabricate(:group) }
-  let(:admin) { Fabricate(:admin) }
-  let(:admin2) { Fabricate(:admin) }
 
   before do
-    TopicAllowedUser.create!(user_id: admin.id, topic_id: topic.id)
-    sign_in(admin)
+    sign_in(Fabricate(:admin))
   end
 
   context '#update' do
@@ -23,16 +20,6 @@ describe TopicsController do
     end
   end
 
-  it 'not invited admin does not have access' do
-    sign_in(admin2)
-    get "/t/#{topic.slug}/#{topic.id}.json"
-    expect(response.status).to eq(403)
-
-    TopicAllowedUser.create!(user_id: admin2.id, topic_id: topic.id)
-    get "/t/#{topic.slug}/#{topic.id}.json"
-    expect(response.status).to eq(200)
-  end
-
   context '#invite' do
     it 'saves user key' do
       post "/t/#{topic.id}/invite.json", params: { user: user.username, key: 'key of user' }

GitHub sha: 197239ff

This commit appears in #22 which was merged by lis2.