DEV: Refactoring.

DEV: Refactoring.

From 10e9a8d36363d13eb8ed74ac75e1f6ef05493351 Mon Sep 17 00:00:00 2001
From: Dan Ungureanu <dan@ungureanu.me>
Date: Tue, 4 Dec 2018 19:54:13 +0200
Subject: [PATCH] DEV: Refactoring.


diff --git a/assets/javascripts/discourse/initializers/hook-invite.js.es6 b/assets/javascripts/discourse/initializers/hook-invite.js.es6
index 1094920..dd8b11e 100644
--- a/assets/javascripts/discourse/initializers/hook-invite.js.es6
+++ b/assets/javascripts/discourse/initializers/hook-invite.js.es6
@@ -72,7 +72,7 @@ export default {
 
         return ajax("/encrypt/topic", {
           type: "DELETE",
-          data: { topic_id: topic.get("id"), users: [user.username] }
+          data: { topic_id: topic.get("id"), usernames: [user.username] }
         }).then(() => _super.call(this, ...arguments));
       }
     });
diff --git a/plugin.rb b/plugin.rb
index fdf2568..6f67817 100644
--- a/plugin.rb
+++ b/plugin.rb
@@ -113,12 +113,17 @@ after_initialize do
       # +usernames+::   Array of usernames.
       def topic_delete
         topic_id = params.require(:topic_id)
-        usernames = params.require(:users)
+        usernames = params.require(:usernames)
 
-        users = Hash[User.where(username: usernames).map { |u| [u.username, u] }]
-        usernames.each { |u| Store.remove("key_#{topic_id}_#{users[u].id}") }
+        topic = Topic.find_by(id: topic_id)
+        if !Guardian.new(current_user).can_see_topic?(topic)
+          return render json: failed_json
+        end
+
+        users = User.where(username: usernames)
+        users.each { |u| Store.remove("key_#{topic_id}_#{u.id}") }
 
-        render json: { success: true }
+        render json: success_json
       end
     end
   end

GitHub

1 Like