diff options
Diffstat (limited to 'app/services/issuable_base_service.rb')
-rw-r--r-- | app/services/issuable_base_service.rb | 24 |
1 files changed, 15 insertions, 9 deletions
diff --git a/app/services/issuable_base_service.rb b/app/services/issuable_base_service.rb index 6d41d449683..7c508237c8d 100644 --- a/app/services/issuable_base_service.rb +++ b/app/services/issuable_base_service.rb @@ -190,11 +190,7 @@ class IssuableBaseService < BaseService change_additional_attributes(issuable) old_associations = associations_before_update(issuable) - label_ids = process_label_ids(params, existing_label_ids: issuable.label_ids) - if labels_changing?(issuable.label_ids, label_ids) - params[:label_ids] = label_ids - issuable.touch - end + assign_requested_labels(issuable) if issuable.changed? || params.present? issuable.assign_attributes(params) @@ -297,10 +293,6 @@ class IssuableBaseService < BaseService update_task(issuable) end - def labels_changing?(old_label_ids, new_label_ids) - old_label_ids.sort != new_label_ids.sort - end - def has_title_or_description_changed?(issuable) issuable.title_changed? || issuable.description_changed? end @@ -349,6 +341,20 @@ class IssuableBaseService < BaseService end # rubocop: enable CodeReuse/ActiveRecord + def assign_requested_labels(issuable) + label_ids = process_label_ids(params, existing_label_ids: issuable.label_ids) + return unless ids_changing?(issuable.label_ids, label_ids) + + params[:label_ids] = label_ids + issuable.touch + end + + # Arrays of ids are used, but we should really use sets of ids, so + # let's have an helper to properly check if some ids are changing + def ids_changing?(old_array, new_array) + old_array.sort != new_array.sort + end + def toggle_award(issuable) award = params.delete(:emoji_award) AwardEmojis::ToggleService.new(issuable, award, current_user).execute if award |