X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/2b62223c9ba420208b9f293825e7f6ae3f50f95b..e7672a0b679659d6ba90d23b4e102fba747fa9ef:/services/api/app/models/user.rb diff --git a/services/api/app/models/user.rb b/services/api/app/models/user.rb index c4a4f92d30..bca1eef726 100644 --- a/services/api/app/models/user.rb +++ b/services/api/app/models/user.rb @@ -20,9 +20,7 @@ class User < ArvadosModel before_update :verify_repositories_empty, :if => Proc.new { |user| user.username.nil? and user.username_changed? } - before_update :setup_on_activate, :if => Proc.new { |user| - ![system_user_uuid, anonymous_user_uuid].include?(user.uuid) - } + before_update :setup_on_activate before_create :check_auto_admin before_create :set_initial_username, :if => Proc.new { |user| user.username.nil? and user.email @@ -143,11 +141,29 @@ class User < ArvadosModel end end + # Return a hash of {user_uuid: group_perms} + def self.all_group_permissions + install_view('permission') + all_perms = {} + ActiveRecord::Base.connection. + exec_query('SELECT user_uuid, target_owner_uuid, max(perm_level) + FROM permission_view + WHERE target_owner_uuid IS NOT NULL + GROUP BY user_uuid, target_owner_uuid', + # "name" arg is a query label that appears in logs: + "all_group_permissions", + ).rows.each do |user_uuid, group_uuid, max_p_val| + all_perms[user_uuid] ||= {} + all_perms[user_uuid][group_uuid] = PERMS_FOR_VAL[max_p_val.to_i] + end + all_perms + end + # Return a hash of {group_uuid: perm_hash} where perm_hash[:read] # and perm_hash[:write] are true if this user can read and write # objects owned by group_uuid. def calculate_group_permissions - install_view('permission') + self.class.install_view('permission') group_perms = {} ActiveRecord::Base.connection.