Address review comments

This commit is contained in:
Valery Sizov 2017-03-02 18:09:48 +02:00
parent b64020de28
commit 39db04bb17
3 changed files with 28 additions and 25 deletions

View file

@ -43,7 +43,6 @@ module RelativePositioning
end end
def move_between(before, after) def move_between(before, after)
return move_nowhere unless before || after
return move_after(before) if before && !after return move_after(before) if before && !after
return move_before(after) if after && !before return move_before(after) if after && !before
@ -52,11 +51,10 @@ module RelativePositioning
if pos_before && pos_after if pos_before && pos_after
if pos_before == pos_after if pos_before == pos_after
pos = pos_before self.relative_position = pos_before
self.relative_position = pos
before.move_before(self) before.move_before(self)
after.move_after(self) after.move_after(self)
@positionable_neighbours = [before, after] @positionable_neighbours = [before, after]
else else
self.relative_position = position_between(pos_before, pos_after) self.relative_position = position_between(pos_before, pos_after)
@ -64,47 +62,50 @@ module RelativePositioning
elsif pos_before elsif pos_before
self.move_after(before) self.move_after(before)
after.move_after(self) after.move_after(self)
@positionable_neighbours = [after] @positionable_neighbours = [after]
elsif pos_after elsif pos_after
self.move_before(after) self.move_before(after)
before.move_before(self) before.move_before(self)
@positionable_neighbours = [before] @positionable_neighbours = [before]
else else
move_to_end move_to_end
before.move_before(self) before.move_before(self)
after.move_after(self) after.move_after(self)
@positionable_neighbours = [before, after] @positionable_neighbours = [before, after]
end end
end end
def move_before(after) def move_before(after)
pos_after = after.relative_position pos_after = after.relative_position
if pos_after if pos_after
self.relative_position = position_between(MIN_POSITION, pos_after) self.relative_position = position_between(MIN_POSITION, pos_after)
else else
move_to_end move_to_end
after.move_after(self) after.move_after(self)
@positionable_neighbours = [after] @positionable_neighbours = [after]
end end
end end
def move_after(before) def move_after(before)
pos_before = before.relative_position pos_before = before.relative_position
if pos_before if pos_before
self.relative_position = position_between(pos_before, MAX_POSITION) self.relative_position = position_between(pos_before, MAX_POSITION)
else else
move_to_end move_to_end
before.move_before(self) before.move_before(self)
@positionable_neighbours = [before] @positionable_neighbours = [before]
end end
end end
def move_nowhere
self.relative_position = nil
end
def move_to_end def move_to_end
self.relative_position = position_between(max_relative_position || MIN_POSITION, MAX_POSITION) self.relative_position = position_between(max_relative_position, MAX_POSITION)
end end
def move_between!(*args) def move_between!(*args)
@ -114,6 +115,9 @@ module RelativePositioning
private private
def position_between(pos_before, pos_after) def position_between(pos_before, pos_after)
pos_before ||= MIN_POSITION
pos_after ||= MAX_POSITION
pos_before, pos_after = [pos_before, pos_after].sort pos_before, pos_after = [pos_before, pos_after].sort
rand(pos_before.next..pos_after.pred) rand(pos_before.next..pos_after.pred)
@ -122,9 +126,9 @@ module RelativePositioning
def save_positionable_neighbours def save_positionable_neighbours
return unless @positionable_neighbours return unless @positionable_neighbours
@positionable_neighbours.each(&:save) status = @positionable_neighbours.all?(&:save)
@positionable_neighbours = nil @positionable_neighbours = nil
true status
end end
end end

View file

@ -71,6 +71,7 @@ module Boards
move_after_iid = params[:move_after_iid] move_after_iid = params[:move_after_iid]
move_before_iid = params[:move_before_iid] move_before_iid = params[:move_before_iid]
return unless move_after_iid || move_before_iid return unless move_after_iid || move_before_iid
[move_after_iid, move_before_iid] [move_after_iid, move_before_iid]
end end
end end

View file

@ -37,11 +37,13 @@ module Issues
end end
added_labels = issue.labels - old_labels added_labels = issue.labels - old_labels
if added_labels.present? if added_labels.present?
notification_service.relabeled_issue(issue, added_labels, current_user) notification_service.relabeled_issue(issue, added_labels, current_user)
end end
added_mentions = issue.mentioned_users - old_mentioned_users added_mentions = issue.mentioned_users - old_mentioned_users
if added_mentions.present? if added_mentions.present?
notification_service.new_mentions_in_issue(issue, added_mentions, current_user) notification_service.new_mentions_in_issue(issue, added_mentions, current_user)
end end
@ -56,27 +58,23 @@ module Issues
end end
def handle_move_between_iids(issue) def handle_move_between_iids(issue)
if move_between_iids = params.delete(:move_between_iids) return unless move_between_iids = params.delete(:move_between_iids)
after_iid, before_iid = move_between_iids
issue_before = nil after_iid, before_iid = move_between_iids
if before_iid
issue_before = issue.project.issues.find_by(iid: before_iid)
issue_before = nil unless can?(current_user, :update_issue, issue_before)
end
issue_after = nil issue_before = get_issue_if_allowed(issue.project, before_iid) if before_iid
if after_iid issue_after = get_issue_if_allowed(issue.project, after_iid) if after_iid
issue_after = issue.project.issues.find_by(iid: after_iid)
issue_after = nil unless can?(current_user, :update_issue, issue_after)
end
issue.move_between(issue_before, issue_after) issue.move_between(issue_before, issue_after)
end
end end
private private
def get_issue_if_allowed(project, iid)
issue = project.issues.find_by(iid: iid)
issue if can?(current_user, :update_issue, issue)
end
def create_confidentiality_note(issue) def create_confidentiality_note(issue)
SystemNoteService.change_issue_confidentiality(issue, issue.project, current_user) SystemNoteService.change_issue_confidentiality(issue, issue.project, current_user)
end end