Skip to content

Commit

Permalink
[api] Refactor Project#check_access?
Browse files Browse the repository at this point in the history
Remove condition that always evaluate to true since grouprels is always
an array.
  • Loading branch information
bgeuken committed Mar 28, 2017
1 parent 055ff04 commit 106c8a4
Showing 1 changed file with 14 additions and 17 deletions.
31 changes: 14 additions & 17 deletions src/api/app/models/project.rb
Expand Up @@ -361,27 +361,24 @@ def self.check_access?(dbp = self)
# dbp.id, User.current
grouprels = dbp.relationships.groups.to_a

if grouprels
ret = 0
grouprels.each do |grouprel|
# check if User.current belongs to group
if grouprel && grouprel.group_id
# LOCAL
# if user is in group -> return true
ret += 1 if User.current.is_in_group?(grouprel.group_id)
# LDAP
# FIXME: please do not do special things here for ldap. please cover this in a generic group model.
if CONFIG['ldap_mode'] == :on && CONFIG['ldap_group_support'] == :on
if UserLdapStrategy.user_in_group_ldap?(User.current, group.group_id)
ret += 1
end
ret = 0
grouprels.each do |grouprel|
# check if User.current belongs to group
if grouprel && grouprel.group_id
# LOCAL
# if user is in group -> return true
ret += 1 if User.current.is_in_group?(grouprel.group_id)
# LDAP
# FIXME: please do not do special things here for ldap. please cover this in a generic group model.
if CONFIG['ldap_mode'] == :on && CONFIG['ldap_group_support'] == :on
if UserLdapStrategy.user_in_group_ldap?(User.current, group.group_id)
ret += 1
end
#
end
end
# relationship to package -> access
return true if ret > 0
end
# relationship to package -> access
return true if ret > 0

false
end
Expand Down

0 comments on commit 106c8a4

Please sign in to comment.