8784: Fix test for latest firefox.
[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       act_as_system_user do
21         uuids = Link.where("owner_uuid = ? and link_class = ? and name = ? and tail_uuid = ? and head_uuid like ?",
22                            system_user_uuid,
23                            'signature',
24                            'require',
25                            system_user_uuid,
26                            Collection.uuid_like_pattern).
27           collect(&:head_uuid)
28         @objects = Collection.where('uuid in (?)', uuids)
29       end
30     end
31     @response_resource_name = 'collection'
32     super
33   end
34
35   def signatures
36     current_user_uuid = (current_user.andand.is_admin && params[:uuid]) ||
37       current_user.uuid
38     act_as_system_user do
39       @objects = Link.where("owner_uuid = ? and link_class = ? and name = ? and tail_uuid = ? and head_uuid like ?",
40                             system_user_uuid,
41                             'signature',
42                             'click',
43                             current_user_uuid,
44                             Collection.uuid_like_pattern)
45     end
46     @response_resource_name = 'link'
47     render_list
48   end
49
50   def sign
51     current_user_uuid = current_user.uuid
52     act_as_system_user do
53       @object = Link.create(link_class: 'signature',
54                             name: 'click',
55                             tail_uuid: current_user_uuid,
56                             head_uuid: params[:uuid])
57     end
58     show
59   end
60
61   def create
62     usage_error
63   end
64   
65   def new
66     usage_error
67   end
68
69   def update
70     usage_error
71   end
72
73   def destroy
74     usage_error
75   end
76
77   protected
78   def usage_error
79     raise ArgumentError.new \
80     "Manage user agreements via Collections and Links instead."
81   end
82   
83 end