Commit 756d6156 authored by Douwe Maan's avatar Douwe Maan

Minor refactoring

parent 16438ad2
...@@ -2,7 +2,7 @@ class Ability ...@@ -2,7 +2,7 @@ class Ability
class << self class << self
def allowed(user, subject) def allowed(user, subject)
return not_auth_abilities(user, subject) if user.nil? return not_auth_abilities(user, subject) if user.nil?
return [] unless user.kind_of?(User) return [] unless user.is_a?(User)
return [] if user.blocked? return [] if user.blocked?
case subject.class.name case subject.class.name
...@@ -22,14 +22,20 @@ class Ability ...@@ -22,14 +22,20 @@ class Ability
# List of possible abilities # List of possible abilities
# for non-authenticated user # for non-authenticated user
def not_auth_abilities(user, subject) def not_auth_abilities(user, subject)
return not_auth_personal_snippet_abilities(subject) if subject.kind_of?(PersonalSnippet) case true
return not_auth_project_abilities(subject) if subject.kind_of?(Project) || subject.respond_to?(:project) when subject.is_a?(PersonalSnippet)
return not_auth_group_abilities(subject) if subject.kind_of?(Group) || subject.respond_to?(:group) not_auth_personal_snippet_abilities(subject)
[] when subject.is_a?(Project) || subject.respond_to?(:project)
not_auth_project_abilities(subject)
when subject.is_a?(Group) || subject.respond_to?(:group)
not_auth_group_abilities(subject)
else
[]
end
end end
def not_auth_project_abilities(subject) def not_auth_project_abilities(subject)
project = if subject.kind_of?(Project) project = if subject.is_a?(Project)
subject subject
else else
subject.project subject.project
...@@ -57,7 +63,7 @@ class Ability ...@@ -57,7 +63,7 @@ class Ability
end end
def not_auth_group_abilities(subject) def not_auth_group_abilities(subject)
group = if subject.kind_of?(Group) group = if subject.is_a?(Group)
subject subject
else else
subject.group subject.group
...@@ -327,7 +333,7 @@ class Ability ...@@ -327,7 +333,7 @@ class Ability
end end
if snippet.public? || snippet.internal? if snippet.public? || snippet.internal?
rules.push(:read_personal_snippet) rules << :read_personal_snippet
end end
rules rules
......
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