mirror of
https://github.com/discourse/discourse.git
synced 2024-11-26 04:56:18 +08:00
FEATURE: Introduce a staff only override key for discourse-presence.
Merge remote-tracking branch 'origin/coding-standards' This uses the composer as a bridge for other plugins.
This commit is contained in:
parent
7f841dc21f
commit
623920f13d
|
@ -17,36 +17,30 @@ import { REPLY, EDIT } from "discourse/models/composer";
|
|||
|
||||
export default Component.extend({
|
||||
// Passed in variables
|
||||
action: null,
|
||||
post: null,
|
||||
topic: null,
|
||||
reply: null,
|
||||
title: null,
|
||||
isWhispering: null,
|
||||
presenceManager: service(),
|
||||
|
||||
@discourseComputed("topic.id")
|
||||
@discourseComputed("model.topic.id")
|
||||
users(topicId) {
|
||||
return this.presenceManager.users(topicId);
|
||||
},
|
||||
|
||||
@discourseComputed("topic.id")
|
||||
@discourseComputed("model.topic.id")
|
||||
editingUsers(topicId) {
|
||||
return this.presenceManager.editingUsers(topicId);
|
||||
},
|
||||
|
||||
isReply: equal("action", REPLY),
|
||||
isReply: equal("model.action", REPLY),
|
||||
|
||||
@on("didInsertElement")
|
||||
subscribe() {
|
||||
this.presenceManager.subscribe(this.get("topic.id"), COMPOSER_TYPE);
|
||||
this.presenceManager.subscribe(this.get("model.topic.id"), COMPOSER_TYPE);
|
||||
},
|
||||
|
||||
@discourseComputed(
|
||||
"post.id",
|
||||
"model.post.id",
|
||||
"editingUsers.@each.last_seen",
|
||||
"users.@each.last_seen",
|
||||
"action"
|
||||
"model.action"
|
||||
)
|
||||
presenceUsers(postId, editingUsers, users, action) {
|
||||
if (action === EDIT) {
|
||||
|
@ -59,23 +53,24 @@ export default Component.extend({
|
|||
|
||||
shouldDisplay: gt("presenceUsers.length", 0),
|
||||
|
||||
@observes("reply", "title")
|
||||
@observes("model.reply", "model.title")
|
||||
typing() {
|
||||
throttle(this, this._typing, KEEP_ALIVE_DURATION_SECONDS * 1000);
|
||||
},
|
||||
|
||||
_typing() {
|
||||
const action = this.action;
|
||||
const action = this.get("model.action");
|
||||
|
||||
if (action !== REPLY && action !== EDIT) {
|
||||
return;
|
||||
}
|
||||
|
||||
let data = {
|
||||
topicId: this.get("topic.id"),
|
||||
topicId: this.get("model.topic.id"),
|
||||
state: action === EDIT ? EDITING : REPLYING,
|
||||
whisper: this.whisper,
|
||||
postId: this.get("post.id")
|
||||
whisper: this.get("model.whisper"),
|
||||
postId: this.get("model.post.id"),
|
||||
presenceStaffOnly: this.get("model._presenceStaffOnly")
|
||||
};
|
||||
|
||||
this._prevPublishData = data;
|
||||
|
@ -84,16 +79,17 @@ export default Component.extend({
|
|||
data.topicId,
|
||||
data.state,
|
||||
data.whisper,
|
||||
data.postId
|
||||
data.postId,
|
||||
data.presenceStaffOnly
|
||||
);
|
||||
},
|
||||
|
||||
@observes("whisper")
|
||||
@observes("model.whisper")
|
||||
cancelThrottle() {
|
||||
this._cancelThrottle();
|
||||
},
|
||||
|
||||
@observes("action", "topic.id")
|
||||
@observes("model.action", "model.topic.id")
|
||||
composerState() {
|
||||
if (this._prevPublishData) {
|
||||
this.presenceManager.publish(
|
||||
|
|
|
@ -99,7 +99,7 @@ const Presence = EmberObject.extend({
|
|||
return `/presence/${topicId}`;
|
||||
},
|
||||
|
||||
publish(state, whisper, postId) {
|
||||
publish(state, whisper, postId, staffOnly) {
|
||||
if (this.get("currentUser.hide_profile_and_presence")) return;
|
||||
|
||||
const data = {
|
||||
|
@ -108,13 +108,17 @@ const Presence = EmberObject.extend({
|
|||
};
|
||||
|
||||
if (whisper) {
|
||||
data.is_whisper = 1;
|
||||
data.is_whisper = true;
|
||||
}
|
||||
|
||||
if (postId && state === EDITING) {
|
||||
data.post_id = postId;
|
||||
}
|
||||
|
||||
if (staffOnly) {
|
||||
data.staff_only = true;
|
||||
}
|
||||
|
||||
return ajax("/presence/publish", {
|
||||
type: "POST",
|
||||
data
|
||||
|
|
|
@ -36,9 +36,14 @@ const PresenceManager = Service.extend({
|
|||
return this._getPresence(topicId).editingUsers;
|
||||
},
|
||||
|
||||
publish(topicId, state, whisper, postId) {
|
||||
publish(topicId, state, whisper, postId, staffOnly) {
|
||||
if (!topicId) return;
|
||||
return this._getPresence(topicId).publish(state, whisper, postId);
|
||||
return this._getPresence(topicId).publish(
|
||||
state,
|
||||
whisper,
|
||||
postId,
|
||||
staffOnly
|
||||
);
|
||||
},
|
||||
|
||||
cleanUpPresence(type) {
|
||||
|
|
|
@ -1,8 +1 @@
|
|||
{{composer-presence-display
|
||||
action=model.action
|
||||
post=model.post
|
||||
topic=model.topic
|
||||
reply=model.reply
|
||||
title=model.title
|
||||
whisper=model.whisper
|
||||
}}
|
||||
{{composer-presence-display model=model}}
|
||||
|
|
|
@ -73,6 +73,9 @@ after_initialize do
|
|||
max_backlog_age: Presence::MAX_BACKLOG_AGE_SECONDS
|
||||
}
|
||||
|
||||
if permitted_params[:staff_only]
|
||||
opts[:group_ids] = [Group::AUTO_GROUPS[:staff]]
|
||||
else
|
||||
case permitted_params[:state]
|
||||
when EDITING_STATE
|
||||
opts[:group_ids] = [Group::AUTO_GROUPS[:staff]]
|
||||
|
@ -130,6 +133,7 @@ after_initialize do
|
|||
opts[:group_ids] = topic.secure_group_ids
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
payload = {
|
||||
user: BasicUserSerializer.new(current_user, root: false).as_json,
|
||||
|
@ -158,7 +162,7 @@ after_initialize do
|
|||
end
|
||||
|
||||
def permitted_params
|
||||
params.permit(:state, :topic_id, :post_id, :is_whisper)
|
||||
params.permit(:state, :topic_id, :post_id, :is_whisper, :staff_only)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -193,6 +193,28 @@ describe ::Presence::PresencesController do
|
|||
expect(message.user_ids).to eq(nil)
|
||||
end
|
||||
|
||||
it 'publishes the message to staff group when staff_only param override is present' do
|
||||
messages = MessageBus.track_publish do
|
||||
post '/presence/publish.json', params: {
|
||||
topic_id: public_topic.id,
|
||||
state: 'replying',
|
||||
staff_only: true
|
||||
}
|
||||
|
||||
expect(response.status).to eq(200)
|
||||
end
|
||||
|
||||
expect(messages.length).to eq(1)
|
||||
|
||||
message = messages.first
|
||||
|
||||
expect(message.channel).to eq("/presence/#{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 contain_exactly(Group::AUTO_GROUPS[:staff])
|
||||
expect(message.user_ids).to eq(nil)
|
||||
end
|
||||
|
||||
it 'publishes the message to staff group when a staff is editing a whisper' do
|
||||
SiteSetting.enable_whispers = true
|
||||
sign_in(admin)
|
||||
|
|
Loading…
Reference in New Issue
Block a user