diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-10-11 18:09:43 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-10-11 18:09:43 +0000 |
commit | 6e7be08ca5d6fac981284e7b1383b320a03d3a5d (patch) | |
tree | 5ae3da5b41f79107b86874c393a2799b7d1b1f3c /app/services | |
parent | 14ae125e1c59ca3e9b535938707831c986dbbc43 (diff) | |
download | gitlab-ce-6e7be08ca5d6fac981284e7b1383b320a03d3a5d.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/services')
-rw-r--r-- | app/services/merge_requests/update_assignees_service.rb | 12 | ||||
-rw-r--r-- | app/services/notes/create_service.rb | 38 | ||||
-rw-r--r-- | app/services/projects/container_repository/cleanup_tags_service.rb | 3 |
3 files changed, 42 insertions, 11 deletions
diff --git a/app/services/merge_requests/update_assignees_service.rb b/app/services/merge_requests/update_assignees_service.rb index a13db52e34b..79a3e9f3c22 100644 --- a/app/services/merge_requests/update_assignees_service.rb +++ b/app/services/merge_requests/update_assignees_service.rb @@ -18,7 +18,17 @@ module MergeRequests return merge_request if old_ids.to_set == new_ids.to_set # no-change attrs = update_attrs.merge(assignee_ids: new_ids) - merge_request.update!(**attrs) + + # We now have assignees validation on merge request + # If we use an update with bang, it will explode, + # instead we need to check if its valid then return if its not valid. + if Feature.enabled?(:limit_assignees_per_issuable) + merge_request.update(**attrs) + + return merge_request unless merge_request.valid? + else + merge_request.update!(**attrs) + end # Defer the more expensive operations (handle_assignee_changes) to the background MergeRequests::HandleAssigneesChangeService diff --git a/app/services/notes/create_service.rb b/app/services/notes/create_service.rb index b7e6a50fa5c..1aaf7fb769a 100644 --- a/app/services/notes/create_service.rb +++ b/app/services/notes/create_service.rb @@ -88,12 +88,14 @@ module Notes return if quick_actions_service.commands_executed_count.to_i == 0 if update_params.present? - if check_for_reviewer_validity(message, update_params) + invalid_message = validate_commands(note, update_params) + + if invalid_message + note.errors.add(:validation, invalid_message) + message = invalid_message + else quick_actions_service.apply_updates(update_params, note) note.commands_changes = update_params - else - message = "Reviewers #{MergeRequest.max_number_of_assignees_or_reviewers_message}" - note.errors.add(:validation, message) end end @@ -114,16 +116,36 @@ module Notes } end - def check_for_reviewer_validity(message, update_params) - return true unless Feature.enabled?(:limit_reviewer_and_assignee_size) + def validate_commands(note, update_params) + if invalid_reviewers?(update_params) + "Reviewers #{note.noteable.class.max_number_of_assignees_or_reviewers_message}" + elsif invalid_assignees?(update_params) + "Assignees #{note.noteable.class.max_number_of_assignees_or_reviewers_message}" + end + end + + def invalid_reviewers?(update_params) + return false unless Feature.enabled?(:limit_reviewer_and_assignee_size) if update_params.key?(:reviewer_ids) possible_reviewers = update_params[:reviewer_ids]&.uniq&.size - return false if possible_reviewers > MergeRequest::MAX_NUMBER_OF_ASSIGNEES_OR_REVIEWERS + possible_reviewers > ::Issuable::MAX_NUMBER_OF_ASSIGNEES_OR_REVIEWERS + else + false end + end + + def invalid_assignees?(update_params) + return false unless Feature.enabled?(:limit_assignees_per_issuable) - true + if update_params.key?(:assignee_ids) + possible_assignees = update_params[:assignee_ids]&.uniq&.size + + possible_assignees > ::Issuable::MAX_NUMBER_OF_ASSIGNEES_OR_REVIEWERS + else + false + end end def track_event(note, user) diff --git a/app/services/projects/container_repository/cleanup_tags_service.rb b/app/services/projects/container_repository/cleanup_tags_service.rb index 0b31ac0c877..cf2eb81e5f3 100644 --- a/app/services/projects/container_repository/cleanup_tags_service.rb +++ b/app/services/projects/container_repository/cleanup_tags_service.rb @@ -30,8 +30,7 @@ module Projects end def use_gitlab_service? - Feature.enabled?(:container_registry_new_cleanup_service, project) && - container_repository.migrated? && + container_repository.migrated? && container_repository.gitlab_api_client.supports_gitlab_api? end |