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