X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/a079a9f1627188e3ef0bb73e004defa2129d25f2..48006f58ed71ccff5de4f6aa0c1f19b7297cb0fb:/services/api/app/models/user.rb diff --git a/services/api/app/models/user.rb b/services/api/app/models/user.rb index 022c4d58ba..9209411f1e 100644 --- a/services/api/app/models/user.rb +++ b/services/api/app/models/user.rb @@ -161,7 +161,7 @@ class User < ArvadosModel # "name" arg is a query label that appears in logs: "all_group_permissions", ).rows.each do |user_uuid, group_uuid, max_p_val, trashed| - all_perms[user_uuid] ||= {user_uuid => {:read => true, :write => true, :manage => true}} + all_perms[user_uuid] ||= {} all_perms[user_uuid][group_uuid] = PERMS_FOR_VAL[max_p_val.to_i] end all_perms @@ -254,6 +254,32 @@ class User < ArvadosModel end end + def update_uuid(new_uuid:) + if !current_user.andand.is_admin + raise PermissionDeniedError + end + if uuid == system_user_uuid || uuid == anonymous_user_uuid + raise "update_uuid cannot update system accounts" + end + if self.class != self.class.resource_class_for_uuid(new_uuid) + raise "invalid new_uuid #{new_uuid.inspect}" + end + transaction(requires_new: true) do + reload + old_uuid = self.uuid + self.uuid = new_uuid + save!(validate: false) + ActiveRecord::Base.descendants.reject(&:abstract_class?).each do |klass| + klass.columns.each do |col| + if col.name.end_with?('_uuid') + column = col.name.to_sym + klass.where(column => old_uuid).update_all(column => new_uuid) + end + end + end + end + end + protected def ensure_ownership_path_leads_to_user