- def repositories
- # all repositories accessible by current user
- all_repositories = Hash[Repository.where(authorized_user_uuid: current_user.uuid).collect {|repo| [repo.uuid, repo]}]
-
- # repositories shared with the user
- repo_links = Link.
- filter([['head_uuid', 'is_a', 'arvados#repository'],
- ['tail_uuid', '=', current_user.uuid],
- ['link_class', '=', 'permission'],
- ])
-
- @my_repositories = [] # we want them ordered as owned, manageable, and the rest
- @repo_writable = {}
-
- # owned repos
- all_repositories.each do |_, repo|
- if repo.owner_uuid == current_user.uuid
- @repo_writable[repo.uuid] = 'can_write'
- @my_repositories << repo
- end
- end
-
- # shared and either writable or manageable
- handled = @my_repositories.map(&:uuid)
- repo_links.each do |link|
- if link.name.in? ['can_write', 'can_manage']
- @repo_writable[link.head_uuid] = link.name
- @my_repositories << all_repositories[link.head_uuid] if !link.head_uuid.in?(handled)
- end
- end
-
- # rest of the repos
- handled = @my_repositories.map(&:uuid)
- all_repositories.each do |_, repo|
- @my_repositories << repo if !repo.uuid.in?(handled)
- end
- end
-