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]
12 @object = current_user
15 send_error("Not logged in", status: 401)
25 if current_user.andand.is_admin && params[:uuid]
26 @object = User.find params[:uuid]
28 @object = current_user
30 if not @object.is_active
31 if not (current_user.is_admin or @object.is_invited)
32 logger.warn "User #{@object.uuid} called users.activate " +
34 raise ArgumentError.new "Cannot activate without being invited."
37 required_uuids = Link.where("owner_uuid = ? and link_class = ? and name = ? and tail_uuid = ? and head_uuid like ?",
42 Collection.uuid_like_pattern).
44 signed_uuids = Link.where(owner_uuid: system_user_uuid,
45 link_class: 'signature',
47 tail_uuid: @object.uuid,
48 head_uuid: required_uuids).
50 todo_uuids = required_uuids - signed_uuids
52 @object.update_attributes is_active: true
53 logger.info "User #{@object.uuid} activated"
55 logger.warn "User #{@object.uuid} called users.activate " +
56 "before signing agreements #{todo_uuids.inspect}"
57 raise ArvadosModel::PermissionDeniedError.new \
58 "Cannot activate without user agreements #{todo_uuids.inspect}."
65 # create user object and all the needed links
69 @object = User.find_by_uuid params[:uuid]
71 return render_404_if_no_object
76 raise ArgumentError.new "Required uuid or user"
78 if params[:user]['uuid']
79 @object = User.find_by_uuid params[:user]['uuid']
86 if !params[:user]['email']
87 raise ArgumentError.new "Require user email"
90 if !params[:openid_prefix]
91 raise ArgumentError.new "Required openid_prefix parameter is missing."
94 @object = model_class.create! resource_attrs
99 # It's not always possible for the client to know the user's
100 # username when submitting this request: the username might have
101 # been assigned automatically in create!() above. If client
102 # provided a plain repository name, prefix it with the username
103 # now that we know what it is.
104 if params[:repo_name].nil?
106 elsif @object.username.nil?
108 new("cannot setup a repository because user has no username")
109 elsif object_found and
110 params[:repo_name].start_with?("#{@object.username}/")
111 full_repo_name = params[:repo_name]
113 full_repo_name = "#{@object.username}/#{params[:repo_name]}"
117 @response = @object.setup_repo_vm_links full_repo_name,
118 params[:vm_uuid], params[:openid_prefix]
120 @response = User.setup @object, params[:openid_prefix],
121 full_repo_name, params[:vm_uuid]
124 # setup succeeded. send email to user
125 if params[:send_notification_email] == true || params[:send_notification_email] == 'true'
126 UserNotifier.account_is_setup(@object).deliver
129 send_json kind: "arvados#HashList", items: @response.as_api_response(nil)
132 # delete user agreements, vm, repository, login links; set state to inactive
134 reload_object_before_update
141 def self._setup_requires_parameters
144 type: 'object', required: false
147 type: 'string', required: false
150 type: 'string', required: false
153 type: 'string', required: false
155 send_notification_email: {
156 type: 'boolean', required: false, default: false
161 def apply_filters(model_class=nil)
162 return super if @read_users.any? &:is_admin
163 if params[:uuid] != current_user.andand.uuid
164 # Non-admin index/show returns very basic information about readable users.
165 safe_attrs = ["uuid", "is_active", "email", "first_name", "last_name"]
167 @select = @select & safe_attrs
171 @filters += [['is_active', '=', true]]