+ def add_ssh_key
+ respond_to do |format|
+ key_params = {'key_type' => 'SSH'}
+ key_params['authorized_user_uuid'] = current_user.uuid
+
+ if params['name'] && params['name'].size>0
+ key_params['name'] = params['name'].strip
+ end
+ if params['public_key'] && params['public_key'].size>0
+ key_params['public_key'] = params['public_key'].strip
+ end
+
+ if !key_params['name'] && params['public_key'].andand.size>0
+ split_key = key_params['public_key'].split
+ key_params['name'] = split_key[-1] if (split_key.size == 3)
+ end
+
+ new_key = AuthorizedKey.create! key_params
+ if new_key
+ format.js
+ else
+ self.render_error status: 422
+ end
+ end
+ end
+
+ protected
+
+ def find_current_links user
+ current_selections = {}
+
+ if !user
+ return current_selections
+ end
+
+ # oid login perm
+ oid_login_perms = Link.where(tail_uuid: user.email,
+ head_kind: 'arvados#user',
+ link_class: 'permission',
+ name: 'can_login')
+
+ if oid_login_perms.any?
+ prefix_properties = oid_login_perms.first.properties
+ current_selections[:identity_url_prefix] = prefix_properties[:identity_url_prefix]
+ end
+
+ # repo perm
+ repo_perms = Link.where(tail_uuid: user.uuid,
+ head_kind: 'arvados#repository',
+ link_class: 'permission',
+ name: 'can_write')
+ if repo_perms.any?
+ repo_uuid = repo_perms.first.head_uuid
+ repos = Repository.where(head_uuid: repo_uuid)
+ if repos.any?
+ repo_name = repos.first.name
+ current_selections[:repo_name] = repo_name
+ end
+ end
+
+ # vm login perm
+ vm_login_perms = Link.where(tail_uuid: user.uuid,
+ head_kind: 'arvados#virtualMachine',
+ link_class: 'permission',
+ name: 'can_login')
+ if vm_login_perms.any?
+ vm_uuid = vm_login_perms.first.head_uuid
+ current_selections[:vm_uuid] = vm_uuid
+ end
+
+ return current_selections
+ end
+