1 # Copyright (C) The Arvados Authors. All rights reserved.
3 # SPDX-License-Identifier: AGPL-3.0
5 class Arvados::V1::UsersController < ApplicationController
6 accept_attribute_as_json :prefs, Hash
8 skip_before_filter :find_object_by_uuid, only:
9 [:activate, :current, :system, :setup]
10 skip_before_filter :render_404_if_no_object, only:
11 [:activate, :current, :system, :setup]
12 before_filter :admin_required, only: [:setup, :unsetup]
16 @object = current_user
19 send_error("Not logged in", status: 401)
29 if current_user.andand.is_admin && params[:uuid]
30 @object = User.find params[:uuid]
32 @object = current_user
34 if not @object.is_active
35 if not (current_user.is_admin or @object.is_invited)
36 logger.warn "User #{@object.uuid} called users.activate " +
38 raise ArgumentError.new "Cannot activate without being invited."
41 required_uuids = Link.where("owner_uuid = ? and link_class = ? and name = ? and tail_uuid = ? and head_uuid like ?",
46 Collection.uuid_like_pattern).
48 signed_uuids = Link.where(owner_uuid: system_user_uuid,
49 link_class: 'signature',
51 tail_uuid: @object.uuid,
52 head_uuid: required_uuids).
54 todo_uuids = required_uuids - signed_uuids
56 @object.update_attributes is_active: true
57 logger.info "User #{@object.uuid} activated"
59 logger.warn "User #{@object.uuid} called users.activate " +
60 "before signing agreements #{todo_uuids.inspect}"
61 raise ArvadosModel::PermissionDeniedError.new \
62 "Cannot activate without user agreements #{todo_uuids.inspect}."
69 # create user object and all the needed links
72 @object = User.find_by_uuid(params[:uuid])
74 return render_404_if_no_object
77 raise ArgumentError.new "Required uuid or user"
78 elsif !params[:user]['email']
79 raise ArgumentError.new "Require user email"
80 elsif !params[:openid_prefix]
81 raise ArgumentError.new "Required openid_prefix parameter is missing."
83 @object = model_class.create! resource_attrs
86 # It's not always possible for the client to know the user's
87 # username when submitting this request: the username might have
88 # been assigned automatically in create!() above. If client
89 # provided a plain repository name, prefix it with the username
90 # now that we know what it is.
91 if params[:repo_name].nil?
93 elsif @object.username.nil?
95 new("cannot setup a repository because user has no username")
96 elsif params[:repo_name].index("/")
97 full_repo_name = params[:repo_name]
99 full_repo_name = "#{@object.username}/#{params[:repo_name]}"
102 @response = @object.setup(repo_name: full_repo_name,
103 vm_uuid: params[:vm_uuid],
104 openid_prefix: params[:openid_prefix])
106 # setup succeeded. send email to user
107 if params[:send_notification_email]
108 UserNotifier.account_is_setup(@object).deliver_now
111 send_json kind: "arvados#HashList", items: @response.as_api_response(nil)
114 # delete user agreements, vm, repository, login links; set state to inactive
116 reload_object_before_update
123 def self._setup_requires_parameters
126 type: 'object', required: false
129 type: 'string', required: false
132 type: 'string', required: false
135 type: 'string', required: false
137 send_notification_email: {
138 type: 'boolean', required: false, default: false
143 def apply_filters(model_class=nil)
144 return super if @read_users.any?(&:is_admin)
145 if params[:uuid] != current_user.andand.uuid
146 # Non-admin index/show returns very basic information about readable users.
147 safe_attrs = ["uuid", "is_active", "email", "first_name", "last_name"]
149 @select = @select & safe_attrs
153 @filters += [['is_active', '=', true]]