diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-11-18 16:16:36 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-11-18 16:16:36 +0300 |
commit | 311b0269b4eb9839fa63f80c8d7a58f32b8138a0 (patch) | |
tree | 07e7870bca8aed6d61fdcc810731c50d2c40af47 /app/models/members | |
parent | 27909cef6c4170ed9205afa7426b8d3de47cbb0c (diff) |
Add latest changes from gitlab-org/gitlab@14-5-stable-eev14.5.0-rc42
Diffstat (limited to 'app/models/members')
-rw-r--r-- | app/models/members/member_task.rb | 43 | ||||
-rw-r--r-- | app/models/members/project_member.rb | 1 |
2 files changed, 43 insertions, 1 deletions
diff --git a/app/models/members/member_task.rb b/app/models/members/member_task.rb new file mode 100644 index 00000000000..f093619ff36 --- /dev/null +++ b/app/models/members/member_task.rb @@ -0,0 +1,43 @@ +# frozen_string_literal: true + +class MemberTask < ApplicationRecord + TASKS = { + code: 0, + ci: 1, + issues: 2 + }.freeze + + belongs_to :member + belongs_to :project + + validates :member, :project, presence: true + validates :tasks, inclusion: { in: TASKS.values } + validate :tasks_uniqueness + validate :project_in_member_source + + scope :for_members, -> (members) { joins(:member).where(member: members) } + + def tasks_to_be_done + Array(self[:tasks]).map { |task| TASKS.key(task) } + end + + def tasks_to_be_done=(tasks) + self[:tasks] = Array(tasks).map do |task| + TASKS[task.to_sym] + end.uniq + end + + private + + def tasks_uniqueness + errors.add(:tasks, 'are not unique') unless Array(tasks).length == Array(tasks).uniq.length + end + + def project_in_member_source + if member.is_a?(GroupMember) + errors.add(:project, _('is not in the member group')) unless project.namespace == member.source + elsif member.is_a?(ProjectMember) + errors.add(:project, _('is not the member project')) unless project == member.source + end + end +end diff --git a/app/models/members/project_member.rb b/app/models/members/project_member.rb index eec46b3493e..89b72508e84 100644 --- a/app/models/members/project_member.rb +++ b/app/models/members/project_member.rb @@ -94,7 +94,6 @@ class ProjectMember < Member override :refresh_member_authorized_projects def refresh_member_authorized_projects(blocking:) - return super unless Feature.enabled?(:specialized_service_for_project_member_auth_refresh) return unless user # rubocop:disable CodeReuse/ServiceClass |