1 class Arvados::V1::UsersController < ApplicationController
2 accept_attribute_as_json :prefs, Hash
4 skip_before_filter :find_object_by_uuid, only:
5 [:activate, :current, :system, :setup]
6 skip_before_filter :render_404_if_no_object, only:
7 [:activate, :current, :system, :setup]
8 before_filter :admin_required, only: [:setup, :unsetup]
11 @object = current_user
20 if current_user.andand.is_admin && params[:uuid]
21 @object = User.find params[:uuid]
23 @object = current_user
25 if not @object.is_active
26 if not (current_user.is_admin or @object.is_invited)
27 logger.warn "User #{@object.uuid} called users.activate " +
29 raise ArgumentError.new "Cannot activate without being invited."
32 required_uuids = Link.where("owner_uuid = ? and link_class = ? and name = ? and tail_uuid = ? and head_uuid like ?",
37 Collection.uuid_like_pattern).
39 signed_uuids = Link.where(owner_uuid: system_user_uuid,
40 link_class: 'signature',
42 tail_uuid: @object.uuid,
43 head_uuid: required_uuids).
45 todo_uuids = required_uuids - signed_uuids
47 @object.update_attributes is_active: true
48 logger.info "User #{@object.uuid} activated"
50 logger.warn "User #{@object.uuid} called users.activate " +
51 "before signing agreements #{todo_uuids.inspect}"
52 raise ArvadosModel::PermissionDeniedError.new \
53 "Cannot activate without user agreements #{todo_uuids.inspect}."
60 # create user object and all the needed links
64 @object = User.find_by_uuid params[:uuid]
66 return render_404_if_no_object
71 raise ArgumentError.new "Required uuid or user"
73 if params[:user]['uuid']
74 @object = User.find_by_uuid params[:user]['uuid']
81 if !params[:user]['email']
82 raise ArgumentError.new "Require user email"
85 if !params[:openid_prefix]
86 raise ArgumentError.new "Required openid_prefix parameter is missing."
89 @object = model_class.create! resource_attrs
95 @response = @object.setup_repo_vm_links params[:repo_name],
96 params[:vm_uuid], params[:openid_prefix]
98 @response = User.setup @object, params[:openid_prefix],
99 params[:repo_name], params[:vm_uuid]
102 # setup succeeded. send email to user
103 if params[:send_notification_email] == true || params[:send_notification_email] == 'true'
104 UserNotifier.account_is_setup(@object).deliver
107 render json: { kind: "arvados#HashList", items: @response.as_api_response(nil) }
110 # delete user agreements, vm, repository, login links; set state to inactive
112 reload_object_before_update
119 def self._setup_requires_parameters
122 type: 'object', required: false
125 type: 'string', required: false
128 type: 'string', required: false
131 type: 'string', required: false
133 send_notification_email: {
134 type: 'boolean', required: false, default: false
139 def find_objects_for_index
140 if (action_name == "index") and (not @read_users.any? { |u| u.is_admin })
141 # Non-admin index returns very basic information about all active users.
142 # We ignore where and filters params to avoid leaking information.
145 @select = ["uuid", "is_active", "email", "first_name", "last_name"]
146 @objects = model_class.where(is_active: true)