diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-09-16 18:09:32 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-09-16 18:09:32 +0300 |
commit | 6de7d2c195a8a7fa5702cafa4365f7a9fcac37cd (patch) | |
tree | e976130993f87a9d1e1f19cdab0ebaf218dfff69 /app/models/project_team.rb | |
parent | 591b0e86e3dbaa31b68340a14dc32859306a27b1 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/models/project_team.rb')
-rw-r--r-- | app/models/project_team.rb | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/app/models/project_team.rb b/app/models/project_team.rb index 072d281e5f8..5b7eded00cd 100644 --- a/app/models/project_team.rb +++ b/app/models/project_team.rb @@ -178,6 +178,40 @@ class ProjectTeam max_member_access_for_user_ids([user_id])[user_id] end + def contribution_check_for_user_ids(user_ids) + user_ids = user_ids.uniq + key = "contribution_check_for_users:#{project.id}" + + Gitlab::SafeRequestStore[key] ||= {} + contributors = Gitlab::SafeRequestStore[key] || {} + + user_ids -= contributors.keys + + return contributors if user_ids.empty? + + resource_contributors = project.merge_requests + .merged + .where(author_id: user_ids, target_branch: project.default_branch.to_s) + .pluck(:author_id) + .product([true]).to_h + + contributors.merge!(resource_contributors) + + missing_resource_ids = user_ids - resource_contributors.keys + + missing_resource_ids.each do |resource_id| + contributors[resource_id] = false + end + + contributors + end + + def contributor?(user_id) + return false if max_member_access(user_id) >= Gitlab::Access::GUEST + + contribution_check_for_user_ids([user_id])[user_id] + end + private def fetch_members(level = nil) |