Sha256: 17804ec1887e56c343d9f8f2243960d879024d180a5c41bff9c9f78d982b5a73

Contents?: true

Size: 774 Bytes

Versions: 21

Compression:

Stored size: 774 Bytes

Contents

class RenameTemplateInvocationPermission < ActiveRecord::Migration[4.2]
  PERMISSION_NAMES = %w(execute_template_invocation create_template_invocations).freeze

  def up
    switch_filtering_permission!(*PERMISSION_NAMES)
  end

  def down
    switch_filtering_permission!(*PERMISSION_NAMES.reverse)
  end

  private

  def switch_filtering_permission!(old, new)
    old_permission = Permission.find_by(:name => old)
    return if old_permission.nil?

    new_permission = Permission.find_or_create_by(:name => new,
                                                  :resource_type => 'TemplateInvocation')
    old_permission.filterings.each do |filtering|
      filtering.permission_id = new_permission.id
      filtering.save!
    end
    old_permission.destroy!
  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
foreman_remote_execution-4.4.0 db/migrate/20180110104432_rename_template_invocation_permission.rb
foreman_remote_execution-4.3.1 db/migrate/20180110104432_rename_template_invocation_permission.rb
foreman_remote_execution-4.3.0 db/migrate/20180110104432_rename_template_invocation_permission.rb
foreman_remote_execution-4.2.3 db/migrate/20180110104432_rename_template_invocation_permission.rb
foreman_remote_execution-4.2.2 db/migrate/20180110104432_rename_template_invocation_permission.rb
foreman_remote_execution-4.2.1 db/migrate/20180110104432_rename_template_invocation_permission.rb
foreman_remote_execution-4.2.0 db/migrate/20180110104432_rename_template_invocation_permission.rb
foreman_remote_execution-4.1.0 db/migrate/20180110104432_rename_template_invocation_permission.rb
foreman_remote_execution-3.3.7 db/migrate/20180110104432_rename_template_invocation_permission.rb
foreman_remote_execution-4.0.0 db/migrate/20180110104432_rename_template_invocation_permission.rb
foreman_remote_execution-3.3.6 db/migrate/20180110104432_rename_template_invocation_permission.rb
foreman_remote_execution-3.3.5 db/migrate/20180110104432_rename_template_invocation_permission.rb
foreman_remote_execution-3.3.4 db/migrate/20180110104432_rename_template_invocation_permission.rb
foreman_remote_execution-3.3.3 db/migrate/20180110104432_rename_template_invocation_permission.rb
foreman_remote_execution-3.2.2 db/migrate/20180110104432_rename_template_invocation_permission.rb
foreman_remote_execution-3.3.2 db/migrate/20180110104432_rename_template_invocation_permission.rb
foreman_remote_execution-3.3.1 db/migrate/20180110104432_rename_template_invocation_permission.rb
foreman_remote_execution-3.3.0 db/migrate/20180110104432_rename_template_invocation_permission.rb
foreman_remote_execution-3.2.1 db/migrate/20180110104432_rename_template_invocation_permission.rb
foreman_remote_execution-3.2.0 db/migrate/20180110104432_rename_template_invocation_permission.rb