2cf7f09b1e
This reverts commit 530f5158e2
.
See !4892.
Signed-off-by: Rémy Coutable <remy@rymai.me>
55 lines
1.3 KiB
Ruby
55 lines
1.3 KiB
Ruby
module Gitlab
|
|
class UserAccess
|
|
attr_reader :user, :project
|
|
|
|
def initialize(user, project: nil)
|
|
@user = user
|
|
@project = project
|
|
end
|
|
|
|
def can_do_action?(action)
|
|
@permission_cache ||= {}
|
|
@permission_cache[action] ||= user.can?(action, project)
|
|
end
|
|
|
|
def cannot_do_action?(action)
|
|
!can_do_action?(action)
|
|
end
|
|
|
|
def allowed?
|
|
return false if user.blank? || user.blocked?
|
|
|
|
if user.requires_ldap_check? && user.try_obtain_ldap_lease
|
|
return false unless Gitlab::LDAP::Access.allowed?(user)
|
|
end
|
|
|
|
true
|
|
end
|
|
|
|
def can_push_to_branch?(ref)
|
|
return false unless user
|
|
|
|
if project.protected_branch?(ref) && !project.developers_can_push_to_protected_branch?(ref)
|
|
user.can?(:push_code_to_protected_branches, project)
|
|
else
|
|
user.can?(:push_code, project)
|
|
end
|
|
end
|
|
|
|
def can_merge_to_branch?(ref)
|
|
return false unless user
|
|
|
|
if project.protected_branch?(ref) && !project.developers_can_merge_to_protected_branch?(ref)
|
|
user.can?(:push_code_to_protected_branches, project)
|
|
else
|
|
user.can?(:push_code, project)
|
|
end
|
|
end
|
|
|
|
def can_read_project?
|
|
return false unless user
|
|
|
|
user.can?(:read_project, project)
|
|
end
|
|
end
|
|
end
|