diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-04-21 02:50:22 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-04-21 02:50:22 +0300 |
commit | 9dc93a4519d9d5d7be48ff274127136236a3adb3 (patch) | |
tree | 70467ae3692a0e35e5ea56bcb803eb512a10bedb /app/models/members | |
parent | 4b0f34b6d759d6299322b3a54453e930c6121ff0 (diff) |
Add latest changes from gitlab-org/gitlab@13-11-stable-eev13.11.0-rc43
Diffstat (limited to 'app/models/members')
-rw-r--r-- | app/models/members/group_member.rb | 4 | ||||
-rw-r--r-- | app/models/members/last_group_owner_assigner.rb | 46 | ||||
-rw-r--r-- | app/models/members/project_member.rb | 2 |
3 files changed, 51 insertions, 1 deletions
diff --git a/app/models/members/group_member.rb b/app/models/members/group_member.rb index c30f6dc81ee..0f9fdd230ff 100644 --- a/app/models/members/group_member.rb +++ b/app/models/members/group_member.rb @@ -7,7 +7,7 @@ class GroupMember < Member SOURCE_TYPE = 'Namespace' belongs_to :group, foreign_key: 'source_id' - + alias_attribute :namespace_id, :source_id delegate :update_two_factor_requirement, to: :user # Make sure group member points only to group as it source @@ -26,6 +26,8 @@ class GroupMember < Member after_create :update_two_factor_requirement, unless: :invite? after_destroy :update_two_factor_requirement, unless: :invite? + attr_accessor :last_owner, :last_blocked_owner + def self.access_level_roles Gitlab::Access.options_with_owner end diff --git a/app/models/members/last_group_owner_assigner.rb b/app/models/members/last_group_owner_assigner.rb new file mode 100644 index 00000000000..64decb1df36 --- /dev/null +++ b/app/models/members/last_group_owner_assigner.rb @@ -0,0 +1,46 @@ +# frozen_string_literal: true + +module Members + class LastGroupOwnerAssigner + def initialize(group, members) + @group = group + @members = members + end + + def execute + @last_blocked_owner = no_owners_in_heirarchy? && group.single_blocked_owner? + @group_single_owner = owners.size == 1 + + members.each { |member| set_last_owner(member) } + end + + private + + attr_reader :group, :members, :last_blocked_owner, :group_single_owner + + def no_owners_in_heirarchy? + owners.empty? + end + + def set_last_owner(member) + member.last_owner = member.id.in?(owner_ids) && group_single_owner + member.last_blocked_owner = member.id.in?(blocked_owner_ids) && last_blocked_owner + end + + def owner_ids + @owner_ids ||= owners.where(id: member_ids).ids + end + + def blocked_owner_ids + @blocked_owner_ids ||= group.blocked_owners.where(id: member_ids).ids + end + + def member_ids + @members_ids ||= members.pluck(:id) + end + + def owners + @owners ||= group.members_with_parents.owners.load + end + end +end diff --git a/app/models/members/project_member.rb b/app/models/members/project_member.rb index 833b27756ab..9a86b3a3fd9 100644 --- a/app/models/members/project_member.rb +++ b/app/models/members/project_member.rb @@ -5,6 +5,8 @@ class ProjectMember < Member belongs_to :project, foreign_key: 'source_id' + delegate :namespace_id, to: :project + # Make sure project member points only to project as it source default_value_for :source_type, SOURCE_TYPE validates :source_type, format: { with: /\AProject\z/ } |