gitlabhq/app/models/ability.rb
Dmitriy Zaporozhets d378468794 v1.0
2011-10-13 04:00:00 +03:00

35 lines
650 B
Ruby

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