1 class Arvados::V1::UsersController < ApplicationController
2 skip_before_filter :find_object_by_uuid, only:
3 [:activate, :event_stream, :current, :system, :setup]
4 skip_before_filter :render_404_if_no_object, only:
5 [:activate, :event_stream, :current, :system, :setup]
6 before_filter :admin_required, only: [:setup, :unsetup]
18 Q_UPDATE_INTERVAL = 12
19 def initialize(opts={})
23 return unless @opts[:channel]
24 @redis = Redis.new(:timeout => 0)
25 @redis.subscribe(@opts[:channel]) do |event|
26 event.message do |channel, msg|
34 channel = current_user.andand.uuid
35 if current_user.andand.is_admin
36 channel = params[:uuid] || channel
38 if client_accepts_plain_text_stream
39 self.response.headers['Last-Modified'] = Time.now.ctime.to_s
40 self.response_body = ChannelStreamer.new(channel: channel)
43 href: url_for(uuid: channel),
44 comment: ('To retrieve the event stream as plain text, ' +
45 'use a request header like "Accept: text/plain"')
51 if current_user.andand.is_admin && params[:uuid]
52 @object = User.find params[:uuid]
54 @object = current_user
56 if not @object.is_active
57 if not (current_user.is_admin or @object.is_invited)
58 logger.warn "User #{@object.uuid} called users.activate " +
60 raise ArgumentError.new "Cannot activate without being invited."
63 required_uuids = Link.where("owner_uuid = ? and link_class = ? and name = ? and tail_uuid = ? and head_uuid like ?",
68 Collection.uuid_like_pattern).
70 signed_uuids = Link.where(owner_uuid: system_user_uuid,
71 link_class: 'signature',
73 tail_uuid: @object.uuid,
74 head_uuid: required_uuids).
76 todo_uuids = required_uuids - signed_uuids
78 @object.update_attributes is_active: true
79 logger.info "User #{@object.uuid} activated"
81 logger.warn "User #{@object.uuid} called users.activate " +
82 "before signing agreements #{todo_uuids.inspect}"
83 raise ArvadosModel::PermissionDeniedError.new \
84 "Cannot activate without user agreements #{todo_uuids.inspect}."
91 # create user object and all the needed links
95 @object = User.find_by_uuid params[:uuid]
97 return render_404_if_no_object
102 raise ArgumentError.new "Required uuid or user"
104 if params[:user]['uuid']
105 @object = User.find_by_uuid params[:user]['uuid']
112 if !params[:user]['email']
113 raise ArgumentError.new "Require user email"
116 if !params[:openid_prefix]
117 raise ArgumentError.new "Required openid_prefix parameter is missing."
120 @object = model_class.create! resource_attrs
126 @response = @object.setup_repo_vm_links params[:repo_name],
127 params[:vm_uuid], params[:openid_prefix]
129 @response = User.setup @object, params[:openid_prefix],
130 params[:repo_name], params[:vm_uuid]
133 # setup succeeded. send email to user
134 if params[:send_notification_email] == true || params[:send_notification_email] == 'true'
135 UserNotifier.account_is_setup(@object).deliver
138 render json: { kind: "arvados#HashList", items: @response.as_api_response(nil) }
141 # delete user agreements, vm, repository, login links; set state to inactive
143 reload_object_before_update
150 def self._setup_requires_parameters
152 send_notification_email: { type: 'boolean', required: true },