ManageIQ/manageiq

View on GitHub
app/models/mixins/read_only_mixin.rb

Summary

Maintainability
A
0 mins
Test Coverage
A
100%
module ReadOnlyMixin
  extend ActiveSupport::Concern

  included do
    before_destroy :reject_if_read_only
  end

  private

  def reject_if_read_only
    if read_only? && !EvmDatabase.seeding?
      model_name = self.class.name.pluralize.underscore.tr('_', ' ').gsub('miq ', '')
      errors.add(:base, _("Read only %{model_name} cannot be deleted.") % {:model_name => model_name})
      throw :abort
    end
  end
end