diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-07-16 18:09:38 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-07-16 18:09:38 +0300 |
commit | 2d8454515e7b631a8f39a6415c86154d6c62841c (patch) | |
tree | d3d5fac01f23a735226cf20a4073e2cb611664d3 /lib | |
parent | 9d67bc14cb59a27c9877474e77d155173a1dedff (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib')
-rw-r--r-- | lib/api/entities/merge_request_approvals.rb | 4 | ||||
-rw-r--r-- | lib/api/members.rb | 2 | ||||
-rw-r--r-- | lib/api/milestone_responses.rb | 29 | ||||
-rw-r--r-- | lib/api/project_milestones.rb | 2 | ||||
-rw-r--r-- | lib/gitlab/background_migration/backfill_namespace_settings.rb | 18 | ||||
-rw-r--r-- | lib/gitlab/danger/helper.rb | 3 |
6 files changed, 50 insertions, 8 deletions
diff --git a/lib/api/entities/merge_request_approvals.rb b/lib/api/entities/merge_request_approvals.rb index d8a464cfeda..e3d58d687c4 100644 --- a/lib/api/entities/merge_request_approvals.rb +++ b/lib/api/entities/merge_request_approvals.rb @@ -4,11 +4,11 @@ module API module Entities class MergeRequestApprovals < Grape::Entity expose :user_has_approved do |merge_request, options| - merge_request.has_approved?(options[:current_user]) + merge_request.approved_by?(options[:current_user]) end expose :user_can_approve do |merge_request, options| - !merge_request.has_approved?(options[:current_user]) && + !merge_request.approved_by?(options[:current_user]) && options[:current_user].can?(:approve_merge_request, merge_request) end diff --git a/lib/api/members.rb b/lib/api/members.rb index 3de7ae13d5e..4edf94c6350 100644 --- a/lib/api/members.rb +++ b/lib/api/members.rb @@ -107,7 +107,7 @@ module API if !member not_allowed! # This currently can only be reached in EE - elsif member.persisted? && member.valid? + elsif member.valid? && member.persisted? present_members(member) else render_validation_error!(member) diff --git a/lib/api/milestone_responses.rb b/lib/api/milestone_responses.rb index 8ff885983bc..ec108ea8c83 100644 --- a/lib/api/milestone_responses.rb +++ b/lib/api/milestone_responses.rb @@ -31,12 +31,14 @@ module API end def list_milestones_for(parent) - milestones = parent.milestones.order_id_desc - milestones = Milestone.filter_by_state(milestones, params[:state]) - milestones = filter_by_iid(milestones, params[:iids]) if params[:iids].present? - milestones = filter_by_title(milestones, params[:title]) if params[:title] + finder_params = params.merge(milestones_finder_params(parent)) + milestones = MilestonesFinder.new(finder_params).execute milestones = filter_by_search(milestones, params[:search]) if params[:search] + if params[:iids].present? && !params[:include_parent_milestones] + milestones = filter_by_iid(milestones, params[:iids]) + end + present paginate(milestones), with: Entities::Milestone end @@ -96,6 +98,25 @@ module API [MergeRequestsFinder, Entities::MergeRequestBasic] end end + + def milestones_finder_params(parent) + if parent.is_a?(Group) + { group_ids: parent.id } + else + { + project_ids: parent.id, + group_ids: parent_group_ids(parent) + } + end + end + + def parent_group_ids(parent) + return unless params[:include_parent_milestones].present? + + parent.group.self_and_ancestors + .public_or_visible_to_user(current_user) + .select(:id) + end end end end diff --git a/lib/api/project_milestones.rb b/lib/api/project_milestones.rb index 2f8dd1085dc..ef74e8cb0c9 100644 --- a/lib/api/project_milestones.rb +++ b/lib/api/project_milestones.rb @@ -16,6 +16,8 @@ module API end params do use :list_params + optional :include_parent_milestones, type: Boolean, default: false, + desc: 'Include milestones from parent group and ancestors' end get ":id/milestones" do authorize! :read_milestone, user_project diff --git a/lib/gitlab/background_migration/backfill_namespace_settings.rb b/lib/gitlab/background_migration/backfill_namespace_settings.rb new file mode 100644 index 00000000000..a391d5f4ebe --- /dev/null +++ b/lib/gitlab/background_migration/backfill_namespace_settings.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +module Gitlab + module BackgroundMigration + # Backfillnamespace_settings for a range of namespaces + class BackfillNamespaceSettings + def perform(start_id, end_id) + ActiveRecord::Base.connection.execute <<~SQL + INSERT INTO namespace_settings (namespace_id, created_at, updated_at) + SELECT namespaces.id, now(), now() + FROM namespaces + WHERE namespaces.id BETWEEN #{start_id} AND #{end_id} + ON CONFLICT (namespace_id) DO NOTHING; + SQL + end + end + end +end diff --git a/lib/gitlab/danger/helper.rb b/lib/gitlab/danger/helper.rb index d65c7887643..db799c094b2 100644 --- a/lib/gitlab/danger/helper.rb +++ b/lib/gitlab/danger/helper.rb @@ -6,6 +6,7 @@ module Gitlab module Danger module Helper RELEASE_TOOLS_BOT = 'gitlab-release-tools-bot' + DRAFT_REGEX = /\A*#{Regexp.union(/(?i)(\[WIP\]\s*|WIP:\s*|WIP$)/, /(?i)(\[draft\]|\(draft\)|draft:|draft\s\-\s|draft$)/)}+\s*/i.freeze # Returns a list of all files that have been added, modified or renamed. # `git.modified_files` might contain paths that already have been renamed, @@ -210,7 +211,7 @@ module Gitlab end def sanitize_mr_title(title) - title.gsub(/^WIP: */, '').gsub(/`/, '\\\`') + title.gsub(DRAFT_REGEX, '').gsub(/`/, '\\\`') end def security_mr? |