+ # Return a hash of {group_uuid: perm_hash} where perm_hash[:read]
+ # and perm_hash[:write] are true if this user can read and write
+ # objects owned by group_uuid.
+ def group_permissions
+ Rails.cache.fetch "groups_for_user_#{self.uuid}" do
+ permissions_from = {}
+ todo = {self.uuid => true}
+ done = {}
+ while !todo.empty?
+ lookup_uuids = todo.keys
+ lookup_uuids.each do |uuid| done[uuid] = true end
+ todo = {}
+ newgroups = []
+ Group.where('owner_uuid in (?)', lookup_uuids).each do |group|
+ newgroups << [group.owner_uuid, group.uuid, 'can_manage']
+ end
+ Link.where('tail_uuid in (?) and link_class = ? and head_kind = ?',
+ lookup_uuids,
+ 'permission',
+ 'arvados#group').each do |link|
+ newgroups << [link.tail_uuid, link.head_uuid, link.name]
+ end
+ newgroups.each do |tail_uuid, head_uuid, perm_name|
+ unless done.has_key? head_uuid
+ todo[head_uuid] = true
+ end
+ link_permissions = {}
+ case perm_name
+ when 'can_read'
+ link_permissions = {read:true}
+ when 'can_write'
+ link_permissions = {read:true,write:true}
+ when 'can_manage'
+ link_permissions = ALL_PERMISSIONS
+ end
+ permissions_from[tail_uuid] ||= {}
+ permissions_from[tail_uuid][head_uuid] ||= {}
+ link_permissions.each do |k,v|
+ permissions_from[tail_uuid][head_uuid][k] ||= v
+ end
+ end
+ end
+ search_permissions(self.uuid, permissions_from)
+ end
+ end
+