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