}
func (conn *Conn) UserGetCurrent(ctx context.Context, options arvados.GetOptions) (arvados.User, error) {
- c, ok := auth.FromContext(ctx)
- if !ok || len(c.Tokens) == 0 {
- return arvados.User{}, httpErrorf(http.StatusUnauthorized, "Must supply a token")
- }
-
- tok := c.Tokens[0]
- if !strings.HasPrefix(tok, "v2/") || len(tok) < 30 {
- return conn.localOrLoginCluster().UserGetCurrent(ctx, options)
- }
-
- // Contact the cluster that issued the token to find out what
- // user it belongs to.
- remote := tok[3:8]
- resp, err := conn.chooseBackend(remote).UserGetCurrent(ctx, options)
- if err != nil {
- return resp, err
- }
-
- // If it is a remote cluster that owns the user, update the local user record.
- if remote != conn.cluster.ClusterID && remote == resp.UUID[:5] {
- err = conn.batchUpdateUsers(ctx, arvados.ListOptions{}, []arvados.User{resp})
- if err != nil {
- return arvados.User{}, err
- }
- }
- return resp, nil
+ return conn.local.UserGetCurrent(ctx, options)
}
func (conn *Conn) UserGetSystem(ctx context.Context, options arvados.GetOptions) (arvados.User, error) {
end
act_as_system_user do
- if user.is_active && !remote_user['is_active']
+ user.save!
+
+ if (user.is_active && !remote_user['is_active']) or (user.is_invited && !remote_user['is_invited'])
+ # If the user is newly created and AutoSetupNewUsers is
+ # true, they will auto-setup in an after_create hook.
+ # Synchronize the user's "active/invited" state state after the record
+ # has been saved.
user.unsetup
end
- user.save!
-
# We will accept this token (and avoid reloading the user
# record) for 'RemoteTokenRefresh' (default 5 minutes).
# Possible todo:
username: 'barney',
is_admin: true,
is_active: true,
+ is_invited: true,
}
end
# revoke original token
@stub_content[:is_active] = false
+ @stub_content[:is_invited] = false
# simulate cache expiry
ApiClientAuthorization.where(
assert_equal 'barney', json_response['username']
end
+ test 'get inactive user from Login cluster when AutoSetupNewUsers is set' do
+ Rails.configuration.Login.LoginCluster = 'zbbbb'
+ Rails.configuration.Users.AutoSetupNewUsers = true
+ @stub_content = {
+ uuid: 'zbbbb-tpzed-000000000000001',
+ email: 'foo@example.com',
+ username: 'barney',
+ is_admin: false,
+ is_active: false,
+ is_invited: false,
+ }
+ get '/arvados/v1/users/current',
+ params: {format: 'json'},
+ headers: auth(remote: 'zbbbb')
+ assert_response :success
+ assert_equal 'zbbbb-tpzed-000000000000001', json_response['uuid']
+ assert_equal false, json_response['is_admin']
+ assert_equal false, json_response['is_active']
+ assert_equal false, json_response['is_invited']
+ assert_equal 'foo@example.com', json_response['email']
+ assert_equal 'barney', json_response['username']
+ end
+
test 'pre-activate remote user' do
@stub_content = {
uuid: 'zbbbb-tpzed-000000000001234',
username: 'barney',
is_admin: true,
is_active: true,
+ is_invited: true,
}
post '/arvados/v1/users',
username: 'barney',
is_admin: true,
is_active: true,
+ is_invited: true,
}
get '/arvados/v1/users/current',