Allow all active users to retrieve list of keep nodes.
[arvados.git] / services / api / app / controllers / arvados / v1 / nodes_controller.rb
1 class Arvados::V1::NodesController < ApplicationController
2   skip_before_filter :require_auth_scope_all, :only => :ping
3
4   def create
5     @object = Node.new
6     @object.save!
7     @object.start!(lambda { |h| arvados_v1_ping_node_url(h) })
8     show
9   end
10
11   def self._ping_requires_parameters
12     { ping_secret: true }
13   end
14   def ping
15     @object.ping({ ip: params[:local_ipv4] || request.env['REMOTE_ADDR'],
16                    ping_secret: params[:ping_secret],
17                    ec2_instance_id: params[:instance_id] })
18     show
19   end
20
21   def find_objects_for_index
22     if current_user.andand.is_admin || !current_user.andand.is_active
23       super
24     else
25       # active non-admin users can list nodes that are (or were
26       # recently) working
27       @objects = model_class.where('last_ping_at >= ?', Time.now - 1.hours)
28     end
29   end
30 end