76 |
76 |
end
|
77 |
77 |
end
|
78 |
78 |
|
79 |
|
# Set member role ids ignoring any change to roles that
|
80 |
|
# user is not allowed to manage
|
|
79 |
# Set member role ids ignoring any change to roles that
|
|
80 |
# user is not allowed to manage
|
81 |
81 |
def set_editable_role_ids(ids, user=User.current)
|
82 |
82 |
ids = (ids || []).collect(&:to_i) - [0]
|
83 |
83 |
editable_role_ids = user.managed_roles(project).map(&:id)
|
... | ... | |
86 |
86 |
self.role_ids = untouched_role_ids + touched_role_ids
|
87 |
87 |
end
|
88 |
88 |
|
89 |
|
# Returns true if one of the member roles is inherited
|
|
89 |
# Returns true if one of the member roles is inherited
|
90 |
90 |
def any_inherited_role?
|
91 |
91 |
member_roles.any? {|mr| mr.inherited_from}
|
92 |
92 |
end
|
93 |
93 |
|
94 |
|
# Returns true if the member has the role and if it's inherited
|
|
94 |
# Returns true if the member has the role and if it's inherited
|
95 |
95 |
def has_inherited_role?(role)
|
96 |
96 |
member_roles.any? {|mr| mr.role_id == role.id && mr.inherited_from.present?}
|
97 |
97 |
end
|
98 |
98 |
|
99 |
|
# Returns true if the member's role is editable by user
|
|
99 |
# Returns true if the member's role is editable by user
|
100 |
100 |
def role_editable?(role, user=User.current)
|
101 |
101 |
if has_inherited_role?(role)
|
102 |
102 |
false
|
... | ... | |
105 |
105 |
end
|
106 |
106 |
end
|
107 |
107 |
|
108 |
|
# Returns true if the member is deletable by user
|
|
108 |
# Returns true if the member is deletable by user
|
109 |
109 |
def deletable?(user=User.current)
|
110 |
110 |
if any_inherited_role?
|
111 |
111 |
false
|
... | ... | |
114 |
114 |
end
|
115 |
115 |
end
|
116 |
116 |
|
117 |
|
# Destroys the member
|
|
117 |
# Destroys the member
|
118 |
118 |
def destroy
|
119 |
119 |
member_roles.reload.each(&:destroy_without_member_removal)
|
120 |
120 |
super
|
121 |
121 |
end
|
122 |
122 |
|
123 |
|
# Returns true if the member is user or is a group
|
124 |
|
# that includes user
|
|
123 |
# Returns true if the member is user or is a group
|
|
124 |
# that includes user
|
125 |
125 |
def include?(user)
|
126 |
126 |
if principal.is_a?(Group)
|
127 |
127 |
!user.nil? && user.groups.include?(principal)
|