Commit c6a0f109 authored by James Lopez's avatar James Lopez

refactored code as projects only have one owner. Kept some refactoring in...

refactored code as projects only have one owner. Kept some refactoring in place (has_owners concern)
parent 1b14bc59
......@@ -323,12 +323,12 @@ class Ability
project = subject.project
can_manage = project_abilities(user, project).include?(:admin_project_member)
if can_manage && (user != target_user)
if can_manage && user != target_user && target_user != project.owner
rules << :update_project_member
rules << :destroy_project_member
end
if !project.last_owner?(user) && (can_manage || (user == target_user))
if user == target_user && target_user != project.owner
rules << :destroy_project_member
end
rules
......
......@@ -6,10 +6,10 @@ module HasOwners
extend ActiveSupport::Concern
def owners
@owners ||= my_members.owners.includes(:user).map(&:user)
@owners ||= members.owners.includes(:user).map(&:user)
end
def my_members
def members
raise NotImplementedError, "Expected my_members to be defined in #{self.class.name}"
end
......
......@@ -22,7 +22,7 @@ class Group < Namespace
include HasOwners
has_many :group_members, dependent: :destroy, as: :source, class_name: 'GroupMember'
alias_method :my_members, :group_members
alias_method :members, :group_members
has_many :users, through: :group_members
validate :avatar_type, if: ->(user) { user.avatar.present? && user.avatar_changed? }
......@@ -91,10 +91,6 @@ class Group < Namespace
add_user(user, Gitlab::Access::MASTER, current_user)
end
def members
group_members
end
def avatar_type
unless self.avatar.image?
self.errors.add :avatar, "only images allowed"
......
......@@ -94,8 +94,7 @@ class Member < ActiveRecord::Base
def can_update_member?(current_user, member)
!current_user || current_user.can?(:update_group_member, member) ||
(member.respond_to?(:project) &&
current_user.can?(:update_project_member, member))
current_user.can?(:update_project_member, member)
end
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment