diff options
Diffstat (limited to 'app/models/ability.rb')
-rw-r--r-- | app/models/ability.rb | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/app/models/ability.rb b/app/models/ability.rb new file mode 100644 index 00000000000..0a2c45f1289 --- /dev/null +++ b/app/models/ability.rb @@ -0,0 +1,34 @@ +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 |