Added doc output directories to .gitignore
[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 table_name
10     'links'
11   end
12
13   def index
14     if not current_user.is_invited
15       # New users cannot see user agreements until/unless invited to
16       # use this installation.
17       @objects = []
18     else
19       current_user_uuid = current_user.uuid
20       act_as_system_user do
21         uuids = Link.where(owner_uuid: system_user_uuid,
22                            link_class: 'signature',
23                            name: 'require',
24                            tail_kind: 'arvados#user',
25                            tail_uuid: system_user_uuid,
26                            head_kind: 'arvados#collection').
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: system_user_uuid,
40                             link_class: 'signature',
41                             name: 'click',
42                             tail_kind: 'arvados#user',
43                             tail_uuid: current_user_uuid,
44                             head_kind: 'arvados#collection')
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_kind: 'arvados#user',
56                             tail_uuid: current_user_uuid,
57                             head_kind: 'arvados#collection',
58                             head_uuid: params[:uuid])
59     end
60     show
61   end
62
63   def create
64     usage_error
65   end
66   
67   def new
68     usage_error
69   end
70
71   def update
72     usage_error
73   end
74
75   def destroy
76     usage_error
77   end
78
79   protected
80   def usage_error
81     raise ArgumentError.new \
82     "Manage user agreements via Collections and Links instead."
83   end
84   
85 end