debian-mirror-gitlab/app/policies/group_policy.rb

48 lines
1.4 KiB
Ruby
Raw Normal View History

2016-09-29 09:46:39 +05:30
class GroupPolicy < BasePolicy
def rules
can! :read_group if @subject.public?
return unless @user
globally_viewable = @subject.public? || (@subject.internal? && !@user.external?)
2017-08-17 22:00:37 +05:30
member = @subject.users_with_parents.include?(@user)
2016-09-29 09:46:39 +05:30
owner = @user.admin? || @subject.has_owner?(@user)
master = owner || @subject.has_master?(@user)
can_read = false
can_read ||= globally_viewable
can_read ||= member
can_read ||= @user.admin?
2017-08-17 22:00:37 +05:30
can_read ||= GroupProjectsFinder.new(group: @subject, current_user: @user).execute.any?
2016-09-29 09:46:39 +05:30
can! :read_group if can_read
# Only group masters and group owners can create new projects
if master
can! :create_projects
can! :admin_milestones
2016-11-03 12:29:30 +05:30
can! :admin_label
2016-09-29 09:46:39 +05:30
end
# Only group owner and administrators can admin group
if owner
can! :admin_group
can! :admin_namespace
can! :admin_group_member
can! :change_visibility_level
2017-08-17 22:00:37 +05:30
can! :create_subgroup if @user.can_create_group
2016-09-29 09:46:39 +05:30
end
if globally_viewable && @subject.request_access_enabled && !member
can! :request_access
end
end
def can_read_group?
return true if @subject.public?
return true if @user.admin?
return true if @subject.internal? && !@user.external?
return true if @subject.users.include?(@user)
2017-08-17 22:00:37 +05:30
GroupProjectsFinder.new(group: @subject, current_user: @user).execute.any?
2016-09-29 09:46:39 +05:30
end
end