HEX
Server: Apache/2.4.41 (Ubuntu)
System: Linux vmi1674223.contaboserver.net 5.4.0-182-generic #202-Ubuntu SMP Fri Apr 26 12:29:36 UTC 2024 x86_64
User: root (0)
PHP: 7.4.3-4ubuntu2.22
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: //opt/openproject/db/migrate/20191112111040_fix_system_user_status.rb
class FixSystemUserStatus < ActiveRecord::Migration[6.0]
  def up
    # The previous migration was supposed to make the system user active,
    # but doesn't since it only touches built-in (0) users while the system user
    # used to be locked (3). An oversight on our part.
    #
    # We also update the anonymous user again. While it was correctly updated
    # in the previous migration, newly created anonymous users since have the
    # wrong status (0) because we failed to update the on-the-fly
    # creation of the anonymous user with the correct status.
    active_users.each do |user|
      user.update_all status: Principal::STATUSES[:active]
    end

    deleted_user.update_all status: Principal::STATUSES[:active]
  end

  def down
    # reset system user to locked which would've been the state before this migration
    system_user.update_all status: Principal::STATUSES[:locked]

    # reset deleted usr to active which he would've been after the previous migration
    deleted_user.update_all status: Principal::STATUSES[:active]

    # There is no need to update the anonymous user since it was supposed to be
    # active at this point already anyway. The previous migration then makes it
    # built-in (0) again if we rollback even further.
  end

  def active_users
    [system_user, anonymous_user]
  end

  def system_user
    SystemUser
  end

  def anonymous_user
    AnonymousUser
  end

  def deleted_user
    DeletedUser
  end
end