optionally apply a regex to post body when assigning stuff out
This commit is contained in:
parent
581e47055c
commit
d7c74701f2
|
@ -4,6 +4,8 @@ en:
|
||||||
assigns_user_url_path: "Path to link all user links for assigned (use: {username} to subtitue username)"
|
assigns_user_url_path: "Path to link all user links for assigned (use: {username} to subtitue username)"
|
||||||
assigns_by_staff_mention: "If a staff member mentions another staff member, topic is automatically assigned"
|
assigns_by_staff_mention: "If a staff member mentions another staff member, topic is automatically assigned"
|
||||||
unassign_creates_tracking_post: "If you unassign a topic a whisper or small action will be created to track change"
|
unassign_creates_tracking_post: "If you unassign a topic a whisper or small action will be created to track change"
|
||||||
|
assign_self_regex: "Regex that needs to pass for self assign. Example 'my list'"
|
||||||
|
assign_other_regex: "Regex that needs to pass for assigning topics to others via mention. Example 'your list'."
|
||||||
discourse_assign:
|
discourse_assign:
|
||||||
assigned_to: "Topic assigned to @%{username}"
|
assigned_to: "Topic assigned to @%{username}"
|
||||||
unassigned: "Topic was unassigned"
|
unassigned: "Topic was unassigned"
|
||||||
|
|
|
@ -2,6 +2,8 @@ plugins:
|
||||||
assigns_by_staff_mention: false
|
assigns_by_staff_mention: false
|
||||||
unassign_creates_tracking_post: true
|
unassign_creates_tracking_post: true
|
||||||
assigns_public: false
|
assigns_public: false
|
||||||
|
assign_self_regex: ""
|
||||||
|
assign_other_regex: ""
|
||||||
assigns_user_url_path:
|
assigns_user_url_path:
|
||||||
client: true
|
client: true
|
||||||
default: "/latest?assigned={username}"
|
default: "/latest?assigned={username}"
|
||||||
|
|
26
plugin.rb
26
plugin.rb
|
@ -45,14 +45,36 @@ SQL
|
||||||
puts "#{assigned} topics where automatically assigned to staff members"
|
puts "#{assigned} topics where automatically assigned to staff members"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.assign_self_passes?(post)
|
||||||
|
return false unless SiteSetting.assign_self_regex.present?
|
||||||
|
regex = Regexp.new(SiteSetting.assign_self_regex) rescue nil
|
||||||
|
|
||||||
|
!!(regex && regex.match(post.raw))
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.assign_other_passes?(post)
|
||||||
|
return true unless SiteSetting.assign_other_regex.present?
|
||||||
|
regex = Regexp.new(SiteSetting.assign_other_regex) rescue nil
|
||||||
|
|
||||||
|
!!(regex && regex.match(post.raw))
|
||||||
|
end
|
||||||
|
|
||||||
def self.auto_assign(post, force: false)
|
def self.auto_assign(post, force: false)
|
||||||
return unless SiteSetting.assigns_by_staff_mention
|
return unless SiteSetting.assigns_by_staff_mention
|
||||||
|
|
||||||
if post.user && post.topic && post.user.staff?
|
if post.user && post.topic && post.user.staff?
|
||||||
can_assign = force || post.topic.custom_fields["assigned_to_id"].nil?
|
can_assign = force || post.topic.custom_fields["assigned_to_id"].nil?
|
||||||
if can_assign && is_last_staff_post?(post) && user = mentioned_staff(post)
|
|
||||||
|
assign_other = assign_other_passes?(post) && mentioned_staff(post)
|
||||||
|
assign_self = assign_self_passes?(post) && post.user
|
||||||
|
|
||||||
|
if can_assign && is_last_staff_post?(post)
|
||||||
assigner = new(post.topic, post.user)
|
assigner = new(post.topic, post.user)
|
||||||
assigner.assign(user, silent: true)
|
if assign_other
|
||||||
|
assigner.assign(assign_other, silent: true)
|
||||||
|
elsif assign_self
|
||||||
|
assigner.assign(assign_self, silent: true)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue