mirror of
https://github.com/discourse/discourse.git
synced 2025-09-05 08:59:27 +08:00
Merge pull request #5610 from discourse/pm-tags
FEATURE: Allow staffs to tag PMs
This commit is contained in:
commit
dd26bbe868
33 changed files with 279 additions and 158 deletions
|
@ -4,10 +4,10 @@ module DiscourseTagging
|
|||
TAGS_FILTER_REGEXP = /[\/\?#\[\]@!\$&'\(\)\*\+,;=\.%\\`^\s|\{\}"<>]+/ # /?#[]@!$&'()*+,;=.%\`^|{}"<>
|
||||
|
||||
def self.tag_topic_by_names(topic, guardian, tag_names_arg, append: false)
|
||||
if SiteSetting.tagging_enabled
|
||||
if guardian.can_tag?(topic)
|
||||
tag_names = DiscourseTagging.tags_for_saving(tag_names_arg, guardian) || []
|
||||
|
||||
old_tag_names = topic.tags.map(&:name) || []
|
||||
old_tag_names = topic.tags.pluck(:name) || []
|
||||
new_tag_names = tag_names - old_tag_names
|
||||
removed_tag_names = old_tag_names - tag_names
|
||||
|
||||
|
|
|
@ -129,6 +129,16 @@ class Guardian
|
|||
alias :can_see_flags? :can_moderate?
|
||||
alias :can_close? :can_moderate?
|
||||
|
||||
def can_tag?(topic)
|
||||
return false if topic.blank?
|
||||
|
||||
topic.private_message? ? can_tag_pms? : can_tag_topics?
|
||||
end
|
||||
|
||||
def can_see_tags?(topic)
|
||||
SiteSetting.tagging_enabled && topic.present? && (!topic.private_message? || can_tag_pms?)
|
||||
end
|
||||
|
||||
def can_send_activation_email?(user)
|
||||
user && is_staff? && !SiteSetting.must_approve_users?
|
||||
end
|
||||
|
|
|
@ -5,7 +5,11 @@ module TagGuardian
|
|||
end
|
||||
|
||||
def can_tag_topics?
|
||||
user && user.has_trust_level?(SiteSetting.min_trust_level_to_tag_topics.to_i)
|
||||
user && SiteSetting.tagging_enabled && user.has_trust_level?(SiteSetting.min_trust_level_to_tag_topics.to_i)
|
||||
end
|
||||
|
||||
def can_tag_pms?
|
||||
is_staff? && SiteSetting.tagging_enabled && SiteSetting.allow_staff_to_tag_pms
|
||||
end
|
||||
|
||||
def can_admin_tags?
|
||||
|
|
|
@ -269,6 +269,13 @@ class TopicQuery
|
|||
create_list(:private_messages, {}, list)
|
||||
end
|
||||
|
||||
def list_private_messages_tag(user)
|
||||
list = private_messages_for(user, :all)
|
||||
list = list.joins("JOIN topic_tags tt ON tt.topic_id = topics.id
|
||||
JOIN tags t ON t.id = tt.tag_id AND t.name = '#{@options[:tags][0]}'")
|
||||
create_list(:private_messages, {}, list)
|
||||
end
|
||||
|
||||
def list_category_topic_ids(category)
|
||||
query = default_results(category: category.id)
|
||||
pinned_ids = query.where('pinned_at IS NOT NULL AND category_id = ?', category.id).limit(nil).order('pinned_at DESC').pluck(:id)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue