DEV: Rename discourse-presence endpoints and messagebus channels (#14089)

DEV: Rename discourse-presence endpoints and messagebus channels (#14089)

We are working to introduce a general core API for presence, which will clash with this plugin’s /presence namespace

This commit introduces no functional change. There may be a slight interruption in discourse-presence functionality during a deploy of this commit.

diff --git a/plugins/discourse-presence/assets/javascripts/discourse/lib/presence.js.es6 b/plugins/discourse-presence/assets/javascripts/discourse/lib/presence.js.es6
index 2146ce5..7db5048 100644
--- a/plugins/discourse-presence/assets/javascripts/discourse/lib/presence.js.es6
+++ b/plugins/discourse-presence/assets/javascripts/discourse/lib/presence.js.es6
@@ -98,7 +98,7 @@ const Presence = EmberObject.extend({
 
   @discourseComputed("topicId")
   channel(topicId) {
-    return `/presence/${topicId}`;
+    return `/presence-plugin/${topicId}`;
   },
 
   publish(state, whisper, postId, staffOnly) {
@@ -134,7 +134,7 @@ const Presence = EmberObject.extend({
       data.staff_only = true;
     }
 
-    return ajax("/presence/publish", {
+    return ajax("/presence-plugin/publish", {
       type: "POST",
       data,
     });
diff --git a/plugins/discourse-presence/plugin.rb b/plugins/discourse-presence/plugin.rb
index a61d97e..d20f4a2 100644
--- a/plugins/discourse-presence/plugin.rb
+++ b/plugins/discourse-presence/plugin.rb
@@ -15,7 +15,7 @@ PLUGIN_NAME ||= -"discourse-presence"
 
 after_initialize do
 
-  MessageBus.register_client_message_filter('/presence/') do |message|
+  MessageBus.register_client_message_filter('/presence-plugin/') do |message|
     published_at = message.data["published_at"]
 
     if published_at
@@ -146,7 +146,7 @@ after_initialize do
         payload[:post_id] = post_id
       end
 
-      MessageBus.publish("/presence/#{topic_id}", payload, opts)
+      MessageBus.publish("/presence-plugin/#{topic_id}", payload, opts)
 
       render json: success_json
     end
@@ -172,7 +172,7 @@ after_initialize do
   end
 
   Discourse::Application.routes.append do
-    mount ::Presence::Engine, at: '/presence'
+    mount ::Presence::Engine, at: '/presence-plugin'
   end
 
 end
diff --git a/plugins/discourse-presence/spec/requests/presence_controller_spec.rb b/plugins/discourse-presence/spec/requests/presence_controller_spec.rb
index 9f374db..adedede 100644
--- a/plugins/discourse-presence/spec/requests/presence_controller_spec.rb
+++ b/plugins/discourse-presence/spec/requests/presence_controller_spec.rb
@@ -6,7 +6,7 @@ describe ::Presence::PresencesController do
   describe '#handle_message' do
     context 'when not logged in' do
       it 'should raise the right error' do
-        post '/presence/publish.json'
+        post '/presence-plugin/publish.json'
 
         expect(response.status).to eq(403)
       end
@@ -40,7 +40,7 @@ describe ::Presence::PresencesController do
       it 'returns the right response when user disables the presence feature' do
         user.user_option.update_column(:hide_profile_and_presence, true)
 
-        post '/presence/publish.json'
+        post '/presence-plugin/publish.json'
 
         expect(response.status).to eq(404)
       end
@@ -49,7 +49,7 @@ describe ::Presence::PresencesController do
         user.user_option.update_column(:hide_profile_and_presence, true)
         SiteSetting.allow_users_to_hide_profile = false
 
-        post '/presence/publish.json', params: { topic_id: public_topic.id, state: 'replying' }
+        post '/presence-plugin/publish.json', params: { topic_id: public_topic.id, state: 'replying' }
 
         expect(response.status).to eq(200)
       end
@@ -57,19 +57,19 @@ describe ::Presence::PresencesController do
       it 'returns the right response when the presence site settings is disabled' do
         SiteSetting.presence_enabled = false
 
-        post '/presence/publish.json'
+        post '/presence-plugin/publish.json'
 
         expect(response.status).to eq(404)
       end
 
       it 'returns the right response if required params are missing' do
-        post '/presence/publish.json'
+        post '/presence-plugin/publish.json'
 
         expect(response.status).to eq(400)
       end
 
       it 'returns the right response if topic_id is invalid' do
-        post '/presence/publish.json', params: { topic_id: -999, state: 'replying' }
+        post '/presence-plugin/publish.json', params: { topic_id: -999, state: 'replying' }
 
         expect(response.status).to eq(400)
       end
@@ -77,13 +77,13 @@ describe ::Presence::PresencesController do
       it 'returns the right response when user does not have access to the topic' do
         group.remove(user)
 
-        post '/presence/publish.json', params: { topic_id: private_topic.id, state: 'replying' }
+        post '/presence-plugin/publish.json', params: { topic_id: private_topic.id, state: 'replying' }
 
         expect(response.status).to eq(403)
       end
 
       it 'returns the right response when an invalid state is provided with a post_id' do
-        post '/presence/publish.json', params: {
+        post '/presence-plugin/publish.json', params: {
           topic_id: public_topic.id,
           post_id: public_topic.first_post.id,
           state: 'some state'
@@ -95,7 +95,7 @@ describe ::Presence::PresencesController do
       it 'returns the right response when user can not edit a post' do
         Fabricate(:post, topic: private_topic, user: private_topic.user)
 
-        post '/presence/publish.json', params: {
+        post '/presence-plugin/publish.json', params: {
           topic_id: private_topic.id,
           post_id: private_topic.first_post.id,
           state: 'editing'
@@ -105,7 +105,7 @@ describe ::Presence::PresencesController do
       end
 
       it 'returns the right response when an invalid post_id is given' do
-        post '/presence/publish.json', params: {
+        post '/presence-plugin/publish.json', params: {
           topic_id: public_topic.id,
           post_id: -9,
           state: 'editing'
@@ -118,7 +118,7 @@ describe ::Presence::PresencesController do
         freeze_time
 
         messages = MessageBus.track_publish do
-          post '/presence/publish.json', params: { topic_id: public_topic.id, state: 'replying' }
+          post '/presence-plugin/publish.json', params: { topic_id: public_topic.id, state: 'replying' }
 
           expect(response.status).to eq(200)
         end
@@ -127,7 +127,7 @@ describe ::Presence::PresencesController do
 
         message = messages.first
 
-        expect(message.channel).to eq("/presence/#{public_topic.id}")
+        expect(message.channel).to eq("/presence-plugin/#{public_topic.id}")
         expect(message.data.dig(:user, :id)).to eq(user.id)
         expect(message.data[:published_at]).to eq(Time.zone.now.to_i)
         expect(message.group_ids).to eq(nil)
@@ -138,7 +138,7 @@ describe ::Presence::PresencesController do
         freeze_time
 
         messages = MessageBus.track_publish do
-          post '/presence/publish.json', params: {
+          post '/presence-plugin/publish.json', params: {
             topic_id: private_topic.id,
             state: 'replying'
           }
@@ -150,7 +150,7 @@ describe ::Presence::PresencesController do
 
         message = messages.first
 
-        expect(message.channel).to eq("/presence/#{private_topic.id}")
+        expect(message.channel).to eq("/presence-plugin/#{private_topic.id}")
         expect(message.data.dig(:user, :id)).to eq(user.id)
         expect(message.data[:published_at]).to eq(Time.zone.now.to_i)
         expect(message.group_ids).to contain_exactly(group.id)
@@ -159,7 +159,7 @@ describe ::Presence::PresencesController do
 
       it 'publishes the right message for a private message' do
         messages = MessageBus.track_publish do
-          post '/presence/publish.json', params: {
+          post '/presence-plugin/publish.json', params: {
             topic_id: private_message.id,
             state: 'replying'
           }
@@ -185,7 +185,7 @@ describe ::Presence::PresencesController do
         SiteSetting.enable_whispers = true
 
         messages = MessageBus.track_publish do
-          post '/presence/publish.json', params: {
+          post '/presence-plugin/publish.json', params: {
             topic_id: public_topic.id,

[... diff too long, it was truncated ...]

GitHub sha: 5eb4e642a6c5e0ccb73ef00abc4258e02c6df80c

This commit appears in #14089 which was approved by CvX. It was merged by davidtaylorhq.