public and private mode, add customizable user link path
This commit is contained in:
parent
13d070c823
commit
a6861ba65a
|
@ -1,3 +1,3 @@
|
||||||
{{#if context.topic.owner}}
|
{{#if context.topic.assigned_to_user}}
|
||||||
<a class='assigned-to discourse-tag simple' href="{{context.topic.owner.path}}">@{{context.topic.owner.username}}</a>
|
<a class='assigned-to discourse-tag simple' href="{{context.topic.assignedToUserPath}}">@{{context.topic.assigned_to_user.username}}</a>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
{{#unless context.topic.tags}}
|
{{#unless context.topic.tags}}
|
||||||
{{#if context.topic.owner}}
|
|
||||||
|
{{#if context.topic.assigned_to_user}}
|
||||||
<div class='discourse-tags'>
|
<div class='discourse-tags'>
|
||||||
<a class='assigned-to discourse-tag simple' href="{{context.topic.owner.path}}">@{{context.topic.owner.username}}</a>
|
<a class='assigned-to discourse-tag simple' href="{{context.topic.assignedToUserPath}}">@{{context.topic.assigned_to_user.username}}</a>
|
||||||
</div>
|
</div>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
{{/unless}}
|
{{/unless}}
|
||||||
|
|
|
@ -1,6 +1,18 @@
|
||||||
import { withPluginApi } from 'discourse/lib/plugin-api';
|
import { withPluginApi } from 'discourse/lib/plugin-api';
|
||||||
|
|
||||||
function initialize(api) {
|
// should this be in API ?
|
||||||
|
import Topic from 'discourse/models/topic';
|
||||||
|
|
||||||
|
function initialize(api, container) {
|
||||||
|
|
||||||
|
const siteSettings = container.lookup('site-settings:main');
|
||||||
|
|
||||||
|
Topic.reopen({
|
||||||
|
assignedToUserPath: function(){
|
||||||
|
return siteSettings.assigns_user_url_path.replace("{username}", this.get("assigned_to_user.username"));
|
||||||
|
}.property('owner')
|
||||||
|
});
|
||||||
|
|
||||||
api.addPostSmallActionIcon('assigned','user-plus');
|
api.addPostSmallActionIcon('assigned','user-plus');
|
||||||
|
|
||||||
api.decorateWidget('post-contents:after-cooked', dec => {
|
api.decorateWidget('post-contents:after-cooked', dec => {
|
||||||
|
@ -9,18 +21,22 @@ function initialize(api) {
|
||||||
if (postModel) {
|
if (postModel) {
|
||||||
const assignedToUser = postModel.get('topic.assigned_to_user');
|
const assignedToUser = postModel.get('topic.assigned_to_user');
|
||||||
if (assignedToUser) {
|
if (assignedToUser) {
|
||||||
const html = I18n.t('discourse_assign.assign_html', assignedToUser);
|
const path = postModel.get('topic.assignedToUserPath');
|
||||||
//const topic = postModel.get('topic');
|
const userLink = `<a href='${path}'>${assignedToUser.username}</a>`;
|
||||||
|
const html = I18n.t('discourse_assign.assign_html', {userLink});
|
||||||
return dec.rawHtml(html);
|
return dec.rawHtml(html);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'extend-for-assign',
|
name: 'extend-for-assign',
|
||||||
initialize() {
|
initialize(container) {
|
||||||
withPluginApi('0.8', initialize);
|
withPluginApi('0.8', api => {
|
||||||
|
initialize(api, container);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -3,7 +3,7 @@ en:
|
||||||
action_codes:
|
action_codes:
|
||||||
assigned: "assigned"
|
assigned: "assigned"
|
||||||
discourse_assign:
|
discourse_assign:
|
||||||
assign_html: "<p class='assigned-to'>Assigned to: @{{username}}</p>"
|
assign_html: "<p class='assigned-to'><i class='fa-user-plus fa'></i> Assigned to {{userLink}}</p>"
|
||||||
assign_notification: "<i title='assigned' class='fa fa-user-plus'></i><p><span>{{username}}</span> {{description}}</p>"
|
assign_notification: "<i title='assigned' class='fa fa-user-plus'></i><p><span>{{username}}</span> {{description}}</p>"
|
||||||
assign:
|
assign:
|
||||||
title: "Assign"
|
title: "Assign"
|
||||||
|
|
|
@ -1,3 +1,6 @@
|
||||||
en:
|
en:
|
||||||
|
site_settings:
|
||||||
|
assigns_public: "Allow general public to see topic assignments"
|
||||||
|
assigns_user_url_path: "Path to link all user links for assigned (use: {username} to subtitue username)"
|
||||||
discourse_assign:
|
discourse_assign:
|
||||||
assigned_to: "Topic assigned to @%{username}"
|
assigned_to: "Topic assigned to @%{username}"
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
plugins:
|
||||||
|
assigns_public: false
|
||||||
|
assigns_user_url_path:
|
||||||
|
client: true
|
||||||
|
default: "/latest?assigned={username}"
|
33
plugin.rb
33
plugin.rb
|
@ -40,11 +40,13 @@ after_initialize do
|
||||||
target_post_id: topic.posts.find_by(post_number: 1).id,
|
target_post_id: topic.posts.find_by(post_number: 1).id,
|
||||||
target_topic_id: topic.id)
|
target_topic_id: topic.id)
|
||||||
|
|
||||||
|
post_type = SiteSetting.assigns_public ? Post.types[:small_action] : Post.types[:whisper]
|
||||||
|
|
||||||
topic.add_moderator_post(current_user,
|
topic.add_moderator_post(current_user,
|
||||||
I18n.t('discourse_assign.assigned_to',
|
I18n.t('discourse_assign.assigned_to',
|
||||||
username: assign_to.username),
|
username: assign_to.username),
|
||||||
{ bump: false,
|
{ bump: false,
|
||||||
post_type: Post.types[:small_action],
|
post_type: post_type,
|
||||||
action_code: "assigned"})
|
action_code: "assigned"})
|
||||||
|
|
||||||
unless false && current_user.id == assign_to.id
|
unless false && current_user.id == assign_to.id
|
||||||
|
@ -67,22 +69,25 @@ after_initialize do
|
||||||
end
|
end
|
||||||
|
|
||||||
class ::Topic
|
class ::Topic
|
||||||
def owner
|
def assigned_to_user
|
||||||
@owner ||
|
@assigned_to_user ||
|
||||||
if user_id = custom_fields["assigned_to_id"]
|
if user_id = custom_fields["assigned_to_id"]
|
||||||
@owner = User.find_by(id: user_id)
|
@assigned_to_user = User.find_by(id: user_id)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def preload_owner(owner)
|
def preload_assigned_to_user(assigned_to_user)
|
||||||
@owner = owner
|
@assigned_to_user = assigned_to_user
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
TopicList.preloaded_custom_fields << "assigned_to_id"
|
TopicList.preloaded_custom_fields << "assigned_to_id"
|
||||||
|
|
||||||
TopicList.on_preload do |topics|
|
TopicList.on_preload do |topics, topic_list|
|
||||||
if topics.length > 0
|
is_staff = topic_list.current_user && topic_list.current_user.staff?
|
||||||
|
allowed_access = SiteSetting.assigns_public || is_staff
|
||||||
|
|
||||||
|
if allowed_access && topics.length > 0
|
||||||
users = User.where("id in (
|
users = User.where("id in (
|
||||||
SELECT value::int
|
SELECT value::int
|
||||||
FROM topic_custom_fields
|
FROM topic_custom_fields
|
||||||
|
@ -95,7 +100,7 @@ after_initialize do
|
||||||
|
|
||||||
topics.each do |t|
|
topics.each do |t|
|
||||||
if id = t.custom_fields['assigned_to_id']
|
if id = t.custom_fields['assigned_to_id']
|
||||||
t.preload_owner(map[id.to_i])
|
t.preload_assigned_to_user(map[id.to_i])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -103,7 +108,11 @@ after_initialize do
|
||||||
|
|
||||||
require_dependency 'listable_topic_serializer'
|
require_dependency 'listable_topic_serializer'
|
||||||
class ::ListableTopicSerializer
|
class ::ListableTopicSerializer
|
||||||
has_one :owner, serializer: BasicUserSerializer, embed: :objects
|
has_one :assigned_to_user, serializer: BasicUserSerializer, embed: :objects
|
||||||
|
|
||||||
|
def include_assigned_to_user?
|
||||||
|
(SiteSetting.assigns_public || scope.is_staff?) && object.assigned_to_user
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
require_dependency 'topic_view_serializer'
|
require_dependency 'topic_view_serializer'
|
||||||
|
@ -128,7 +137,9 @@ after_initialize do
|
||||||
end
|
end
|
||||||
|
|
||||||
def include_assigned_to_user?
|
def include_assigned_to_user?
|
||||||
assigned_to_user_id
|
if SiteSetting.assigns_public || scope.is_staff?
|
||||||
|
assigned_to_user_id
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def assigned_to_user_id
|
def assigned_to_user_id
|
||||||
|
|
Loading…
Reference in New Issue