app/models/user.rb
# Org users share the same db, so must only delete the schema
Org users share the same db, so must only delete the schema
Org users share the same db so must only delete the schema
def drop_organization_user
    Thread.new do
      in_database(as: :superuser) do |database|
        schemas = ['cdb', 'cdb_importer', 'cartodb', 'public'] +
          User.select(:database_schema).where(:organization_id => self.organization_id).all.collect(&:database_schema).uniq
        schemas.each do |s|
          drop_user_privileges_in_schema(s)
        end
        database.run(%Q{ DROP FUNCTION IF EXISTS \"#{self.database_schema}\"._cdb_userquotainbytes()})
        database.run(%Q{ DROP SCHEMA IF EXISTS "#{self.database_schema}" }) unless self.database_schema == 'public'
      end
      conn = self.in_database(as: :cluster_admin)
      User.terminate_database_connections(database_name, database_host)
      conn.run("REVOKE ALL ON DATABASE \"#{database_name}\" FROM \"#{database_username}\"")
      conn.run("REVOKE ALL ON DATABASE \"#{database_name}\" FROM \"#{database_public_username}\"")
      conn.run("DROP USER \"#{database_public_username}\"")
      conn.run("DROP USER \"#{database_username}\"")
    end.join
    monitor_user_notification
  end
def drop_organization_user Thread . new do in_database ( as : :superuser ) do | database | schemas = [ 'cdb' , 'cdb_importer' , 'cartodb' , 'public' ] + User . select ( :database_schema ) . where ( :organization_id => self . organization_id ) . all . collect ( & :database_schema ) . uniq schemas . each do | s | drop_user_privileges_in_schema ( s ) end database . run ( %Q{ DROP FUNCTION IF EXISTS \"#{self.database_schema}\"._cdb_userquotainbytes()} ) database . run ( %Q{ DROP SCHEMA IF EXISTS "#{self.database_schema}" } ) unless self . database_schema == 'public' end conn = self . in_database ( as : :cluster_admin ) User . terminate_database_connections ( database_name , database_host ) conn . run ( "REVOKE ALL ON DATABASE \"#{database_name}\" FROM \"#{database_username}\"" ) conn . run ( "REVOKE ALL ON DATABASE \"#{database_name}\" FROM \"#{database_public_username}\"" ) conn . run ( "DROP USER \"#{database_public_username}\"" ) conn . run ( "DROP USER \"#{database_username}\"" ) end . join monitor_user_notification end
Org users share the same db, so must only delete the schema
Org users share the same db so must only delete the schema
# Drop this user privileges in every schema of the DB # Drop user quota function # If user is in an organization should never have public schema, so to be safe check