Abilities refactoring

This commit is contained in:
Dmitriy Zaporozhets 2011-12-15 23:57:46 +02:00
parent 7a9fc48080
commit ccc9bed893
7 changed files with 83 additions and 8 deletions

View file

@ -161,6 +161,18 @@ class Project < ActiveRecord::Base
@admins ||= users_projects.includes(:user).where(:project_access => PROJECT_RWA).map(&:user)
end
def allow_read_for?(user)
!users_projects.where(:user_id => user.id, :project_access => [PROJECT_R, PROJECT_RW, PROJECT_RWA]).empty?
end
def allow_write_for?(user)
!users_projects.where(:user_id => user.id, :project_access => [PROJECT_RW, PROJECT_RWA]).empty?
end
def allow_admin_for?(user)
!users_projects.where(:user_id => user.id, :project_access => [PROJECT_RWA]).empty? || owner_id == user.id
end
def root_ref
default_branch || "master"
end