16387: Allow setting is_active=false only on LoginCluster users.
authorTom Clegg <tom@tomclegg.ca>
Wed, 6 May 2020 19:39:30 +0000 (15:39 -0400)
committerTom Clegg <tom@tomclegg.ca>
Wed, 6 May 2020 19:39:30 +0000 (15:39 -0400)
Arvados-DCO-1.1-Signed-off-by: Tom Clegg <tom@tomclegg.ca>

services/api/app/controllers/arvados/v1/users_controller.rb
services/api/app/models/user.rb

index 62da35ae86a626486b37e2c0943e65e0b1dfb75f..867b9a6e6abfdf0ae050a668f4340d1664608586 100644 (file)
@@ -54,9 +54,10 @@ class Arvados::V1::UsersController < ApplicationController
       @object = current_user
     end
     if not @object.is_active
       @object = current_user
     end
     if not @object.is_active
-      if @object.uuid[0..4] != Rails.configuration.ClusterID
-        logger.warn "Remote user #{@object.uuid} called users.activate"
-        raise ArgumentError.new "cannot activate remote account"
+      if @object.uuid[0..4] == Rails.configuration.Login.LoginCluster &&
+         @object.uuid[0..4] != Rails.configuration.ClusterID
+        logger.warn "Local user #{@object.uuid} called users#activate but only LoginCluster can do that"
+        raise ArgumentError.new "cannot activate user #{@object.uuid} here, only the #{@object.uuid[0..4]} cluster can do that"
       elsif not (current_user.is_admin or @object.is_invited)
         logger.warn "User #{@object.uuid} called users.activate " +
           "but is not invited"
       elsif not (current_user.is_admin or @object.is_invited)
         logger.warn "User #{@object.uuid} called users.activate " +
           "but is not invited"
index ba451eb1846b321598435aac82ca241d1fccbe59..c3641b64e84f04217145edacab05ac8d84f259a7 100644 (file)
@@ -238,10 +238,15 @@ class User < ArvadosModel
   end
 
   def must_unsetup_to_deactivate
   end
 
   def must_unsetup_to_deactivate
-    if self.is_active_changed? &&
+    if !self.new_record? &&
+       self.uuid[0..4] == Rails.configuration.Login.LoginCluster &&
+       self.uuid[0..4] != Rails.configuration.ClusterID
+      # OK to update our local record to whatever the LoginCluster
+      # reports, because self-activate is not allowed.
+      return
+    elsif self.is_active_changed? &&
        self.is_active_was &&
        self.is_active_was &&
-       !self.is_active &&
-       self.uuid[0..4] == Rails.configuration.ClusterID
+       !self.is_active
 
       group = Group.where(name: 'All users').select do |g|
         g[:uuid].match(/-f+$/)
 
       group = Group.where(name: 'All users').select do |g|
         g[:uuid].match(/-f+$/)