add trait resource
[arvados.git] / services / api / app / controllers / arvados / v1 / repositories_controller.rb
1 class Arvados::V1::RepositoriesController < ApplicationController
2   before_filter :admin_required, :only => :get_all_permissions
3   def get_all_permissions
4     @users = {}
5     User.includes(:authorized_keys).all.each do |u|
6       @users[u.uuid] = u
7     end
8     @user_aks = {}
9     @repo_info = {}
10     @repos = Repository.includes(:permissions).all
11     @repos.each do |repo|
12       gitolite_permissions = ''
13       repo.permissions.each do |perm|
14         user_uuid = perm.tail_uuid
15         @user_aks[user_uuid] = @users[user_uuid].andand.authorized_keys.collect do |ak|
16           {
17             public_key: ak.public_key,
18             authorized_key_uuid: ak.uuid
19           }
20         end || []
21         if @user_aks[user_uuid].any?
22           @repo_info[repo.uuid] ||= {
23             uuid: repo.uuid,
24             name: repo.name,
25             push_url: repo.push_url,
26             fetch_url: repo.fetch_url,
27             user_permissions: {}
28           }
29           @repo_info[repo.uuid][:user_permissions][user_uuid] ||= {}
30           @repo_info[repo.uuid][:user_permissions][user_uuid][perm.name] = true
31         end
32       end
33     end
34     @repo_info.values.each do |repo_users|
35       repo_users[:user_permissions].each do |user_uuid,perms|
36         if perms['can_write']
37           perms[:gitolite_permissions] = 'RW'
38           perms['can_read'] = true
39         elsif perms['can_read']
40           perms[:gitolite_permissions] = 'R'
41         end
42       end
43     end
44     render json: {
45       kind: 'arvados#RepositoryPermissionSnapshot',
46       repositories: @repo_info.values,
47       user_keys: @user_aks
48     }
49   end
50 end