FEATURE: Display link with count to user's assigned messages page.
This commit is contained in:
parent
3905f8f992
commit
22108df6be
|
@ -1,11 +1,18 @@
|
||||||
{{#if canUnassignAll}}
|
<div class='assign-controls'>
|
||||||
<div class='assign-controls'>
|
{{#if model.topic_list.assigned_messages_count}}
|
||||||
|
{{#link-to 'userPrivateMessages.assigned' user.model class="btn assign-messages-assigned"}}
|
||||||
|
{{d-icon "envelope" class="glyph"}}
|
||||||
|
{{i18n 'user.messages.assigned_title' count=model.topic_list.assigned_messages_count}}
|
||||||
|
{{/link-to}}
|
||||||
|
{{/if}}
|
||||||
|
|
||||||
|
{{#if canUnassignAll}}
|
||||||
{{d-button
|
{{d-button
|
||||||
action=(action "unassignAll")
|
action=(action "unassignAll")
|
||||||
icon="times"
|
icon="times"
|
||||||
label="discourse_assign.unassign_all.title"
|
label="discourse_assign.unassign_all.title"
|
||||||
class="btn-danger"}}
|
class="btn-danger"}}
|
||||||
</div>
|
{{/if}}
|
||||||
{{/if}}
|
</div>
|
||||||
|
|
||||||
{{outlet}}
|
{{outlet}}
|
||||||
|
|
|
@ -3,6 +3,10 @@
|
||||||
display: flex;
|
display: flex;
|
||||||
justify-content: flex-end;
|
justify-content: flex-end;
|
||||||
margin-bottom: 0.5em;
|
margin-bottom: 0.5em;
|
||||||
|
|
||||||
|
.assign-messages-assigned {
|
||||||
|
margin-right: 0.5em;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -28,4 +28,5 @@ en:
|
||||||
help: "Assign topic to yourself"
|
help: "Assign topic to yourself"
|
||||||
user:
|
user:
|
||||||
messages:
|
messages:
|
||||||
|
assigned_title: "Assigned Messages (%{count})"
|
||||||
assigned: "Assigned"
|
assigned: "Assigned"
|
||||||
|
|
32
plugin.rb
32
plugin.rb
|
@ -123,13 +123,21 @@ after_initialize do
|
||||||
end
|
end
|
||||||
|
|
||||||
add_to_class(:topic_query, :list_private_messages_assigned) do |user|
|
add_to_class(:topic_query, :list_private_messages_assigned) do |user|
|
||||||
list = private_messages_for(user, :all)
|
list = private_messages_assigned_query(user)
|
||||||
list = list.where("topics.id IN (
|
|
||||||
SELECT topic_id FROM topic_custom_fields WHERE name = 'assigned_to_id' AND value = ?
|
|
||||||
)", user.id.to_s)
|
|
||||||
create_list(:private_messages, {}, list)
|
create_list(:private_messages, {}, list)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
add_to_class(:topic_query, :private_messages_assigned_query) do |user|
|
||||||
|
list = private_messages_for(user, :all)
|
||||||
|
|
||||||
|
list = list.where("
|
||||||
|
topics.id IN (
|
||||||
|
SELECT topic_id FROM topic_custom_fields
|
||||||
|
WHERE name = 'assigned_to_id'
|
||||||
|
AND value = ?)
|
||||||
|
", user.id.to_s)
|
||||||
|
end
|
||||||
|
|
||||||
add_to_class(:topic, :assigned_to_user) do
|
add_to_class(:topic, :assigned_to_user) do
|
||||||
@assigned_to_user ||
|
@assigned_to_user ||
|
||||||
if user_id = custom_fields["assigned_to_id"]
|
if user_id = custom_fields["assigned_to_id"]
|
||||||
|
@ -145,6 +153,22 @@ after_initialize do
|
||||||
(SiteSetting.assigns_public || scope.is_staff?) && object.assigned_to_user
|
(SiteSetting.assigns_public || scope.is_staff?) && object.assigned_to_user
|
||||||
end
|
end
|
||||||
|
|
||||||
|
add_to_serializer(:topic_list, :assigned_messages_count) do
|
||||||
|
TopicQuery.new(object.current_user, guardian: scope, limit: false)
|
||||||
|
.private_messages_assigned_query(object.current_user)
|
||||||
|
.count
|
||||||
|
end
|
||||||
|
|
||||||
|
add_to_serializer(:topic_list, 'include_assigned_messages_count?') do
|
||||||
|
return unless SiteSetting.assigns_public
|
||||||
|
options = object.instance_variable_get(:@opts)
|
||||||
|
|
||||||
|
if assigned_username = options[:assigned]&.downcase
|
||||||
|
assigned_username == object.current_user&.username_lower
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
add_to_serializer(:topic_view, :assigned_to_user, false) do
|
add_to_serializer(:topic_view, :assigned_to_user, false) do
|
||||||
DiscourseAssign::Helpers.build_assigned_to_user(assigned_to_user_id, object.topic)
|
DiscourseAssign::Helpers.build_assigned_to_user(assigned_to_user_id, object.topic)
|
||||||
end
|
end
|
||||||
|
|
|
@ -0,0 +1,60 @@
|
||||||
|
require 'rails_helper'
|
||||||
|
|
||||||
|
RSpec.describe TopicListSerializer do
|
||||||
|
let(:user) { Fabricate(:user) }
|
||||||
|
|
||||||
|
let(:private_message_topic) do
|
||||||
|
Fabricate(:private_message_topic,
|
||||||
|
posts: [Fabricate(:post)],
|
||||||
|
topic_allowed_users: [
|
||||||
|
Fabricate.build(:topic_allowed_user, user: user)
|
||||||
|
]
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
let(:assigned_topic) do
|
||||||
|
topic = Fabricate(:private_message_topic,
|
||||||
|
posts: [Fabricate(:post)],
|
||||||
|
topic_allowed_users: [
|
||||||
|
Fabricate.build(:topic_allowed_user, user: user)
|
||||||
|
]
|
||||||
|
)
|
||||||
|
|
||||||
|
TopicAssigner.new(topic, user).assign(user)
|
||||||
|
topic
|
||||||
|
end
|
||||||
|
|
||||||
|
let(:guardian) { Guardian.new(user) }
|
||||||
|
let(:serializer) { TopicListSerializer.new(topic_list, scope: guardian) }
|
||||||
|
|
||||||
|
before do
|
||||||
|
SiteSetting.assign_enabled = true
|
||||||
|
SiteSetting.assigns_public = true
|
||||||
|
end
|
||||||
|
|
||||||
|
describe '#assigned_messages_count' do
|
||||||
|
let(:topic_list) do
|
||||||
|
TopicQuery.new(user, assigned: user.username).list_private_messages_assigned(user)
|
||||||
|
end
|
||||||
|
|
||||||
|
before do
|
||||||
|
assigned_topic
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should include right attribute' do
|
||||||
|
expect(serializer.as_json[:topic_list][:assigned_messages_count])
|
||||||
|
.to eq(1)
|
||||||
|
end
|
||||||
|
|
||||||
|
describe 'when assigns are not public' do
|
||||||
|
before do
|
||||||
|
SiteSetting.assigns_public = false
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should not include the attributes' do
|
||||||
|
expect(serializer.as_json[:topic_list][:assigned_messages_count])
|
||||||
|
.to eq(nil)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in New Issue