#219: updated ability.rb
This commit is contained in:
parent
ef02f33a42
commit
6501ba0f72
|
@ -81,7 +81,8 @@ class Ability
|
|||
can [:read, :log, :owned, :everything], BuildList, :user_id => user.id
|
||||
can [:read, :log, :related, :everything], BuildList, :project => {:owner_type => 'User', :owner_id => user.id}
|
||||
can [:read, :log, :related, :everything], BuildList, :project => {:owner_type => 'Group', :owner_id => user.group_ids}
|
||||
# can([:read, :log, :everything], BuildList, read_relations_for('build_lists', 'projects')) {|build_list| can? :read, build_list.project}
|
||||
can([:read, :log, :everything], BuildList, read_relations_for('build_lists', 'projects')) {|build_list| can? :read, build_list.project}
|
||||
|
||||
can(:create, BuildList) {|build_list|
|
||||
build_list.project.is_package &&
|
||||
can?(:write, build_list.project) &&
|
||||
|
@ -197,10 +198,14 @@ class Ability
|
|||
def read_relations_for(table, parent = nil)
|
||||
key = parent ? "#{parent.singularize}_id" : 'id'
|
||||
parent ||= table
|
||||
["#{table}.#{key} IN (
|
||||
SELECT target_id FROM relations WHERE relations.target_type = ? AND
|
||||
|
||||
target_ids = Relation.where("relations.target_type = ? AND
|
||||
(relations.actor_type = 'User' AND relations.actor_id = ? OR
|
||||
relations.actor_type = 'Group' AND relations.actor_id IN (?)))", parent.classify, @user, @user.group_ids]
|
||||
relations.actor_type = 'Group' AND relations.actor_id IN (?))",
|
||||
parent.classify, @user, @user.group_ids
|
||||
).pluck(:target_id)
|
||||
|
||||
["#{table}.#{key} IN (?)",target_ids]
|
||||
end
|
||||
|
||||
def local_reader?(target)
|
||||
|
|
Loading…
Reference in New Issue