refactor [fixes SCI-825]

This commit is contained in:
zmagod 2017-04-06 15:08:03 +02:00
parent 439cd0cd89
commit 9bb1bb3f9b
2 changed files with 7 additions and 4 deletions

View file

@ -55,6 +55,8 @@ module StepsActions
checklists checklists
end end
# used for step update action it traverse through the input params and
# generates notifications
def update_annotation_notification(step, def update_annotation_notification(step,
old_description, old_description,
new_checklists, new_checklists,
@ -139,6 +141,7 @@ module StepsActions
)) ))
end end
# temporary data containers
PreviouseChecklistItem = Struct.new(:id, :text) PreviouseChecklistItem = Struct.new(:id, :text)
PreviouseChecklist = Struct.new(:id, :name, :items) do PreviouseChecklist = Struct.new(:id, :name, :items) do
def initialize(id, name, items = []) def initialize(id, name, items = [])

View file

@ -64,24 +64,24 @@ module ApplicationHelper
new_text = options.fetch(:new_text) { :new_text_must_be_present } new_text = options.fetch(:new_text) { :new_text_must_be_present }
old_text = options[:old_text] || '' old_text = options[:old_text] || ''
sa_user = /\[\@(.*?)~([0-9a-zA-Z]+)\]/ sa_user = /\[\@(.*?)~([0-9a-zA-Z]+)\]/
# fetch user ids from the previouse text
old_user_ids = [] old_user_ids = []
old_text.gsub(sa_user) do |el| old_text.gsub(sa_user) do |el|
match = el.match(sa_user) match = el.match(sa_user)
old_user_ids << match[2].base62_decode old_user_ids << match[2].base62_decode
end end
# fetch user ids from the new text
new_user_ids = [] new_user_ids = []
new_text.gsub(sa_user) do |el| new_text.gsub(sa_user) do |el|
match = el.match(sa_user) match = el.match(sa_user)
new_user_ids << match[2].base62_decode new_user_ids << match[2].base62_decode
end end
# check if the user has been already mentioned
annotated_users = [] annotated_users = []
new_user_ids.each do |el| new_user_ids.each do |el|
annotated_users << el unless old_user_ids.include?(el) annotated_users << el unless old_user_ids.include?(el)
end end
# restrict the list of ids and generate notification
annotated_users.uniq.each do |user_id| annotated_users.uniq.each do |user_id|
target_user = User.find_by_id(user_id) target_user = User.find_by_id(user_id)
next unless target_user next unless target_user