Merge branch 'master' into 3112-report-bug
[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 = ? and link_class = ? and name = ? and tail_uuid = ? and head_uuid like ?",
23                            system_user_uuid,
24                            'signature',
25                            'require',
26                            system_user_uuid,
27                            Collection.uuid_like_pattern).
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 = ? and link_class = ? and name = ? and tail_uuid = ? and head_uuid like ?",
41                             system_user_uuid,
42                             'signature',
43                             'click',
44                             current_user_uuid,
45                             Collection.uuid_like_pattern)
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_uuid: current_user_uuid,
57                             head_uuid: params[:uuid])
58     end
59     show
60   end
61
62   def create
63     usage_error
64   end
65   
66   def new
67     usage_error
68   end
69
70   def update
71     usage_error
72   end
73
74   def destroy
75     usage_error
76   end
77
78   protected
79   def usage_error
80     raise ArgumentError.new \
81     "Manage user agreements via Collections and Links instead."
82   end
83   
84 end