permissionable.rb revision d62eba79f306957dd89ea9d3313600e98e2a8beb
included do
end
# Deny if role is unknown or user is wrong object.
# Allow any admin user.
# Retrieve direct user permissions.
# Retrieve permissions through team.
user.teams.each do |team|
@perms << Permission.item(self).subject(team).all
end
# Deny if no permission is found.
return false unless @perms
# Allow if role matches any permission.
@perms.flatten.each do |perm|
return true if perm.role == role.to_s
return true if perm.role == 'owner' and role == :editor
end
# Deny otherwise.
false
end
end