Merge branch 'master' into 2221-complete-docker
[arvados.git] / services / api / app / controllers / arvados / v1 / user_agreements_controller.rb
1 class Arvados::V1::UserAgreementsController < ApplicationController
2   before_filter :admin_required, except: [:index, :sign, :signatures]
3   skip_before_filter :find_object_by_uuid, only: [:sign, :signatures]
4   skip_before_filter :render_404_if_no_object, only: [:sign, :signatures]
5
6   def model_class
7     Link
8   end
9
10   def table_name
11     'links'
12   end
13
14   def index
15     if not current_user.is_invited
16       # New users cannot see user agreements until/unless invited to
17       # use this installation.
18       @objects = []
19     else
20       current_user_uuid = current_user.uuid
21       act_as_system_user do
22         uuids = Link.where(owner_uuid: system_user_uuid,
23                            link_class: 'signature',
24                            name: 'require',
25                            tail_kind: 'arvados#user',
26                            tail_uuid: system_user_uuid,
27                            head_kind: 'arvados#collection').
28           collect &:head_uuid
29         @objects = Collection.where('uuid in (?)', uuids)
30       end
31     end
32     @response_resource_name = 'collection'
33     super
34   end
35
36   def signatures
37     current_user_uuid = (current_user.andand.is_admin && params[:uuid]) ||
38       current_user.uuid
39     act_as_system_user do
40       @objects = Link.where(owner_uuid: system_user_uuid,
41                             link_class: 'signature',
42                             name: 'click',
43                             tail_kind: 'arvados#user',
44                             tail_uuid: current_user_uuid,
45                             head_kind: 'arvados#collection')
46     end
47     @response_resource_name = 'link'
48     render_list
49   end
50
51   def sign
52     current_user_uuid = current_user.uuid
53     act_as_system_user do
54       @object = Link.create(link_class: 'signature',
55                             name: 'click',
56                             tail_kind: 'arvados#user',
57                             tail_uuid: current_user_uuid,
58                             head_kind: 'arvados#collection',
59                             head_uuid: params[:uuid])
60     end
61     show
62   end
63
64   def create
65     usage_error
66   end
67   
68   def new
69     usage_error
70   end
71
72   def update
73     usage_error
74   end
75
76   def destroy
77     usage_error
78   end
79
80   protected
81   def usage_error
82     raise ArgumentError.new \
83     "Manage user agreements via Collections and Links instead."
84   end
85   
86 end