gitlabhq/app/models/ability.rb

35 lines
650 B
Ruby
Raw Normal View History

2011-10-08 23:36:38 +02:00
class Ability
def self.allowed(object, subject)
case subject.class.name
when "Project" then project_abilities(object, subject)
else []
end
end
def self.project_abilities(user, project)
rules = []
rules << [
:read_project,
:read_issue,
:read_team_member,
:read_note
] if project.readers.include?(user)
rules << [
:write_project,
:write_issue,
:write_note
] if project.writers.include?(user)
rules << [
:admin_project,
:admin_issue,
:admin_team_member,
:admin_note
] if project.admins.include?(user)
rules.flatten
end
end