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.
This commit is contained in:
David Taylor 2021-08-19 13:04:31 +01:00 committed by GitHub
parent ec352a1969
commit 5eb4e642a6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 32 additions and 32 deletions

View File

@ -98,7 +98,7 @@ const Presence = EmberObject.extend({
@discourseComputed("topicId") @discourseComputed("topicId")
channel(topicId) { channel(topicId) {
return `/presence/${topicId}`; return `/presence-plugin/${topicId}`;
}, },
publish(state, whisper, postId, staffOnly) { publish(state, whisper, postId, staffOnly) {
@ -134,7 +134,7 @@ const Presence = EmberObject.extend({
data.staff_only = true; data.staff_only = true;
} }
return ajax("/presence/publish", { return ajax("/presence-plugin/publish", {
type: "POST", type: "POST",
data, data,
}); });

View File

@ -15,7 +15,7 @@ PLUGIN_NAME ||= -"discourse-presence"
after_initialize do 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"] published_at = message.data["published_at"]
if published_at if published_at
@ -146,7 +146,7 @@ after_initialize do
payload[:post_id] = post_id payload[:post_id] = post_id
end end
MessageBus.publish("/presence/#{topic_id}", payload, opts) MessageBus.publish("/presence-plugin/#{topic_id}", payload, opts)
render json: success_json render json: success_json
end end
@ -172,7 +172,7 @@ after_initialize do
end end
Discourse::Application.routes.append do Discourse::Application.routes.append do
mount ::Presence::Engine, at: '/presence' mount ::Presence::Engine, at: '/presence-plugin'
end end
end end

View File

@ -6,7 +6,7 @@ describe ::Presence::PresencesController do
describe '#handle_message' do describe '#handle_message' do
context 'when not logged in' do context 'when not logged in' do
it 'should raise the right error' do it 'should raise the right error' do
post '/presence/publish.json' post '/presence-plugin/publish.json'
expect(response.status).to eq(403) expect(response.status).to eq(403)
end end
@ -40,7 +40,7 @@ describe ::Presence::PresencesController do
it 'returns the right response when user disables the presence feature' do it 'returns the right response when user disables the presence feature' do
user.user_option.update_column(:hide_profile_and_presence, true) 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) expect(response.status).to eq(404)
end end
@ -49,7 +49,7 @@ describe ::Presence::PresencesController do
user.user_option.update_column(:hide_profile_and_presence, true) user.user_option.update_column(:hide_profile_and_presence, true)
SiteSetting.allow_users_to_hide_profile = false 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) expect(response.status).to eq(200)
end end
@ -57,19 +57,19 @@ describe ::Presence::PresencesController do
it 'returns the right response when the presence site settings is disabled' do it 'returns the right response when the presence site settings is disabled' do
SiteSetting.presence_enabled = false SiteSetting.presence_enabled = false
post '/presence/publish.json' post '/presence-plugin/publish.json'
expect(response.status).to eq(404) expect(response.status).to eq(404)
end end
it 'returns the right response if required params are missing' do 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) expect(response.status).to eq(400)
end end
it 'returns the right response if topic_id is invalid' do 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) expect(response.status).to eq(400)
end end
@ -77,13 +77,13 @@ describe ::Presence::PresencesController do
it 'returns the right response when user does not have access to the topic' do it 'returns the right response when user does not have access to the topic' do
group.remove(user) 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) expect(response.status).to eq(403)
end end
it 'returns the right response when an invalid state is provided with a post_id' do 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, topic_id: public_topic.id,
post_id: public_topic.first_post.id, post_id: public_topic.first_post.id,
state: 'some state' state: 'some state'
@ -95,7 +95,7 @@ describe ::Presence::PresencesController do
it 'returns the right response when user can not edit a post' do it 'returns the right response when user can not edit a post' do
Fabricate(:post, topic: private_topic, user: private_topic.user) 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, topic_id: private_topic.id,
post_id: private_topic.first_post.id, post_id: private_topic.first_post.id,
state: 'editing' state: 'editing'
@ -105,7 +105,7 @@ describe ::Presence::PresencesController do
end end
it 'returns the right response when an invalid post_id is given' do 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, topic_id: public_topic.id,
post_id: -9, post_id: -9,
state: 'editing' state: 'editing'
@ -118,7 +118,7 @@ describe ::Presence::PresencesController do
freeze_time freeze_time
messages = MessageBus.track_publish do 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) expect(response.status).to eq(200)
end end
@ -127,7 +127,7 @@ describe ::Presence::PresencesController do
message = messages.first 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.dig(:user, :id)).to eq(user.id)
expect(message.data[:published_at]).to eq(Time.zone.now.to_i) expect(message.data[:published_at]).to eq(Time.zone.now.to_i)
expect(message.group_ids).to eq(nil) expect(message.group_ids).to eq(nil)
@ -138,7 +138,7 @@ describe ::Presence::PresencesController do
freeze_time freeze_time
messages = MessageBus.track_publish do messages = MessageBus.track_publish do
post '/presence/publish.json', params: { post '/presence-plugin/publish.json', params: {
topic_id: private_topic.id, topic_id: private_topic.id,
state: 'replying' state: 'replying'
} }
@ -150,7 +150,7 @@ describe ::Presence::PresencesController do
message = messages.first 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.dig(:user, :id)).to eq(user.id)
expect(message.data[:published_at]).to eq(Time.zone.now.to_i) expect(message.data[:published_at]).to eq(Time.zone.now.to_i)
expect(message.group_ids).to contain_exactly(group.id) 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 it 'publishes the right message for a private message' do
messages = MessageBus.track_publish do messages = MessageBus.track_publish do
post '/presence/publish.json', params: { post '/presence-plugin/publish.json', params: {
topic_id: private_message.id, topic_id: private_message.id,
state: 'replying' state: 'replying'
} }
@ -185,7 +185,7 @@ describe ::Presence::PresencesController do
SiteSetting.enable_whispers = true SiteSetting.enable_whispers = true
messages = MessageBus.track_publish do messages = MessageBus.track_publish do
post '/presence/publish.json', params: { post '/presence-plugin/publish.json', params: {
topic_id: public_topic.id, topic_id: public_topic.id,
state: 'replying', state: 'replying',
is_whisper: true is_whisper: true
@ -204,7 +204,7 @@ describe ::Presence::PresencesController do
it 'publishes the message to staff group when staff_only param override is present' do it 'publishes the message to staff group when staff_only param override is present' do
messages = MessageBus.track_publish do messages = MessageBus.track_publish do
post '/presence/publish.json', params: { post '/presence-plugin/publish.json', params: {
topic_id: public_topic.id, topic_id: public_topic.id,
state: 'replying', state: 'replying',
staff_only: true staff_only: true
@ -226,7 +226,7 @@ describe ::Presence::PresencesController do
sign_in(admin) sign_in(admin)
messages = MessageBus.track_publish do messages = MessageBus.track_publish do
post '/presence/publish.json', params: { post '/presence-plugin/publish.json', params: {
topic_id: public_topic.id, topic_id: public_topic.id,
post_id: public_topic.first_post.id, post_id: public_topic.first_post.id,
state: 'editing', state: 'editing',
@ -250,7 +250,7 @@ describe ::Presence::PresencesController do
locked_post = Fabricate(:post, topic: public_topic, locked_by_id: admin.id) locked_post = Fabricate(:post, topic: public_topic, locked_by_id: admin.id)
messages = MessageBus.track_publish do messages = MessageBus.track_publish do
post '/presence/publish.json', params: { post '/presence-plugin/publish.json', params: {
topic_id: public_topic.id, topic_id: public_topic.id,
post_id: locked_post.id, post_id: locked_post.id,
state: 'editing', state: 'editing',
@ -271,7 +271,7 @@ describe ::Presence::PresencesController do
post = Fabricate(:post, topic: public_topic, user: user) post = Fabricate(:post, topic: public_topic, user: user)
messages = MessageBus.track_publish do messages = MessageBus.track_publish do
post '/presence/publish.json', params: { post '/presence-plugin/publish.json', params: {
topic_id: public_topic.id, topic_id: public_topic.id,
post_id: post.id, post_id: post.id,
state: 'editing', state: 'editing',
@ -299,7 +299,7 @@ describe ::Presence::PresencesController do
SiteSetting.trusted_users_can_edit_others = false SiteSetting.trusted_users_can_edit_others = false
messages = MessageBus.track_publish do messages = MessageBus.track_publish do
post '/presence/publish.json', params: { post '/presence-plugin/publish.json', params: {
topic_id: public_topic.id, topic_id: public_topic.id,
post_id: post.id, post_id: post.id,
state: 'editing', state: 'editing',
@ -323,7 +323,7 @@ describe ::Presence::PresencesController do
SiteSetting.min_trust_to_edit_wiki_post = TrustLevel.levels[:basic] SiteSetting.min_trust_to_edit_wiki_post = TrustLevel.levels[:basic]
messages = MessageBus.track_publish do messages = MessageBus.track_publish do
post '/presence/publish.json', params: { post '/presence-plugin/publish.json', params: {
topic_id: public_topic.id, topic_id: public_topic.id,
post_id: post.id, post_id: post.id,
state: 'editing', state: 'editing',
@ -348,7 +348,7 @@ describe ::Presence::PresencesController do
post = Fabricate(:post, topic: private_message, user: user) post = Fabricate(:post, topic: private_message, user: user)
messages = MessageBus.track_publish do messages = MessageBus.track_publish do
post '/presence/publish.json', params: { post '/presence-plugin/publish.json', params: {
topic_id: private_message.id, topic_id: private_message.id,
post_id: post.id, post_id: post.id,
state: 'editing', state: 'editing',
@ -383,7 +383,7 @@ describe ::Presence::PresencesController do
SiteSetting.min_trust_to_edit_wiki_post = TrustLevel.levels[:basic] SiteSetting.min_trust_to_edit_wiki_post = TrustLevel.levels[:basic]
messages = MessageBus.track_publish do messages = MessageBus.track_publish do
post '/presence/publish.json', params: { post '/presence-plugin/publish.json', params: {
topic_id: private_message.id, topic_id: private_message.id,
post_id: post.id, post_id: post.id,
state: 'editing', state: 'editing',
@ -408,7 +408,7 @@ describe ::Presence::PresencesController do
it 'publishes the right message when closing composer in public topic' do it 'publishes the right message when closing composer in public topic' do
messages = MessageBus.track_publish do messages = MessageBus.track_publish do
post '/presence/publish.json', params: { post '/presence-plugin/publish.json', params: {
topic_id: public_topic.id, topic_id: public_topic.id,
state: described_class::CLOSED_STATE, state: described_class::CLOSED_STATE,
} }
@ -426,7 +426,7 @@ describe ::Presence::PresencesController do
it 'publishes the right message when closing composer in private topic' do it 'publishes the right message when closing composer in private topic' do
messages = MessageBus.track_publish do messages = MessageBus.track_publish do
post '/presence/publish.json', params: { post '/presence-plugin/publish.json', params: {
topic_id: private_topic.id, topic_id: private_topic.id,
state: described_class::CLOSED_STATE, state: described_class::CLOSED_STATE,
} }
@ -446,7 +446,7 @@ describe ::Presence::PresencesController do
post = Fabricate(:post, topic: private_message, user: user) post = Fabricate(:post, topic: private_message, user: user)
messages = MessageBus.track_publish do messages = MessageBus.track_publish do
post '/presence/publish.json', params: { post '/presence-plugin/publish.json', params: {
topic_id: private_message.id, topic_id: private_message.id,
state: described_class::CLOSED_STATE, state: described_class::CLOSED_STATE,
} }