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: system_user_uuid,
64 link_class: 'signature',
66 tail_uuid: system_user_uuid,
67 head_kind: 'arvados#collection').
69 signed_uuids = Link.where(owner_uuid: system_user_uuid,
70 link_class: 'signature',
72 tail_kind: 'arvados#user',
73 tail_uuid: @object.uuid,
74 head_kind: 'arvados#collection',
75 head_uuid: required_uuids).
77 todo_uuids = required_uuids - signed_uuids
79 @object.update_attributes is_active: true
80 logger.info "User #{@object.uuid} activated"
82 logger.warn "User #{@object.uuid} called users.activate " +
83 "before signing agreements #{todo_uuids.inspect}"
84 raise ArvadosModel::PermissionDeniedError.new \
85 "Cannot activate without user agreements #{todo_uuids.inspect}."
92 # create user object and all the needed links
96 @object = User.find_by_uuid params[:uuid]
98 return render_404_if_no_object
103 raise ArgumentError.new "Required uuid or user"
105 if params[:user]['uuid']
106 @object = User.find_by_uuid params[:user]['uuid']
113 if !params[:user]['email']
114 raise ArgumentError.new "Require user email"
117 if !params[:openid_prefix]
118 raise ArgumentError.new "Required openid_prefix parameter is missing."
121 @object = model_class.create! resource_attrs
127 @response = @object.setup_repo_vm_links params[:repo_name], params[:vm_uuid]
129 @response = User.setup @object, params[:openid_prefix],
130 params[:repo_name], params[:vm_uuid]
133 render json: { kind: "arvados#HashList", items: @response }
136 # delete user agreements, vm, repository, login links; set state to inactive
138 if current_user.andand.is_admin && params[:uuid]
139 @object = User.find_by_uuid params[:uuid]
141 @object = current_user
145 return render_404_if_no_object
148 @object = @object.unsetup